PostgreSQL "Password Authentication Failed for User": Why One Error Hides Several Problems, and How to Find Yours (RDS Too)
"FATAL: password authentication failed for user" sounds like a wrong password, and sometimes it is. But PostgreSQL deliberately prints the exact same message when the user doesn't exist at all, and when the password is right but has expired, so that nobody can probe which accounts exist. So the fix starts with one check: read the server's log, where the real reason sits on a DETAIL line right under the error: "Role "nobody" does not exist", "User "app" has an expired password", or a plain mismatch. On Amazon RDS, you read it in the database's logs. Two causes don't even reach the server as you think: a password containing $ loses part of itself when you put it in double quotes in a shell, and a password containing @ or : breaks a connection URL unless it's percent-encoded. This page shows each cause with the message it produces, how to read the log locally and on RDS, and how to reset a password, including the RDS master user's.
Ethan, a developer, gave the reporting service for his friend Jake's phone repair shop a strong new database password with symbols in it. He pasted it into a deploy script, ran the script, and got "password authentication failed". He checked the password three times. It was right. The script just never sent it.
New to these terms? A PostgreSQL role is a database user. Amazon RDS runs PostgreSQL for you, and the user you chose when creating the database is its master user.
One message, several different problems
Here's the error a client shows, from psql connecting to PostgreSQL 17:
psql: error: connection to server at "127.0.0.1", port 15417 failed: FATAL: password authentication failed for user "app"That exact text came back for each of these, and only the server's log tells them apart:
| What's actually wrong | Client sees | Server log's DETAIL line |
|---|---|---|
| Wrong password | password authentication failed | Connection matched ... the pg_hba.conf rule used |
| User doesn't exist | password authentication failed | Role "nobody" does not exist. |
Password expired (VALID UNTIL) | password authentication failed | User "app" has an expired password. |
| Password mangled by the shell | password authentication failed | Same as a wrong password |
| Role not allowed to log in | role "app" is not permitted to log in | (the client message already says it) |
Hiding the difference from the client is a security feature: an attacker can't use the error to learn which user names exist. It also means that, for you, guessing is slow and reading the log is fast.
Jake: "So 'wrong password' might not mean wrong password?"
Ethan: "It means 'I'm not telling you which part was wrong'. The log tells me. The client never does."
Read the DETAIL line: locally and on RDS
On a server you run, the PostgreSQL log holds the full story. Here it is for a user that doesn't exist:
FATAL: password authentication failed for user "nobody"
DETAIL: Role "nobody" does not exist.And for an expired password:
FATAL: password authentication failed for user "app"
DETAIL: User "app" has an expired password.On Amazon RDS for PostgreSQL, you can't open the log file directly, but you can read it in the RDS console, on the database's logs section, or with the CLI. This takes the newest log file's name and prints each FATAL line with the line after it:
💻 Where to run these commands
Easiest: AWS CloudShell, nothing to install. Sign in to the AWS Management Console, choose your Region at the top right, then click the CloudShell icon (a small >_ terminal symbol) in the top bar, or type CloudShell in the search box and open it. When the $ prompt appears, paste a command and press Enter. CloudShell already has the AWS CLI, uses your console permissions and costs nothing extra.
On your own computer: install AWS CLI version 2 (installers for Windows, macOS and Linux are on the AWS CLI page), run aws configure once (or aws configure sso if your company signs in through single sign-on), and check it works with aws sts get-caller-identity. Then paste commands into Terminal on Mac or Linux, or PowerShell or Command Prompt on Windows.
Windows tip: a line ending in a backslash ( \ ) continues on the next line in CloudShell, Mac and Linux. In PowerShell use a backtick ( ` ) instead, in Command Prompt a caret ( ^ ), or simply join the lines into one. JSON inside single quotes works as shown in CloudShell; on Windows, save the JSON in a file and pass it as file://name.json.
Replace example values such as my-bucket, my-function, 111122223333 (an account ID) and us-east-1 with your own.
LOG=$(aws rds describe-db-log-files --db-instance-identifier shop-reports \
--query "DescribeDBLogFiles[-1].LogFileName" --output text)
aws rds download-db-log-file-portion --db-instance-identifier shop-reports \
--log-file-name "$LOG" --query LogFileData --output text | grep -A1 FATALIf the failure happened earlier, list more files by changing [-1] to [-3:]. If you'd rather search than download, publish the PostgreSQL log to CloudWatch Logs from the database's settings, and search for "password authentication failed" there.
Passwords with $ in them: the shell eats part of it
Ethan's password was Shop$2026!x. He passed it to his script like this, and it failed every time:
PGPASSWORD="Shop$2026!x" psql -h shop-reports.c1abcdexample.us-east-1.rds.amazonaws.com -U web -d postgresInside double quotes, the shell treats $2 as a variable, and replaces it with nothing. Here's what actually reached PostgreSQL:
bash -c 'echo "Shop$2026!x"'Shop026!xSingle quotes stop the shell from touching anything inside them, so the same command with single quotes works:
PGPASSWORD='Shop$2026!x' psql -h shop-reports.c1abcdexample.us-east-1.rds.amazonaws.com -U web -d postgresIn an interactive terminal, ! inside double quotes can also be rewritten, by the shell's history feature. Ways to hand a password to psql or a script, from riskiest to safest:
- Double quotes on the command line: the shell can change
$and!. - Single quotes on the command line: sent as typed, but saved in your shell history.
- Typing it at
psql's password prompt: not saved, but not usable in scripts. - A
~/.pgpassfile readable only by you: no quoting at all, and scripts can use it. - A secret fetched at run time from Secrets Manager: nothing stored on the machine, and rotation doesn't break anything.
Passwords in connection URLs: percent-encode the symbols
Many apps take a single connection URL, postgresql://user:password@host:port/database. The characters @, : and / have meanings in that format, so a password containing them confuses the parser. With the password p@ss:w0rd/1, the client misread the URL before it even reached the server:
psql: error: invalid integer value "w0rd" for connection option "port"Other clients may instead connect to the wrong host or send the wrong password, and then you get "password authentication failed". The fix is to percent-encode those characters in the URL:
| Character in the password | Write it in the URL as |
|---|---|
@ | %40 |
: | %3A |
/ | %2F |
% | %25 |
# | %23 |
? | %3F |
The encoded URL for p@ss:w0rd/1:
psql "postgresql://app:p%40ss%3Aw0rd%2F1@shop-reports.c1abcdexample.us-east-1.rds.amazonaws.com:5432/postgres"That connected. Python's urllib.parse.quote(password, safe="") produces the encoded form if you build URLs in code.
The user doesn't exist: check the name
Because a missing user gives the same message as a wrong password, check the name before resetting anything. List the roles that can log in:
SELECT rolname, rolcanlogin, rolvaliduntil FROM pg_roles WHERE rolcanlogin ORDER BY rolname;Common mix-ups: the RDS master user's name isn't always postgres; it's whatever was entered when the database was created. You can read it without connecting:
aws rds describe-db-instances --db-instance-identifier shop-reports \
--query "DBInstances[0].MasterUsername" --output textRole names are also case-sensitive when they were created with double quotes, so "Reports" and reports are different roles.
Expired passwords: VALID UNTIL
A role can carry an expiry date for its password, and after that date, the right password fails with the same message, while the log says "has an expired password". The rolvaliduntil column in the query above shows it. To lift the expiry, or set a new date:
ALTER ROLE app VALID UNTIL 'infinity';Expiry dates are often set by security policies or account-creation scripts and forgotten. If you use them on purpose, put the renewal in a calendar, or rotate the password automatically with Secrets Manager instead.
Reset a password, including the RDS master user's
For any role, a user with the right to manage roles can set a new password:
ALTER ROLE app PASSWORD 'a-new-long-password';For the RDS master user, when nobody can log in to run that, reset it from AWS:
aws rds modify-db-instance --db-instance-identifier shop-reports \
--master-user-password 'a-new-long-password' --apply-immediatelyThe change takes a short while to apply; the database's status shows it as it goes. If you'd rather never handle the master password at all, RDS can manage it in Secrets Manager for you. If the database seems stuck afterwards, our RDS "modifying" guide explains the states.
Jake: "So the master key can always be recut, as long as we can reach AWS?"
Ethan: "Exactly. The database lets AWS change the lock even when nobody inside can open the door."
Work through it in order
When you see "password authentication failed", this order finds the cause fastest:
- Read the server log's
DETAILline for that attempt. It names the cause in most cases. - If it says the role doesn't exist, check the user name and the database host you're connecting to.
- If it mentions an expired password, run
ALTER ROLE ... VALID UNTILor set a new password. - If the log shows a plain mismatch, check how the password reaches the client: shell quoting, URL encoding, environment variables, or an old value in a config file.
- Only then reset the password, and store the new one where every client reads it from the same place.
Troubleshooting by symptom
FATAL: password authentication failed for user
Read the server log's DETAIL line. It says whether the role is missing, the password expired or it simply didn't match.
The password is right but still fails in a script
The shell probably changed it. Put it in single quotes, or read it from .pgpass or Secrets Manager.
invalid integer value for connection option "port"
The password in the URL contains : or @. Percent-encode those characters.
role is not permitted to log in
The role has NOLOGIN. Run ALTER ROLE name LOGIN, or connect as a different role.
Works in psql, fails in the app
The app uses a different user, database or stored password. Compare its settings with what you typed in psql.
Can't log in as the RDS master user
Check its name with describe-db-instances, then reset it with modify-db-instance --master-user-password.
PostgreSQL password authentication failed: frequently asked questions
What does password authentication failed for user mean in PostgreSQL?
The server rejected the login. The cause can be a wrong password, a user that doesn't exist or an expired password.
Why does PostgreSQL say password authentication failed when the user doesn't exist?
On purpose, so the error can't be used to discover user names. The server log's DETAIL line says the role doesn't exist.
How do I see why PostgreSQL rejected a password?
Read the server log. The DETAIL line after the FATAL error gives the reason.
How do I view PostgreSQL logs on Amazon RDS?
In the RDS console's logs section for the database, with aws rds download-db-log-file-portion, or in CloudWatch Logs if you publish them.
Why does my password with a dollar sign fail?
In double quotes, the shell replaces $ and the following text. Use single quotes.
How do I put a password with @ in a PostgreSQL URL?
Percent-encode it: @ becomes %40, : becomes %3A and / becomes %2F.
How do I reset the RDS PostgreSQL master password?
Run aws rds modify-db-instance with --master-user-password and --apply-immediately, or change it in the console.
How do I find the RDS master username?
Run aws rds describe-db-instances with --query DBInstances[0].MasterUsername.
How do I check if a PostgreSQL password has expired?
Query pg_roles for rolvaliduntil. A date in the past means the password has expired.
How do I remove a password expiry in PostgreSQL?
Run ALTER ROLE name VALID UNTIL 'infinity'.
What is the difference between password authentication failed and no pg_hba.conf entry?
No pg_hba.conf entry means no rule allowed the connection at all; password authentication failed means a rule matched but the login failed.
What does role is not permitted to log in mean?
The role exists but has NOLOGIN. Grant it with ALTER ROLE name LOGIN.
Where should I store database passwords?
In a ~/.pgpass file or a secrets service such as AWS Secrets Manager, not in scripts or command lines.
Are PostgreSQL role names case-sensitive?
Only if they were created with double quotes. Unquoted names are folded to lower case.
Does the same error appear for wrong database names?
No. A database that doesn't exist gives a different error naming the database.
Why did my password stop working after a migration?
Check that the new server's role exists and that its password was set there; passwords don't travel with plain table dumps.
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: CloudOps Engineer – Associate (SOA-C03) • Security – Specialty (SCS-C03).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. What are common causes of "password authentication failed for user"?
A wrong password, connecting to the wrong database or host, or a user that does not exist on that server.
2. How do you reset the master password on RDS for PostgreSQL?
Modify the instance and set a new master password.
3. Which password hashing method is the default in current PostgreSQL?
SCRAM-SHA-256.
4. How can users authenticate without passwords on RDS?
IAM database authentication with tokens, or Kerberos with AWS Directory Service.
5. Where should applications read credentials from?
AWS Secrets Manager, with automatic rotation.
6. How do you log failed connection attempts?
Enable log_connections and publish PostgreSQL logs to CloudWatch Logs.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
Ethan changed one character in his deploy script, a double quote to a single quote, and the reporting service connected. Then he moved the password into Secrets Manager, so the script no longer contains it at all. Jake asked whether he should choose simpler passwords. "Keep them strong," Ethan said. "Just keep the shell's hands off them."
📌 If you keep one line from this page
PostgreSQL hides why a login failed from the client, so read the DETAIL line in the server log, and quote or percent-encode passwords with symbols.
DETAIL line · single quotes for $ · %40 %3A %2F in URLs · VALID UNTIL · modify-db-instance --master-user-password.
Revision note. Written October 13, 2026, for PostgreSQL 17 and Amazon RDS for PostgreSQL. "Don't judge a book by its cover," goes the saying; don't judge a login failure by its first line.