Sample Header Ad - 728x90

Does a serializable transaction around a single statement have any effect compared to an implicit transaction?

2 votes
2 answers
314 views
I'm doing some performance auditing of our codebase and have noticed that we always run SQL statements within a serializable transaction. I've also noticed that many of these transactions only perform a single statement. Are there any circumstances where the effect of a statement will change based on whether or not it's running in a serializable transaction? The official PostgreSQL documentation (https://www.postgresql.org/docs/current/tutorial-transactions.html) states: > PostgreSQL actually treats every SQL statement as being executed within a transaction. If you do not issue a BEGIN command, then each individual statement has an implicit BEGIN and (if successful) COMMIT wrapped around it. But it doesn't say anything about the isolation level used. My hope is I can drop these transactions (avoiding at least two roundtrips for BEGIN and COMMIT, along with some other accidental complexity), but I want to avoid subtly changing the semantics of this code.
Asked by ocharles (208 rep)
Apr 11, 2024, 03:33 PM
Last activity: Jan 11, 2025, 01:58 PM