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.

2
  • 1
    What does the query SELECT * FROM pg_settings show you? Commented Jan 6, 2016 at 7:21
  • @TimBiegeleisen, There are many things out there around 227 rows. Commented Jan 6, 2016 at 7:28

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

5 Comments

After running your query I get the host ::1? Does that mean localhost?
The OS is window 7.
@mak what is the result for select inet_client_addr()
@MAK check this select usename, client_addr from pg_catalog.pg_stat_activity;
@MAK ::1 is the IPv6 version of localhost: en.wikipedia.org/wiki/Localhost
4

Try it for host Name

select *
from pg_settings
where name = 'listen_addresses'

3 Comments

What does column boot_val indicates?
@MAK am check the short_desc column read that description so only posted
I belive start * or localhost would be the most popular results :)
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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.