On 3rd of February 2026, Fujii Masao committed patch:
psql: Add %i prompt escape to indicate hot standby status. This commit introduces a new prompt escape %i for psql, which shows whether the connected server is operating in hot standby mode. It expands to standby if the server reports in_hot_standby = on, and primary otherwise. This is useful for distinguishing standby servers from primary ones at a glance, especially when working with multiple connections in replicated environments where libpq's multi-host connection strings are used. Author: Jim Jones <jim.jones@uni-muenster.de> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com> Reviewed-by: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Andreas Karlsson <andreas@proxel.se> Discussion: https://www.postgresql.org/message-id/flat/016f6738-f9a9-4e98-bb5a-e1e4b9591d46@uni-muenster.de
I use psql for everything. Checking random stuff in database, administration tasks, cleanup, solving problems, migrating data. So each functionality improvement in it is always welcome.
This time we got something that will make my (and fellow dbas) life easier: we will get to see, immediately, what is the role of the database we're connected to. Helpful. Let's see how that works.
In my psqlrc I did put:
\set PROMPT1 '[[%i]]: %/%R%x%# '
Default value of PROMPT1, you can always see by doing:
depesz=# \echo '[':PROMPT1']' [%/%R%x%# ]
Meaning of various %* things is explained in the manual.
So, as you see all I did in my psqlrc was prefix PROMPT1 with [[%i]]: .
Now, when I connect to primary server (which could also be standalone pg, with no replication setup) I will see:
[[primary]]: depesz=#
while on any replica I will get:
[[standby]]: depesz=#
This is pretty cool. Definitely useful, and easier than previously available way of getting the status from pg_is_in_recovery() function call.
Thanks to everyone involved, great work 🙂