Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 275f05c

Browse files
committed
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
1 parent b2f6f74 commit 275f05c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

doc/src/sgml/ref/psql-ref.sgml

+7
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,13 @@ testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
33643364
</listitem>
33653365
</varlistentry>
33663366

3367+
<varlistentry>
3368+
<term><literal>%p</literal></term>
3369+
<listitem>
3370+
<para>The pid of the backend currently connected to.</para>
3371+
</listitem>
3372+
</varlistentry>
3373+
33673374
<varlistentry>
33683375
<term><literal>%&gt;</literal></term>
33693376
<listitem><para>The port number at which the database server is listening.</para></listitem>

src/bin/psql/prompt.c

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* %M - database server "hostname.domainname", "[local]" for AF_UNIX
3535
* sockets, "[local:/dir/name]" if not default
3636
* %m - like %M, but hostname only (before first dot), or always "[local]"
37+
* %p - backend pid
3738
* %> - database server port number
3839
* %n - database user name
3940
* %/ - current database
@@ -161,6 +162,15 @@ get_prompt(promptStatus_t status)
161162
if (pset.db)
162163
strlcpy(buf, session_username(), sizeof(buf));
163164
break;
165+
/* backend pid */
166+
case 'p':
167+
if (pset.db)
168+
{
169+
int pid = PQbackendPID(pset.db);
170+
if (pid)
171+
snprintf(buf, sizeof(buf), "%d", pid);
172+
}
173+
break;
164174

165175
case '0':
166176
case '1':

0 commit comments

Comments
 (0)