How to display host, user and port in PostgreSQL

Viewed 3178

I am aiming to use R to connect to a database within PostgreSQL, for which I need to know the database host, port and user.

Do you know how I can find these details within PostgreSQL?

Thanks.

2 Answers

If you are using psql and already logged into the database, you can use the below command to display connection info

\conninfo

SELECT current_database() AS database, user AS user;

SHOW port;

If you are using psql(1), you can discover your hostname like this on linux and OSX, respectively:

\echo hostname

\echo scutil --get ComputerName

Related