3

I just created a PostgreSQL database on my laptop (following these instructions), which is running Linux CentOS 7.

Now I would like to understand what is the hostname address of my default database. I thought it was localhost but it's not.

I want to get to know the name or the IP address to use with the psql -h command. Basically, running this psql -h HOSTNAME command should let me have the same result of the psql command alone, that is letting me connect to my database.

What is the hostname address of my default database?

> service postgresql status 

states:

● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2017-03-30 14:40:30 EDT; 1 day 1h ago Main PID: 2256 (postgres

while both psql -h 127.0.0.1 and psql -h 127.0.0.1 -U davide produce this message:

psql: FATAL: Ident authentication failed for user "davide"`

  • Thanks but both did not work. The pg_lsclusters does not exist to me. The psql -h 127.0.0.1 command fails for my user and for the postgres default user. Using the result of the hostname command does not work, the system says: Is the server running on host hostname and accepting TCP/IP connections on port 5432? – DavideChicco.it Mar 31 '17 at 19:16
  • service postgresql status states ● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2017-03-30 14:40:30 EDT; 1 day 1h ago Main PID: 2256 (postgres – DavideChicco.it Mar 31 '17 at 20:31
  • psql -h 127.0.0.1 and psql -h 127.0.0.1 -U davide produce this message: psql: FATAL: Ident authentication failed for user "davide" – DavideChicco.it Mar 31 '17 at 20:32
  • Discussion moved to chat. – ypercubeᵀᴹ Mar 31 '17 at 21:04
2

The default on Linux is to connect over unix domain sockets, rather than TCP, so there is no hostname.

If you want to reproduce the default with an explicit option, it would be something like -h /var/run/postgresql (if you installed from yum) or -h /tmp (if you installed from sources using the default settings).

1

If you're connecting from the same machine, use localhost

A given computer can run multiple instances of PostgreSQL on different sockets (address:port pairs). The default port is 5432

A given PostgreSQL server can run multiple databases on the same instance. The postgres database is always there. There's no "default database" though really.

Are you sure the service is enabled and running? Did you set listen_addresses in postgresql.conf and set up authentication in pg_hba.conf?

Is the service actually running?

  • psql -h localhost -U davide and psql -h localhost both produce this error: psql: FATAL: Ident authentication failed for user "davide" – DavideChicco.it Mar 31 '17 at 20:33
  • @DavideChicco.it you probably want to setup md5 authentication in pg_hba.conf – Neil McGuigan Apr 1 '17 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.