Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

PostgreSQL FATAL: role "…" does not exist: find which name the client sent and which roles the server has

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When PostgreSQL answers FATAL: role "joe" does not exist, the server was reached and is running, but the cluster has no database role with the name the client sent. The name usually comes from a default, because psql and createuser assume the name of the current operating system user. Compare the name in the message with the list of roles first. Then either connect as a role that exists or create the missing one.

What the error means

PostgreSQL's tutorial page shows the message as createdb: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: role "joe" does not exist. It explains the cause in these words: "This will happen if the administrator has not created a PostgreSQL user account for you." It adds that "PostgreSQL user accounts are distinct from operating system user accounts."

Three rules from the documentation decide how this error behaves.

  • Roles are separate from operating system users. The Database Roles page says they are "conceptually completely separate from operating system users".
  • Roles are cluster-wide. The same page says they "are global across a database cluster installation (and not per individual database)". A role created in one database exists in all databases of that cluster, and a role in a different cluster or on a different server does not exist here.
  • The client chooses the name. libpq documents the user parameter as "PostgreSQL user name to connect as. Defaults to be the same as the operating system name of the user running the application." The psql page says "The default database user name is your operating-system user name."

The Authentication Problems page prints the same failure as FATAL: user "andym" does not exist, while the tutorial page prints role "joe" does not exist. The Authentication Problems page says "The indicated database user name was not found." It also says "The server log might contain more information about an authentication failure than is reported to the client."

Likely causes

Cause What you see How to confirm
The client sent a default name, the operating system user The role named in the message matches the login name of the shell or service account that ran psql or the application whoami prints the same name as the message
The role was never created, or the name has a typo The name in the message is not in the role list \du or pg_roles on the server has no such name
Upper-case name created without double quotes The role list shows the name in lower case \du shows appuser where the client sends AppUser
Wrong server, port or cluster The role exists on another server or cluster The same \du query on the intended server lists the role
The role was dropped A login that worked before now fails The name is missing from \du; ask who ran DROP ROLE
The application passes its own user setting The message names the application's setting, not a person's login PGUSER or the user field of the application's connection settings holds the name

Prove the cause before changing anything

Every check below only reads.

1. See which name the client would send by default.

whoami

The whoami manual says it prints "the user name associated with the current effective user ID". If that name is the one in the error message, the client sent a default and no one chose it.

2. List the roles on the server you meant to reach. Run this as the operating system user that owns the cluster, which the tutorial says is usually postgres. The sudo manual documents -u user as running a command as another user.

sudo -u postgres psql -c '\du'

The psql manual documents -c command and says \du lists database roles. A good result shows the role the application needs. A bad result lacks the name in the error message.

3. List the roles with their login capability.

sudo -u postgres psql -c "SELECT rolname, rolcanlogin FROM pg_roles ORDER BY rolname"

The Database Roles page gives SELECT rolname FROM pg_roles WHERE rolcanlogin; to see roles able to log in. Compare the spelling and letter case character by character with the name in the message.

4. Confirm which server and port you are asking. Where Debian's postgresql-common package is installed, pg_lsclusters lists the status and configuration details of all clusters, so a second cluster on another port shows up here.

pg_lsclusters

If the list shows more than one cluster, repeat step 2 with -p and the port of the cluster the application uses. The psql manual describes -p as the TCP port or Unix-domain socket file extension, defaulting to PGPORT or the compiled-in port, usually 5432.

5. Read what the application sends. Check the service's environment for PGUSER, which libpq documents as behaving "the same as the user connection parameter", and the user field of its connection string.

6. Read the server log. The Authentication Problems page says the server log can hold more than the client sees. Where that log is differs by distribution; use your distribution's documentation.

Fix

The role exists and the client sent the wrong name

No server change is needed. Connect with the name the server has. The psql manual documents -U username as "Connect to the database as the user username instead of the default."

psql -h db01.example.com -U appuser -d appdb

An application's own user setting, or its PGUSER variable, must hold the same name. Editing an application's settings is a change to that application and follows its own change process.

The role does not exist and should

Roles are made by a superuser or a role with CREATEROLE. The tutorial says to become the operating system user the server was installed under to create the first account.

First save the current list of roles:

sudo -u postgres psql -c '\du' > /root/roles-before.2026-12-01.txt

Risk: the next command creates a new database role that can log in, in the whole cluster, with a password you type at the prompt. The role has no privileges on existing tables beyond those every role has, so the application may still be refused until privileges are granted, which depends on what the application needs.

Create the role. The createuser manual says it is a wrapper around CREATE ROLE, that the new user "will be allowed to log in" by default, and that -P (--pwprompt) prompts for the new user's password:

sudo -u postgres createuser --pwprompt appuser

To undo it: first print the list you saved, and confirm that appuser is not in it:

cat /root/roles-before.2026-12-01.txt

If appuser appears in that list, the role existed before your change; stop and do not drop it. If it is absent, show the role you are about to remove:

sudo -u postgres psql -c '\du appuser'

Then remove it. The dropuser manual says -i (--interactive) will "Prompt for confirmation before actually removing the user". The DROP ROLE page says a role "cannot be removed if it is still referenced in any database of the cluster", so grants or owned objects must be handled first.

sudo -u postgres dropuser --interactive appuser

The name differs only in letter case

The lexical rules say "unquoted names are always folded to lower case" and that quoting "makes it case-sensitive". A role created with CREATE ROLE AppUser is stored as appuser; one created with CREATE ROLE "AppUser" keeps the capitals. Use exactly the name \du prints. Do not create a second role that differs only by case.

The client is talking to the wrong cluster

The right host and port are the ones in the application's connection settings, or -h and -p in psql. Nothing on the server changes.

Example (illustrative): a script on web01 (198.51.100.10) runs as the operating system user deploy and calls psql -h db01.example.com -d appdb. It fails with FATAL: role "deploy" does not exist. whoami on web01 prints deploy, so psql sent its default. On db01, sudo -u postgres psql -c '\du' lists postgres and appuser only. The role the script should use already exists, so no role is created. The engineer changes the call to psql -h db01.example.com -U appuser -d appdb, and the connection proceeds to authentication.

Confirm the fix

  1. The command that failed now connects, or fails with a different message. A new message such as password authentication failed means the role is now found and the next problem is authentication.
  2. sudo -u postgres psql -c '\du' lists the role that the application sends.
  3. \conninfo inside a working psql session prints information about the current connection, so you can see the user, host and port in use.

What to watch afterwards

  • Keep a list of the roles each application uses, and compare it with \du after a server rebuild, a restore or a move to a new cluster.
  • After any change of the application's service account on the operating system, check whether it relied on the default name.
  • When a role is dropped on purpose, search application settings for its name first.

Risks and limits

  • These commands have not been run or lab-tested.
  • createuser --pwprompt and dropuser --interactive ask questions at the terminal; do not run them from an unattended script.
  • The PostgreSQL pages used here are for version 19; pages for older releases were not consulted.
  • With some authentication methods the client may be told only that authentication failed, and the real reason, including a missing role, is in the server log. The topic "PostgreSQL "password authentication failed for user": scram-sha-256, md5 and the stored password" covers that case.
  • Granting the new role rights on databases and tables, and the pg_hba.conf entry for it, are separate steps.

Sources