This error occurs when PostgreSQL rejects a login attempt due to incorrect credentials, misconfigured authentication settings, or a missing password. Common causes include wrong password, incorrect pg_hba.conf authentication method, or users created without passwords.
PostgreSQL uses host-based authentication (pg_hba.conf) to control which users can connect to which databases from which locations. When the server receives a connection attempt, it checks the authentication rules in order and applies the first matching rule. This error means the authentication step failed—either the password was incorrect, the user has no password set, or the authentication method in pg_hba.conf doesn't support password-based login. The error typically appears when connecting via psql, pgAdmin, DBeaver, or application connection strings. It blocks all database access for the affected user until the authentication issue is resolved.
Double-check that you are typing the correct password. Test with a known-good password or reset it if you are unsure.
psql -U postgres -W -h localhostWhen prompted, carefully enter the password. If you forgot the password, proceed to Step 3.
Locate your pg_hba.conf file (usually at /etc/postgresql/<version>/main/pg_hba.conf on Linux, $PGDATA/pg_hba.conf, or C:\Program Files\PostgreSQL\<version>\data\pg_hba.conf on Windows).
Open it and find the line matching your connection type. For example, for local TCP/IP connections from localhost:
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 scram-sha-256Ensure the METHOD column uses a password-based method like scram-sha-256, md5, or password. Do NOT use trust, peer, or ident for remote connections that require passwords.
If you need to change it:
# Before: trust (no password required)
host all all 127.0.0.1/32 trust
# After: scram-sha-256 (password required)
host all all 127.0.0.1/32 scram-sha-256Changes to pg_hba.conf do not take effect until the PostgreSQL service reloads the configuration.
On Linux:
# Reload without restarting (preferred)
sudo systemctl reload postgresql
# Or: restart the service
sudo systemctl restart postgresql
# Or: use pg_ctl if installed
pg_ctl reloadOn macOS (with Homebrew):
brew services reload postgresqlOn Windows:
1. Open Services (services.msc)
2. Find "postgresql-x64-<version>" service
3. Right-click → Restart
If the user has no password or you need to set a new one, log in as a superuser first (using sudo -u postgres on Linux or trusted connection) and run:
ALTER USER postgres PASSWORD 'new_password';Replace postgres with the actual username and new_password with a secure password.
If you cannot log in at all (e.g., on a fresh installation):
On Linux, use the peer authentication method:
sudo -u postgres psql
psql (14.7, server 14.7)
Type "help" for help.
postgres=# ALTER USER postgres PASSWORD 'new_password';
ALTER ROLE
postgres=# \qThen update pg_hba.conf to use password-based authentication.
If the user was created without the LOGIN privilege, grant it:
ALTER ROLE username LOGIN;
ALTER ROLE username PASSWORD 'new_password';Check if a user was created with NOLOGIN by querying the system:
SELECT usename, usesuper, usecreatedb, usecreaterole, usecanlogin
FROM pg_user
WHERE usename = 'username';The usecanlogin column must be true.
After making changes, test the connection:
psql -U postgres -W -h localhostEnter the new password when prompted. If successful, you will see the psql prompt:
psql (14.7, server 14.7)
Type "help" for help.
postgres=# \qIf using an application or connection string, update the connection details and retry.
PostgreSQL 13.3+ defaults to SCRAM-SHA-256 authentication, which is more secure than MD5 but may not be compatible with very old clients. If you need backward compatibility, you can use the MD5 method in pg_hba.conf, but SCRAM is preferred for security.
On local Linux systems, PostgreSQL uses "peer" authentication for the postgres user, which trusts the OS user identity and does not require a password. This is why sudo -u postgres psql works without entering a password—it uses peer authentication, not password authentication.
For Docker or containerized PostgreSQL, if you set the POSTGRES_PASSWORD environment variable, it creates the postgres user with that password during initialization. If you run the container without setting the password, the user may not have a password set, leading to authentication failures.
For production systems, always use strong passwords, enable SSL/TLS encryption for connections, and restrict pg_hba.conf rules to only allow connections from trusted IP ranges. Avoid using "trust" authentication except for local development on secure machines.
ERROR: syntax error at end of input
Syntax error at end of input in PostgreSQL
Bind message supplies N parameters but prepared statement requires M
Bind message supplies N parameters but prepared statement requires M in PostgreSQL
Multidimensional arrays must have sub-arrays with matching dimensions
Multidimensional arrays must have sub-arrays with matching dimensions
ERROR: value too long for type character varying
Value too long for type character varying
insufficient columns in unique constraint for partition key
How to fix "insufficient columns in unique constraint for partition key" in PostgreSQL