From e883f551227116e87c643d588f8c957f2defaeeb Mon Sep 17 00:00:00 2001 From: "okbob@github.com" Date: Sat, 4 Feb 2023 18:29:42 +0100 Subject: [PATCH] implementation of BACKEND_PID psql's variable --- doc/src/sgml/ref/psql-ref.sgml | 11 +++++++++++ src/bin/psql/command.c | 4 ++++ src/bin/psql/help.c | 2 ++ 3 files changed, 17 insertions(+) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index dc6528dc11..92180a2eae 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3902,6 +3902,17 @@ bar + + BACKEND_PID + + + The id of server process of the current connection. + This is set every time you connect to a database (including + program start-up), but can be changed or unset. + + + + COMP_KEYWORD_CASE diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index b5201edf55..5a9b0e1569 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3783,6 +3783,9 @@ SyncVariables(void) SetVariable(pset.vars, "PORT", PQport(pset.db)); SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding)); + snprintf(vbuf, sizeof(vbuf), "%d", PQbackendPID(pset.db)); + SetVariable(pset.vars, "BACKEND_PID", vbuf); + /* this bit should match connection_warnings(): */ /* Try to get full text form of version, might include "devel" etc */ server_version = PQparameterStatus(pset.db, "server_version"); @@ -3817,6 +3820,7 @@ UnsyncVariables(void) SetVariable(pset.vars, "ENCODING", NULL); SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL); SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL); + SetVariable(pset.vars, "BACKEND_PID", NULL); } diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index e45c4aaca5..61c6edd0ba 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -396,6 +396,8 @@ helpVariables(unsigned short int pager) HELP0(" AUTOCOMMIT\n" " if set, successful SQL commands are automatically committed\n"); + HELP0(" BACKEND_PID\n" + " id of server process of the current connection\n"); HELP0(" COMP_KEYWORD_CASE\n" " determines the case used to complete SQL key words\n" " [lower, upper, preserve-lower, preserve-upper]\n"); -- 2.39.1