Error Codes Wiki

PostgreSQL Common Errors — Connection Refused, Authentication, and Query Failures

Warningdatabase

Overview

Fix common PostgreSQL errors including connection refused, authentication failures, permission denied, and query syntax errors on Linux servers.

Key Details

  • PostgreSQL uses pg_hba.conf for client authentication and postgresql.conf for server settings
  • Default installation only allows local connections — listen_addresses must be changed for remote access
  • Common errors: FATAL: password authentication failed, could not connect to server, permission denied for table
  • PostgreSQL roles (users) and database ownership affect what queries can be executed
  • Connection pooling (PgBouncer, Pgpool-II) adds another layer of configuration and potential errors

Common Causes

  • PostgreSQL not listening on the expected address/port (listen_addresses = 'localhost' by default)
  • pg_hba.conf not allowing the client's authentication method or IP range
  • User password incorrect or role does not exist in the database
  • Insufficient privileges for the database role to access specific tables or schemas

Steps

  1. 1Check if PostgreSQL is running: 'systemctl status postgresql' and 'ss -tlnp | grep 5432'
  2. 2For remote connections: set 'listen_addresses = '*'' in postgresql.conf and add client entry in pg_hba.conf
  3. 3Reset user password: 'sudo -u postgres psql -c "ALTER USER myuser PASSWORD 'newpassword';"'
  4. 4Grant permissions: 'GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser; GRANT ALL ON ALL TABLES IN SCHEMA public TO myuser;'
  5. 5Check logs: 'tail -50 /var/log/postgresql/postgresql-[version]-main.log' for detailed error messages

Tags

postgresqldatabaseconnectionauthenticationpermissions

More in Database

Frequently Asked Questions

1) Set listen_addresses='*' in postgresql.conf. 2) Add 'host all all 0.0.0.0/0 scram-sha-256' in pg_hba.conf. 3) Restart PostgreSQL. 4) Open port 5432 in firewall. Use specific IP ranges instead of 0.0.0.0/0 for security.