Skip to content

Latest commit

 

History

History
59 lines (39 loc) · 1.31 KB

setting_the_prompt.md

File metadata and controls

59 lines (39 loc) · 1.31 KB

Setting the prompt

Tweaking the Postgresql commandline utility psql prompt can be quite useful.

Experiment with in psql

\set PROMPT1 '(%n@%m) [%/]>

Rendering:

(jonasbn@[local]) [mydb]>

When satisfied, put this in your .psqlrc.

In addition you can set transactional state in the prompt, following this tip (examples lifed from the referenced resource).

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

Starting a transaction will render (note the asterisk):

test=> BEGIN;
BEGIN
test=*>

Committing the transaction will render:

test=*> COMMIT;
COMMIT
test=>

So in combination you could do;

\set PROMPT1 '(%n@%m) [%/]%x> '

Rendering (for open transaction):

(jonasbn@[local]) [mydb]*>

References

Source: SQL-info

More information on psql can be found at: http://www.postgresql.org/docs/current/static/app-psql.html

More tips on how to get the most of the PostgreSQL shell and CLI, please see this article by Craig Kerstiens.