RE: Psql meta-command conninfo+

From: Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br>
To: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Erik Wienhold <ewie(at)ewie(dot)name>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Psql meta-command conninfo+
Date: 2024-02-12 14:16:00
Message-ID: CP8P284MB2496C7F14594722472C9FEBAEC482@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


>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(at)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(at)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(at)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(at)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.

Attachment Content-Type Size
v14-0001-psql-meta-command-conninfo-plus.patch application/octet-stream 9.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2024-02-12 14:19:26 Re: [PATCH] Add native windows on arm64 support
Previous Message Bertrand Drouvot 2024-02-12 14:06:03 Re: Synchronizing slots from primary to standby