3

I want to write a query which should result me the following details:

  1. Host,
  2. Port,
  3. Username.

Like we get in the PgAdmin as shown in the below picture:

enter image description here

As per a_horse_with_no_name said in this answer gives me only port number.

Community
  • 1
  • 1
MAK
  • 6,824
  • 25
  • 74
  • 131

3 Answers3

8
SELECT CURRENT_USER usr
      ,inet_server_addr() host -- use inet_client_addr() to get address of the remote connection
      ,inet_server_port() port -- use inet_client_port() to get port of the remote connection

System Information Functions

Vivek S.
  • 19,945
  • 7
  • 68
  • 85
4

Try it for host Name

select *
from pg_settings
where name = 'listen_addresses'
Sathish
  • 4,419
  • 4
  • 30
  • 59
0

Building on w͏̢in̡͢g͘̕ed̨p̢͟a͞n͏͏t̡͜͝he̸r̴'s answer above;

SELECT CURRENT_USER usr, :'HOST' host, inet_server_port() port;

This uses psql's built in HOST variable, documented here

  • An interesting approach, but worth noting: this only works in the `psql` tool, not using other clients, and for a Unix socket connection it returns the socket path. – EM0 Jul 16 '20 at 12:45