Commit 275f05c9 authored by Andres Freund's avatar Andres Freund

Add psql PROMPT variable showing the pid of the connected to backend.

The substitution for the pid is %p.

Author: Julien Rouhaud
Discussion: 116262CF971C844FB6E793F8809B51C6E99D48@BPXM02GP.gisp.nec.co.jp
parent b2f6f749
...@@ -3364,6 +3364,13 @@ testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput> ...@@ -3364,6 +3364,13 @@ testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><literal>%p</literal></term>
<listitem>
<para>The pid of the backend currently connected to.</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><literal>%&gt;</literal></term> <term><literal>%&gt;</literal></term>
<listitem><para>The port number at which the database server is listening.</para></listitem> <listitem><para>The port number at which the database server is listening.</para></listitem>
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
* %M - database server "hostname.domainname", "[local]" for AF_UNIX * %M - database server "hostname.domainname", "[local]" for AF_UNIX
* sockets, "[local:/dir/name]" if not default * sockets, "[local:/dir/name]" if not default
* %m - like %M, but hostname only (before first dot), or always "[local]" * %m - like %M, but hostname only (before first dot), or always "[local]"
* %p - backend pid
* %> - database server port number * %> - database server port number
* %n - database user name * %n - database user name
* %/ - current database * %/ - current database
...@@ -161,6 +162,15 @@ get_prompt(promptStatus_t status) ...@@ -161,6 +162,15 @@ get_prompt(promptStatus_t status)
if (pset.db) if (pset.db)
strlcpy(buf, session_username(), sizeof(buf)); strlcpy(buf, session_username(), sizeof(buf));
break; break;
/* backend pid */
case 'p':
if (pset.db)
{
int pid = PQbackendPID(pset.db);
if (pid)
snprintf(buf, sizeof(buf), "%d", pid);
}
break;
case '0': case '0':
case '1': case '1':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment