How can I customize the prompt in the PostgreSQL command line tool psql (ideally in a per-user start-up script)?
In particular, I'd like to be able to change it while still including the character that indicates whether the command is multi-line (eg. =
, -
, '
, etc.).
I'm running Ubuntu 10.04 (Lucid), PostgreSQL 8.4.4.
You can certainly customize the prompt.
From the documentation:
The prompts psql issues can be customized to your preference. The three variables
PROMPT1
,PROMPT2
, andPROMPT3
contain strings and special escape sequences that describe the appearance of the prompt. Prompt 1 is the normal prompt that is issued when psql requests a new command. Prompt 2 is issued when more input is expected during command input because the command was not terminated with a semicolon or a quote was not closed. Prompt 3 is issued when you run anSQL COPY
command and you are expected to type in the row values on the terminal.
If you want to set the prompt on a per user basis, you can add the \set
commands to the user's .psqlrc
file.
So, your $HOME/.psqlrc
would be something like this:
\set PROMPT1 '(%n@%M:%>) %`date +%H:%M:%S` [%/] \n%x%# '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With