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
listen_addressesso the server accepts network connections.- A
pg_hba.confrule so the client is allowed to authenticate. - Firewall/security group open on 5432.
Reload vs restart
pg_hba.confand 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."
More on PostgreSQL
How do you set up PostgreSQL and log in with psql?BeginnerHow do you create a database, tables, users and query data in PostgreSQL?BeginnerHow do you back up and restore a PostgreSQL database?BeginnerWhat is PostgreSQL and why is it so popular?BeginnerHow is PostgreSQL organised: cluster, database, schema and table?BeginnerHow do you connect to PostgreSQL from the command line?Beginner