This section is from the "Practical PostgreSQL" book, by John Worsley and Joshua Drake. Also available from Amazon: Practical PostgreSQL.
Combine the different substitution characters to form whatever prompt you would like.
Example 4-61. Setting the Prompt to Include Database Host, the Username, Port, and Current Username
testdb=# \set PROMPT1 '[ %m:%>:%n](%/)= ' [filesrv:5432:postgres](testdb)=
Example 4-62. Setting the Prompt to Include the Output of the Linux date Command, the Database Name, and Current Username
testdb=#\set PROMPT1 '\n[ %`date`]\n%n:%/%=# ' [Fri Aug 3 21:44:30 PDT 2001] postgres:testdb=#
 
Continue to: