sexta-feira, 18 de março de 2016

Error: psql: could not connect to server: Connection refused Is the server running on host (...) and accepting TCP/IP connections on port 5432

As I'm supporting a considerable set of applications running from Oracle and Sql Server to Postgres. 
After running a clean install on CentOS 7, I tried a remote connection using HeidiSQL to the postgres instance and ran into this error:

Error: psql: could not connect to server: Connection refused Is the server running on host (...) and accepting TCP/IP connections on port 5432

My imediate response was to check if Postgres was up and running on port 5432:

systemctl status postgresql

● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2016-03-18 09:22:51 EDT; 8min ago
  Process: 10015 ExecStop=/usr/bin/pg_ctl stop -D ${PGDATA} -s -m fast (code=exited, status=0/SUCCESS)
  Process: 10022 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
  Process: 10016 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 10026 (postgres)
   CGroup: /system.slice/postgresql.service
           ├─10026 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
           ├─10027 postgres: logger process
           ├─10029 postgres: checkpointer process
           ├─10030 postgres: writer process
           ├─10031 postgres: wal writer process
           ├─10032 postgres: autovacuum launcher process
           └─10033 postgres: stats collector process


Ok, all is running, so what is the problem? After some googling I found this post on revsys. Postgres uses some config files to actually set some rules. The listen_address configuration on /var/lib/pgsql/data/postgresql.conf, just sets which address to listen to and take connections. So I ended up setting it like this:

nano /var/lib/pgsql/data/postgresql.conf

listen_addresses = '*' 

The '*' sets Postgres to listen on localhost and real ip addresses. That resolved this message, and took me into another error message (and in a few minutes, another blog post... :)

cheers!


Check out my new book about R Language http://www.amazon.com/dp/B00SX6WA06

Nenhum comentário:

Postar um comentário

Leave your comment here!