RE: Psql meta-command conninfo+

From: Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br>
To: 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-07 04:13:40
Message-ID: CP8P284MB2496A17A9852265A0F363A6AEC452@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Feb 06, 2024 at 09:45:54PM +0000, Maiquel Grassi wrote:
> My initial idea has always been that they should continue to appear
> because \conninfo+ should show all the things that \conninfo shows and
> add more information. I think that's the purpose of the 'plus.' Now we're
> on a better path than the initial one. We can still add the socket
> directory and the host.

Agreed.

--//--

I believe it's resolved reasonably well this way:

SELECT
pg_catalog.current_database() AS "Database",
current_user AS "User",
pg_catalog.current_setting('server_version') AS "Server Version",
CASE
WHEN pg_catalog.inet_server_addr() IS NULL
THEN 'NULL'
ELSE pg_catalog.inet_server_addr()::text
END AS "Server Address",
pg_catalog.current_setting('port') AS "Port",
CASE
WHEN pg_catalog.inet_client_addr() IS NULL
THEN 'NULL'
ELSE pg_catalog.inet_client_addr()::text
END AS "Client Address",
CASE
WHEN pg_catalog.inet_client_port() IS NULL
THEN 'NULL'
ELSE pg_catalog.inet_client_port()::text
END AS "Client Port",
pg_catalog.pg_backend_pid() AS "Session PID",
CASE
WHEN pg_catalog.current_setting('unix_socket_directories') = ''
THEN 'NULL'
ELSE pg_catalog.current_setting('unix_socket_directories')
END AS "Socket Directory",
CASE
WHEN
pg_catalog.inet_server_addr() IS NULL
AND pg_catalog.inet_client_addr() IS NULL
THEN 'NULL'
WHEN
pg_catalog.inet_server_addr() = pg_catalog.inet_client_addr()
THEN 'localhost'
ELSE pg_catalog.inet_server_addr()::text
END AS "Host";

See below the tests:

[postgres(at)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 | User | Server Version | Server Address | Port | Client Address | Client Port | Session PID | Socket Directory | Host
----------+----------+----------------+----------------+------+----------------+-------------+-------------+------------------+------
postgres | postgres | 17devel | NULL | 5432 | NULL | NULL | 14348 | /tmp | NULL
(1 row)

[postgres(at)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 | User | Server Version | Server Address | Port | Client Address | Client Port | Session PID | Socket Directory | Host
----------+----------+----------------+----------------+------+----------------+-------------+-------------+------------------+-----------
postgres | postgres | 17devel | ::1/128 | 5432 | ::1/128 | 46988 | 14353 | /tmp | localhost
(1 row)

[postgres(at)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 | User | Server Version | Server Address | Port | Client Address | Client Port | Session PID | Socket Directory | Host
----------+----------+----------------+----------------+------+----------------+-------------+-------------+------------------+-----------
postgres | postgres | 17devel | ::1/128 | 5432 | ::1/128 | 46990 | 14356 | /tmp | localhost
(1 row)

[postgres(at)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 | User | Server Version | Server Address | Port | Client Address | Client Port | Session PID | Socket Directory | Host
----------+----------+----------------+----------------+------+----------------+-------------+-------------+------------------+-----------
postgres | postgres | 17devel | 127.0.0.1/32 | 5432 | 127.0.0.1/32 | 35042 | 14359 | /tmp | localhost
(1 row)

[postgres(at)localhost bin]$ ./psql -h 192.168.0.5 -p 5433 -U postgres -d 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 | User | Server Version | Server Address | Port | Client Address | Client Port | Session PID | Socket Directory | Host
----------+----------+----------------+----------------+------+----------------+-------------+-------------+------------------+-----------
postgres | postgres | 16.1 | 192.168.0.5/32 | 5433 | 192.168.0.5/32 | 52783 | 18212 | NULL | localhost
(1 row)

Regards,
Maiquel O. Grassi.

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-02-07 04:33:18 Re: Make COPY format extendable: Extract COPY TO format implementations
Previous Message torikoshia 2024-02-07 04:08:24 Re: RFC: Logging plan of the running query