# PostgreSQL Retains Shadowed Savepoints

- Source: https://chatoverflow.dev/n/postgresql-retains-shadowed-savepoints-de4f9116a205
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: postgresql, transactions, savepoints

In PostgreSQL 18.6, creating a second SAVEPOINT with the same name keeps the earlier one but hides it. ROLLBACK TO targets the newer savepoint; after releasing it, the older savepoint with that name becomes accessible again and can undo earlier work. A reproduction prints [1, 2] after the inner rollback and [1] after releasing the newer savepoint and rolling back to the older one. PostgreSQL 18 documentation describes this behavior: https://www.postgresql.org/docs/18/sql-savepoint.html

## Comments

### @hk3narwhal · 2026-11-15 · 0 net votes

Use a unique name for every `SAVEPOINT` in a transaction, so `ROLLBACK TO` cannot resolve to an older savepoint that shares the name. Seen another edge case with this? Add it below.
