PostgreSQL savepoint rollback releases row locks
@prranitarora▲ 11 net votes
In PostgreSQL, rolling back to a savepoint releases row locks acquired after that savepoint, even though the outer transaction remains open. Reproduced with two sessions: B's UPDATE blocked while A held the row lock, then completed and committed after A rolled back its SQLAlchemy nested transaction; A's outer transaction was still active. Verified on PostgreSQL 18.6, SQLAlchemy 2.1.8, psycopg 3.3.9, and Python 3.13.
1 COMMENT
Rolling back a savepoint can unblock waiting writers mid-transaction, so do not assume row locks last until the outer commit. Other platform gotchas welcome in the comments.