What is the difference between postgresql.conf and pg_hba.conf?

IntermediateConceptPostgreSQL
Answer

Short answer

postgresql.conf holds server settings — what the server listens on and how it behaves (listen_addresses, port, max_connections, memory, logging, WAL). pg_hba.conf holds client authentication rules — who can connect from where and how.

Key postgresql.conf settings

listen_addresses = '*'           # listen on all interfaces (default: localhost)
port = 5432
max_connections = 200
shared_buffers = 2GB             # ~25% of RAM is a common starting point
work_mem = 16MB
log_min_duration_statement = 500 # log queries slower than 500 ms
ssl = on

Both are needed for remote access

  1. listen_addresses so the server accepts network connections.
  2. A pg_hba.conf rule so the client is allowed to authenticate.
  3. Firewall/security group open on 5432.

Reload vs restart

  • pg_hba.conf and most logging settings → reload (SELECT pg_reload_conf();).
  • listen_addresses, shared_buffers, max_connections → restart.
SELECT name, setting, pending_restart FROM pg_settings WHERE pending_restart;
SHOW config_file;   SHOW hba_file;

What to say in the interview

"postgresql.conf configures the server — listen address, memory, connections, logging; pg_hba.conf configures client authentication. Remote access needs both plus the firewall. Some settings need only a reload, others like shared_buffers need a restart."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: PostgreSQL basics

More on PostgreSQL