October 27, 2004

PostgreSQL | Showing transaction status in the psql prompt

Ever start a transaction in psql, then lose track of whether it's been committed or not? psql provides a prompt formatting option (%x) which displays a * whenever a transaction is in process:

test=> \set PROMPT1 '%/%R%x%# '
test=> BEGIN;
test=*> SELECT 'Hello World!';
 Hello World!
(1 row)

test=*> COMMIT;

The psql manpage contains more information on the available formatting options.

Note: This option is only available in PostgreSQL 7.4 and later.

Posted at 7:24 PM