RELEASE_SAVEPOINT(7pg16)
π RELEASE SAVEPOINT π
okay bestie so this is RELEASE_SAVEPOINT from the PostgreSQL 16 docs, and it's genuinely one of the most useful little commands ever β it's the "okay I'm done with this checkpoint, let's keep everything" button. let's get into it π
β¨ NAME β¨
RELEASE_SAVEPOINT β release a previously defined savepoint. that's it. that's the whole vibe. you made a savepoint, now you're letting it go, and everything good that happened inside it comes with you πΈ
π¦ SYNOPSIS π¦
RELEASE [ SAVEPOINT ] savepoint_name
see how SAVEPOINT is in brackets? that means it's optional, lowkey. you can just say RELEASE my_savepoint and Postgres gets it. slay π
π DESCRIPTION π
okay so RELEASE SAVEPOINT does a few things at once, bestie, so stay with me:
- it releases the named savepoint and all active savepoints that were created after the named savepoint β like, the whole little stack above it
- it frees their resources (bye, clutter π§Ή)
- and β this is the main character moment β all changes made since the creation of the savepoint that didn't already get rolled back are merged into the transaction or savepoint that was active when the named savepoint was created
so those changes get adopted by the savepoint that was live before your named one existed. any changes you make after RELEASE SAVEPOINT are also part of that active transaction or savepoint. nothing is lost, it just moved in with a new parent π«Ά
π PARAMETERS π
savepoint_nameβ the name of the savepoint you want to release. that's the one. the chosen one. π
β NOTES β
- fr fr, if you give a savepoint name that was not previously defined, that's an error. no mystery savepoints. π
- you can't release a savepoint when the transaction is in an aborted state. nope. not happening. if that's what you need, use
ROLLBACK TO SAVEPOINT(ROLLBACK_TO_SAVEPOINT(7)) instead. - and here's a fun one: if multiple savepoints have the same name, only the most recently defined unreleased one is released. repeated commands will release progressively older savepoints. so same-name savepoints stack up like a little queue and you pop them one at a time π
π EXAMPLES π
setting up and releasing a savepoint β¨
BEGIN;
INSERT INTO table1 VALUES (3);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (4);
RELEASE SAVEPOINT my_savepoint;
COMMIT;
the above transaction will insert both 3 and 4. nothing lost, everything ate π
the more complex nested subtransaction example π
BEGIN;
INSERT INTO table1 VALUES (1);
SAVEPOINT sp1;
INSERT INTO table1 VALUES (2);
SAVEPOINT sp2;
INSERT INTO table1 VALUES (3);
RELEASE SAVEPOINT sp2;
INSERT INTO table1 VALUES (4))); -- generates an error
okay so in this example, the application requests the release of the savepoint sp2, which inserted 3. this changes the insert's transaction context to sp1.
then when the statement attempting to insert value 4 generates an error:
- the insertion of 2 and 4 are lost, because they're in the same, now-rolled back savepoint
- and value 3 is in the same transaction context
so the application can now only choose one of these two commands, since all other commands will be ignored:
ROLLBACK;
ROLLBACK TO SAVEPOINT sp1;
choosing ROLLBACK will abort everything, including value 1. whereas ROLLBACK TO SAVEPOINT sp1 will retain value 1 and allow the transaction to continue. that's the save. π
π COMPATIBILITY π
this command conforms to the SQL standard, periodt. the standard specifies that the key word SAVEPOINT is mandatory β but PostgreSQL allows it to be omitted. generous queen π
π« SEE ALSO π«
BEGIN(7)COMMIT(7)ROLLBACK(7)ROLLBACK TO SAVEPOINT(ROLLBACK_TO_SAVEPOINT(7))SAVEPOINT(7)
and that's the whole page bestie π¦ this one's from PostgreSQL 16.15, dated 2026 β go forth and release those savepoints responsibly, mwah πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms