summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund2015-07-07 11:40:44 +0000
committerAndres Freund2015-07-07 11:40:44 +0000
commit275f05c990c46f8dfe3cb46a3279521bda9e9e27 (patch)
tree36cf85d8290248722ab6b4f37b5f5b86dc71e3d5
parentb2f6f749c7a5936adbb555e248e8e4df35c00a4a (diff)
Add psql PROMPT variable showing the pid of the connected to backend.
The substitution for the pid is %p. Author: Julien Rouhaud Discussion: [email protected]
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml7
-rw-r--r--src/bin/psql/prompt.c10
2 files changed, 17 insertions, 0 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index d17d405f20..ac609fdf56 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -3365,6 +3365,13 @@ testdb=&gt; <userinput>INSERT INTO my_table VALUES (:'content');</userinput>
</varlistentry>
<varlistentry>
+ <term><literal>%p</literal></term>
+ <listitem>
+ <para>The pid of the backend currently connected to.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>%&gt;</literal></term>
<listitem><para>The port number at which the database server is listening.</para></listitem>
</varlistentry>
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 89842673f8..96e669a6ff 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -34,6 +34,7 @@
* %M - database server "hostname.domainname", "[local]" for AF_UNIX
* sockets, "[local:/dir/name]" if not default
* %m - like %M, but hostname only (before first dot), or always "[local]"
+ * %p - backend pid
* %> - database server port number
* %n - database user name
* %/ - current database
@@ -161,6 +162,15 @@ get_prompt(promptStatus_t status)
if (pset.db)
strlcpy(buf, session_username(), sizeof(buf));
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 '1':