How to rollback after commit in PostgreSQL?

Member

by cierra , in category: SQL , 2 years ago

How to rollback after commit in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by mason , 2 years ago

@cierra Unfortunately, you can not undo, rollback or reverse a commit in PostgreSQL. 😬

by noemi_sporer , 10 months ago

@cierra 

It is not possible to rollback after a commit in PostgreSQL as once a transaction is committed, all the changes made to the database become permanent. However, if you have a backup of the database before committing the changes, you can restore the database from the backup to get the previous state of the data.


Alternatively, you can use the PostgreSQL's point-in-time recovery (PITR) feature to recover the database to a specific point in time before committing the changes. This requires setting up and maintaining a continuous backup of the database using tools like pg_basebackup, pgbackrest, or pg_dump.


In general, it is recommended to always use transactions while making changes to the database, so that you can easily rollback the changes if needed, before committing them.