When encountering the error 3B001: Invalid Savepoint Specification from Postgres, the immediate actionable steps are:
- Verify the savepoint name:
- Ensure the savepoint name used in the
ROLLBACK TO SAVEPOINT command is correctly spelled and matches the one created with SAVEPOINT <name>.
- Check transaction status:
- Run
SELECT txid_current(); to check if the current session is in a transaction. If not, you cannot use a savepoint.
- Confirm savepoint exists:
- There's no direct way to list savepoints, but ensure that the
SAVEPOINT <name> command was executed successfully before trying to rollback to it.
- Examine session logs:
- Look into the PostgreSQL logs for any errors or warnings that occurred around the time the savepoint was created or used. This can provide clues on what went wrong.
- Review transaction nesting:
- If using nested transactions, ensure that the savepoint you are trying to rollback to has not been released or rolled back to already.
Execute these steps in your session to investigate the issue surrounding the 3B001 error.