RE: Psql meta-command conninfo+ - Mailing list pgsql-hackers

From Maiquel Grassi
Subject RE: Psql meta-command conninfo+
Date
Msg-id CP8P284MB24961361A9C1D32C28A7EC0EEC452@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM
Whole thread Raw
In response to Re: Psql meta-command conninfo+  (Pavel Luzanov <p.luzanov@postgrespro.ru>)
Responses Re: Psql meta-command conninfo+
List pgsql-hackers
  This is a good idea about extended connection info.

  On 07.02.2024 07:13, Maiquel Grassi wrote:
SELECT
...
  current_user AS "User",
This will be inconsistent with \conninfo. \conninfo returns authenticated user (PQuser), not the current_user. It might be worth showing current_user, session_user, and authenticated user, but I can't find the appropriate sql function for PQuser. What about to include system_user function? It shows useful authentication details. Also, it seems that the verbose parameter in the listConnectionInformation is unnecessary.

--//--

Hi,

Tks Pavel.

Analyzing the functions' code more thoroughly, it seems to make more sense.
I liked your suggestions and implemented them for validation.
Regarding "system_user," I believe it is valid and also added it to the row.

"Also, it seems that the verbose parameter in the listConnectionInformation is unnecessary."
Could you point out exactly the line or code snippet you are referring to?

To print the string from the "Authenticated User" column, I chose to use PQuser(pset.db) directly. I did the same for the "Host" column, opting for PQhost(pset.db). This does not contradict the result of \conninfo.

Here are the tests as usual, and v6 patch.

[postgres@localhost bin]$ ./psql
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
 Database | Authenticated User | Current User | Session User | System User | Server Version | Server Address | Server Port | Client Address | Client Port | Session PID | Socket Directory | Host
----------+--------------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+-------------+------------------+------
 postgres | postgres           | postgres     | postgres     |             | 17devel        |                | 5432        |                |             |       17240 | /tmp             |
(1 row)

postgres=# \q
[postgres@localhost bin]$ ./psql -h ::1
psql (17devel)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "::1" at port "5432".
postgres=# \conninfo+
                                                                                  Current Connection Information
 Database | Authenticated User | Current User | Session User | System User | Server Version | Server Address | Server Port | Client Address | Client Port | Session PID | Socket Directory | Host
----------+--------------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+-------------+------------------+------
 postgres | postgres           | postgres     | postgres     |             | 17devel        | ::1            | 5432        | ::1            |       47024 |       17242 | /tmp             | ::1
(1 row)

postgres=# \q
[postgres@localhost bin]$ ./psql -h 127.0.0.1
psql (17devel)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "127.0.0.1" at port "5432".
postgres=# \conninfo+
                                                                                    Current Connection Information
 Database | Authenticated User | Current User | Session User | System User | Server Version | Server Address | Server Port | Client Address | Client Port | Session PID | Socket Directory |   Host
----------+--------------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+-------------+------------------+-----------
 postgres | postgres           | postgres     | postgres     |             | 17devel        | 127.0.0.1      | 5432        | 127.0.0.1      |       35076 |       17245 | /tmp             | 127.0.0.1
(1 row)

postgres=# \q
[postgres@localhost bin]$ ./psql -h localhost
psql (17devel)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "localhost" (address "::1") at port "5432".
postgres=# \conninfo+
                                                                                    Current Connection Information
 Database | Authenticated User | Current User | Session User | System User | Server Version | Server Address | Server Port | Client Address | Client Port | Session PID | Socket Directory |   Host
----------+--------------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+-------------+------------------+-----------
 postgres | postgres           | postgres     | postgres     |             | 17devel        | ::1            | 5432        | ::1            |       47028 |       17248 | /tmp             | localhost
(1 row)

postgres=# \q
[postgres@localhost bin]$ ./psql -h 192.168.0.5 -p 5433 -d postgres -U postgres
psql (17devel, server 16.1)
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" on host "192.168.0.5" at port "5433".
postgres=# \conninfo+
                                                                                     Current Connection Information
 Database | Authenticated User | Current User | Session User | System User | Server Version | Server Address | Server Port | Client Address | Client Port | Session PID | Socket Directory |    Host
----------+--------------------+--------------+--------------+-------------+----------------+----------------+-------------+----------------+-------------+-------------+------------------+-------------
 postgres | postgres           | postgres     | postgres     |             | 16.1           | 192.168.0.5    | 5433        | 192.168.0.5    |       60115 |       28896 |                  | 192.168.0.5
(1 row)

Regards,
Maiquel O. Grassi.
Attachment

pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: Set log_lock_waits=on by default
Next
From: Tom Lane
Date:
Subject: Re: Set log_lock_waits=on by default