no pg_hba.conf entry for host
This error occurs when your IP address or authentication method isn't configured in pg_hba.conf.
The no pg_hba.conf entry error means PostgreSQL's host-based authentication rejected your connection.
Understanding the Error
Your connection doesn't match any entry in pg_hba.conf.
Understanding pg_hba.conf
- TYPE: local (socket) or host (TCP/IP)
- DATABASE: which databases this applies to
- USER: which users this applies to
- ADDRESS: IP address or range (for host type)
- METHOD: authentication method (md5, scram-sha-256, peer, trust, etc.)
Common Causes
1. IP Address Not Allowed
Your IP address isn't in any allowed range in pg_hba.conf.
2. User Not Allowed
The specific user isn't permitted for that database.
3. Wrong Authentication Method
The configured method doesn't match how you're trying to authenticate.
How to Fix It
Solution 1: Add Your IP to pg_hba.conf
BASH
Add entry for your IP:
Solution 2: Reload Configuration
BASH
Solution 3: Allow All Local Connections
Solution 4: Configure for Docker
Solution 5: Use SCRAM Authentication
Then set password encryption:
SQL
Solution 6: Allow Specific Database/User
Authentication Methods
Best Practices
- Use scram-sha-256 instead of md5
- Be specific with IP ranges
- Never use trust in production
- Document changes to pg_hba.conf
- Test changes before applying to production