</listitem>
</varlistentry>
+ <varlistentry id="app-psql-prompting-i">
+ <term><literal>%i</literal></term>
+ <listitem>
+ <para>
+ Indicates whether the connected server is running in hot standby mode.
+ The value is shown as <literal>standby</literal>, if the server is
+ currently in hot standby and reports
+ <xref linkend="guc-in-hot-standby"/> as <literal>on</literal>,
+ and <literal>primary</literal> otherwise. This is useful when
+ connecting to multiple servers to quickly determine the role of
+ each connection. A value of <literal>?</literal> is shown
+ when connected to a server running
+ <productname>PostgreSQL</productname> 13 or older.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="app-psql-prompting-x">
<term><literal>%x</literal></term>
<listitem>
* or a ! if session is not connected to a database;
* in prompt2 -, *, ', or ";
* in prompt3 nothing
+ * %i - "standby" or "primary" depending on the server's in_hot_standby
+ * status, or "?" if unavailable (empty if unknown)
* %x - transaction status: empty, *, !, ? (unknown or no connection)
* %l - The line number inside the current statement, starting from 1.
* %? - the error code of the last query (not yet implemented)
break;
}
break;
+ case 'i':
+ if (pset.db)
+ {
+ const char *hs = PQparameterStatus(pset.db, "in_hot_standby");
+ if (hs)
+ {
+ if (strcmp(hs, "on") == 0)
+ strlcpy(buf, "standby", sizeof(buf));
+ else
+ strlcpy(buf, "primary", sizeof(buf));
+ }
+ /* Use ? for versions that don't report in_hot_standby */
+ else
+ buf[0] = '?';
+ }
+ break;
case 'x':
if (!pset.db)
buf[0] = '?';