Re: Psql meta-command conninfo+
Pavel Luzanov <p.luzanov@postgrespro.ru>
From: Pavel Luzanov <p.luzanov@postgrespro.ru>
To: Maiquel Grassi <grassi@hotmail.com.br>,
Nathan Bossart <nathandbossart@gmail.com>
Cc: Erik Wienhold <ewie@ewie.name>,
"pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2024-02-09T07:58:15Z
Lists: pgsql-hackers
Hi, Maiquel!
The patch v10 build ends with a warning:
$ make -j --silent
describe.c:911:1: warning: no previous prototype for ‘listConnectionInformation’ [-Wmissing-prototypes]
911 | listConnectionInformation()
| ^~~~~~~~~~~~~~~~~~~~~~~~~
About terms.
postgres@postgres(17.0)=# \x \conninfo+
Expanded display is on.
Current Connection Information
-[ RECORD 1 ]------+---------
Database | postgres
Authenticated User | postgres
System User |
Current User | postgres
Session User | postgres
*Session PID | 951112 *Server Version | 17devel
Server Address |
Server Port | 5401
Client Address |
Client Port |
Socket Directory | /tmp
Host |
It looks like "Session PID" is a new term for the server process identifier.
How about changing the name to "Backend PID" (from pg_backend_pid) or even PID (from pg_stat_activity)?
On 08.02.2024 17:58, Maiquel Grassi wrote:
> > 1. > + if (db == NULL) > + printf(_("You are currently not connected to
> a database.\n")); > > This check is performed for \conninfo, but not
> for \conninfo+.
> 1. The connection check for the case of \conninfo+ is handled by
> "describe.c" itself since it deals with queries. I might be mistaken,
> but I believe that by using "printQuery()" via "describe.c", this is
> already ensured, and there is no need to evaluate the connection status.
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.
--
Pavel Luzanov
Postgres Professional:https://postgrespro.com
Commits
-
psql: Change new \conninfo to use SSL instead of TLS
- 6d6480066c1a 18.0 landed
-
Change \conninfo to use tabular format
- bba2fbc6238b 18.0 landed
-
Update extension lookup routines to use the syscache
- d8df7ac5c04c 18.0 cited
-
Improve COPY TO performance when server and client encodings match
- b619852086ed 17.0 cited
-
doc: Remove superfluous bracket in synopsis
- fdfb92c0307c 17.0 cited
-
Remove psql support for server versions preceding 9.2.
- cf0cab868aa4 15.0 cited