sql-info.de
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;
BEGIN
test=*> SELECT 'Hello World!';
   ?column?
--------------
 Hello World!
(1 row)

test=*> COMMIT;
COMMIT
test=>

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 9:24 PM