2

I am new to postgresql and rails. I am trying to connect to the server and create the necessary databases. When I run rake db:create I get this message:

could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Couldn't create 'ecom_shoppie_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

However the server is running on port 5433. I tried changing the port number in postgresql.conf and database.yml but I get the same error.

I have tried uninstalling and reinstalling postgresql but it always chooses port 5433 instead of 5432.

I followed this tutorial.

Postgresql log file /var/log/postgresql/postgresql-11-main.log:

2019-09-24 06:12:09.951 EDT [3379] LOG:  listening on IPv4 address "127.0.0.1", port 5433
2019-09-24 06:12:10.087 EDT [3379] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2019-09-24 06:12:10.669 EDT [3380] LOG:  database system was shut down at 2019-09-24 05:54:16 EDT
2019-09-24 06:12:11.313 EDT [3379] LOG:  database system is ready to accept connections
2019-09-24 06:12:12.102 EDT [3387] [unknown]@[unknown] LOG:  incomplete startup packet
2019-09-24 06:35:51.836 EDT [3379] LOG:  received fast shutdown request
2019-09-24 06:35:51.887 EDT [3379] LOG:  aborting any active transactions
2019-09-24 06:35:52.001 EDT [3379] LOG:  background worker "logical replication launcher" (PID 3386) exited with exit code 1
2019-09-24 06:35:52.003 EDT [3381] LOG:  shutting down
2019-09-24 06:35:52.842 EDT [3379] LOG:  database system is shut down
2019-09-24 06:35:54.193 EDT [3475] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:35:54.193 EDT [3475] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:35:54.194 EDT [3475] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:35:54.194 EDT [3475] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:35:54.215 EDT [3475] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:36:57.130 EDT [3517] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:36:57.130 EDT [3517] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:36:57.130 EDT [3517] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:36:57.131 EDT [3517] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:36:57.153 EDT [3517] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:38:02.555 EDT [3533] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:38:02.555 EDT [3533] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:38:02.556 EDT [3533] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:38:02.557 EDT [3533] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:38:02.579 EDT [3533] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:42:48.723 EDT [3564] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 06:42:48.723 EDT [3564] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 06:42:48.724 EDT [3564] WARNING:  could not create listen socket for "localhost"
2019-09-24 06:42:48.724 EDT [3564] FATAL:  could not create any TCP/IP sockets
2019-09-24 06:42:48.746 EDT [3564] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 06:44:22.342 EDT [3599] LOG:  listening on IPv4 address "127.0.0.1", port 5433
2019-09-24 06:44:22.463 EDT [3599] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2019-09-24 06:44:23.036 EDT [3600] LOG:  database system was shut down at 2019-09-24 06:35:52 EDT
2019-09-24 06:44:23.772 EDT [3599] LOG:  database system is ready to accept connections
2019-09-24 06:44:24.488 EDT [3607] [unknown]@[unknown] LOG:  incomplete startup packet
2019-09-24 06:49:23.812 EDT [3601] WARNING:  could not flush dirty data: Function not implemented
2019-09-24 08:43:17.387 EDT [3599] LOG:  received fast shutdown request
2019-09-24 08:43:17.446 EDT [3599] LOG:  aborting any active transactions
2019-09-24 08:43:17.693 EDT [3599] LOG:  background worker "logical replication launcher" (PID 3606) exited with exit code 1
2019-09-24 08:43:17.695 EDT [3601] LOG:  shutting down
2019-09-24 08:43:18.620 EDT [3599] LOG:  database system is shut down
2019-09-24 08:43:20.185 EDT [6822] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2019-09-24 08:43:20.185 EDT [6822] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 08:43:20.186 EDT [6822] WARNING:  could not create listen socket for "localhost"
2019-09-24 08:43:20.186 EDT [6822] FATAL:  could not create any TCP/IP sockets
2019-09-24 08:43:20.206 EDT [6822] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 08:44:24.969 EDT [6857] LOG:  could not bind IPv4 address "0.0.0.0": Address already in use
2019-09-24 08:44:24.969 EDT [6857] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 08:44:24.969 EDT [6857] LOG:  could not bind IPv6 address "::": Address already in use
2019-09-24 08:44:24.969 EDT [6857] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2019-09-24 08:44:24.969 EDT [6857] WARNING:  could not create listen socket for "*"
2019-09-24 08:44:24.970 EDT [6857] FATAL:  could not create any TCP/IP sockets
2019-09-24 08:44:24.991 EDT [6857] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.
2019-09-24 08:48:02.243 EDT [6894] LOG:  listening on IPv4 address "127.0.0.1", port 5433
2019-09-24 08:48:02.396 EDT [6894] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2019-09-24 08:48:03.677 EDT [6895] LOG:  database system was shut down at 2019-09-24 08:43:17 EDT
2019-09-24 08:48:04.398 EDT [6894] LOG:  database system is ready to accept connections
2019-09-24 08:48:05.177 EDT [6902] [unknown]@[unknown] LOG:  incomplete startup packet
2019-09-24 08:53:04.168 EDT [6896] WARNING:  could not flush dirty data: Function not implemented
2019-09-24 15:10:39.731 EDT [7350] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:10:39.731 EDT [7350] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:10:39.926 EDT [7351] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:10:39.926 EDT [7351] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:10:53.402 EDT [7355] tjgrevious@tjgrevious FATAL:  database "tjgrevious" does not exist
2019-09-24 15:11:06.360 EDT [7358] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:06.360 EDT [7358] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:11:06.478 EDT [7359] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:06.478 EDT [7359] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:11:40.716 EDT [7374] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:40.716 EDT [7374] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:11:40.853 EDT [7375] tjgrevious@tjgrevious FATAL:  password authentication failed for user "tjgrevious"
2019-09-24 15:11:40.853 EDT [7375] tjgrevious@tjgrevious DETAIL:  Password does not match for user "tjgrevious".
        Connection matched pg_hba.conf line 92: "host    all             all             127.0.0.1/32            md5"
2019-09-24 15:12:02.098 EDT [7378] tjgrevious@tjgrevious FATAL:  database "tjgrevious" does not exist
Zuse
  • 93
  • 1
  • 11
  • "I tried changing the port number in postgresql.conf and database.yml but I get the same error." If the error did not change to report 5433 instead of 5432, then your change to database.yml must not have taken effect. – jjanes Sep 24 '19 at 20:16

2 Answers2

2

try this:

$ rm /usr/local/var/postgres/postmaster.pid
$ brew services restart postgresql

ref:https://stackoverflow.com/a/18832331/13180074

0

Are you sure it's running on 5433? You can see what is actually running using the netstat tool (available on OS X, Windows, and Linux, with command line syntax varying across all three)

If you're on a mac, and you are using the default postgres install, discard that and install it via homebrew.

What ends up happening is that the user installs Pg and starts a server from one packaging, but uses the psql and libpq client from a different packaging. Typically this occurs when they're running Postgres.app or homebrew Pg and connecting with the psql that shipped with the OS. Not only do these sometimes have different default ports, but the Pg that shipped with Mac OS X has a different default unix socket path, so even if the server is running on the same port it won't be listening to the same unix socket.

Most Mac users work around this by just using tcp/ip with psql -h localhost. You can also specify a port if required, eg psql -h localhost -p 5433. You might have multiple PostgreSQL instances running so make sure you're connecting to the right one by using select version() and SHOW data_directory;.

Further answers to this can be found postgresql port confusion 5433 or 5432?

courtsimas
  • 764
  • 1
  • 13
  • 20
  • I am using ubuntu. netstat does not return anything. I have tried `sudo netstat -plunt | grep postgres`. The psql command gives the could not connect to server error too. `service postgresql status` returns : `11/main (port 5433): online`. That is the only way I can check the port. – Zuse Sep 24 '19 at 19:27
  • @Zuse It sounds like PostgreSQL did not actually start, despite what "service" says. Can you find the PostgresSQL log file and see what it says? – jjanes Sep 24 '19 at 20:18
  • log file is too long so I added it to the question – Zuse Sep 24 '19 at 21:48