diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 38253fa..76b7276 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -204,6 +204,14 @@ exec_command(const char *cmd, success = do_pset("format", "unaligned", &pset.popt, pset.quiet); } + /* + * \bid -- show backend pid + */ + if (strcmp(cmd,"bid") == 0) + { + success = showBackendPid(); + } + /* \C -- override table title (formerly change HTML caption) */ else if (strcmp(cmd, "C") == 0) { diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index db56809..7a845d8 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -737,6 +737,36 @@ listAllDbs(const char *pattern, bool verbose) return true; } +/* + * \bid + * + * Show Backend PID + */ +bool +showBackendPid() +{ + PQExpBufferData buf; + PGresult *res; + printQueryOpt myopt = pset.popt; + + initPQExpBuffer (&buf); + printfPQExpBuffer(&buf, "SELECT pg_backend_pid as pid from pg_backend_pid()"); + + res = PSQLexec(buf.data); + termPQExpBuffer(&buf); + if(!res) + return false; + + myopt.nullPrint = NULL; + myopt.title = _("Backend Process ID"); + myopt.translate_header = true; + + printQuery(res, &myopt, pset.queryFout, pset.logfile); + + PQclear(res); + return true; + +} /* * List Tables' Grant/Revoke Permissions diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h index 822e71a..7c77bd5 100644 --- a/src/bin/psql/describe.h +++ b/src/bin/psql/describe.h @@ -57,6 +57,9 @@ extern bool listTSTemplates(const char *pattern, bool verbose); /* \l */ extern bool listAllDbs(const char *pattern, bool verbose); +/* \bid */ +extern bool showBackendPid(void); + /* \dt, \di, \ds, \dS, etc. */ extern bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem);