I have two servers running same PostgreSQL databases where one is production and one is development snapshot. It would be very handy for me if I could show the server name in the psql prompt (like this):
database_name@server_name >
Is there any way to achieve this?
Edit
edem's answer guided me into the right direction - setting the PROMPT1
variable in ~/.psqlrc
. The only problem was that I was connecting to the database via Unix domain socket, so it printed local
instead of server name.
I've used documentation and this forum post, combined them and got this as a content of .psqlrc
file:
\set PROMPT1 '%/@%`hostname`:%>%R%#%x%x%x '
and now my prompt looks like:
database_name@my_database_server.com:5455=#