RE: Psql meta-command conninfo+

Поиск
Список
Период
Сортировка
От Maiquel Grassi
Тема RE: Psql meta-command conninfo+
Дата
Msg-id CP8P284MB2496A17A9852265A0F363A6AEC452@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответ на Re: Psql meta-command conninfo+  (Nathan Bossart <nathandbossart@gmail.com>)
Ответы Re: Psql meta-command conninfo+  (Erik Wienhold <ewie@ewie.name>)
Re: Psql meta-command conninfo+  (Pavel Luzanov <p.luzanov@postgrespro.ru>)
Список 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@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@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@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@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@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.
Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: torikoshia
Дата:
Сообщение: Re: RFC: Logging plan of the running query
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Make COPY format extendable: Extract COPY TO format implementations