Show transaction status in the psql prompt

Add a visual identifier to psql's prompt to show if you are currently in the middle of a transaction:

testdb=# \set PROMPT1 '%/%R%x%# '

testdb=# BEGIN; BEGIN
testdb=*# SELECT 'Hello World!'; ?column? -------------- Hello World! (1 row) testdb=*# COMMIT; COMMIT
testdb=# BEGIN; BEGIN
testdb=*# SELECT error; ERROR: column "error" does not exist LINE 1: SELECT error; ^ testdb=!# ROLLBACK; ROLLBACK

The %x token will cause psql to show * (asterisk) if in a transaction block, ! (exclamation mark) if the transaction has failed, or ? (question mark) if the transaction is in an unknown status (due to e.g. a broken connection to the database).

For more details, see the psql documentation page's Prompting section.