>I found that \conninfo and \conninfo+ act differently when the connection is >broken. >I used pg_terminate_backend function from another session to terminate an open >psql session. >After that, \conninfo does not see the connection break (surprisingly!), and >\conninfo+ returns an error: > >postgres@postgres(17.0)=# \conninfo+ >FATAL: terminating connection due to administrator command >server closed the connection unexpectedly > This probably means the server terminated abnormally > before or while processing the request. >The connection to the server was lost. Attempting reset: Succeeded. > >postgres@postgres(17.0)=# \conninfo >You are connected to database "postgres" as user "postgres" via socket in >"/tmp" at port "5401". > >Another surprise is that this check: if (db == NULL) did not work in both >cases.
--//-- Hi Pavel! (v14) The "if (db == NULL)" has been removed, as well as the message inside it. To always maintain the same error messages, I changed the validation of "\conninfo" to match the validation used for "\conninfo+". Therefore, now "\conninfo" and "\conninfo+" return the same error when "pg_terminate_backend()" terminates this session through another session. The result of the adjustment is as follows: Case 1 ("\conninfo+"): [postgres@localhost bin]$ ./psql -x psql (17devel) Type "help" for help. postgres=# \conninfo You are connected to database "postgres" as user "postgres" via socket in "/tmp" at port "5432". postgres=# \conninfo+ Current Connection Information -[ RECORD 1 ]------+--------- Database | postgres Authenticated User | postgres System User | Current User | postgres Session User | postgres Backend PID | 24381 Server Address | Server Port | 5432 Client Address | Client Port | Socket Directory | /tmp Host | postgres=# \conninfo+ FATAL: terminating connection due to administrator command server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Succeeded. Case 2 ("\conninfo"): [postgres@localhost bin]$ ./psql -x psql (17devel) Type "help" for help. postgres=# \conninfo You are connected to database "postgres" as user "postgres" via socket in "/tmp" at port "5432". postgres=# \conninfo+ Current Connection Information -[ RECORD 1 ]------+--------- Database | postgres Authenticated User | postgres System User | Current User | postgres Session User | postgres Backend PID | 24539 Server Address | Server Port | 5432 Client Address | Client Port | Socket Directory | /tmp Host | postgres=# \conninfo FATAL: terminating connection due to administrator command server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. The connection to the server was lost. Attempting reset: Succeeded. In both cases, the sessions were terminated by another session. Regards, Maiquel Grassi.
v14-0001-psql-meta-command-conninfo-plus.patch
Description: v14-0001-psql-meta-command-conninfo-plus.patch