Add psql PROMPT variable showing the pid of the connected to backend.
authorAndres Freund
Tue, 7 Jul 2015 11:40:44 +0000 (13:40 +0200)
committerAndres Freund
Tue, 7 Jul 2015 11:40:44 +0000 (13:40 +0200)
The substitution for the pid is %p.

Author: Julien Rouhaud
Discussion: 116262CF971C844FB6E793F8809B51C6E99D48@BPXM02GP.gisp.nec.co.jp

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/prompt.c

index d17d405f20fb1e47c9ad3e2f3ca1607ae43fb893..ac609fdf56a87389ee1d9f8952a3f41c18fc6370 100644 (file)
@@ -3364,6 +3364,13 @@ testdb=> INSERT INTO my_table VALUES (:'content');
         
       
 
+      
+        %p
+        
+         The pid of the backend currently connected to.
+        
+      
+
       
         %>
         The port number at which the database server is listening.
index 89842673f87fce0160fe9f1d6b203321271a315e..96e669a6ff5caa82097689cddc67ac07cfcbc6a2 100644 (file)
@@ -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':