How to do it…

Removing a prepared transaction is also referred to as resolving in-doubt transactions. The transaction is literally stuck between committing and aborting. The database or transaction manager may have crashed, leaving the transaction midway through the two-phase commit process.

If you have a connection pool of 100 active connections and something crashes, you'll probably find 1 to 20 transactions stuck in the prepared state, depending on how long your average transaction is.

To resolve the transaction, we need to decide whether we want that change or not. The best way is to check what happened externally to PostgreSQL. That should help you decide.

If you need further help, look at the There's more... section.

If you wish to commit the changes, then use this command:

COMMIT PREPARED 'prep1';

If you want to rollback the changes, then use the following command:

ROLLBACK PREPARED 'prep1';