BugMedic

PostgreSQL “role does not exist”: create the role or pass -U

psql defaults to your OS username as the role. Connect with -U or create the missing role.

By BugMedic editorial teamLast source review: 2026-09-28Windows, macOS, Linux

psql uses your OS username as the role by default. Either connect as an existing role with psql -U postgres, or create the missing role: on Debian/Ubuntu run sudo -u postgres createuser --superuser $USER; on Homebrew run createuser -s postgres from your own account (your macOS user is the superuser there).

Try these fixes in order

01

List existing roles

Confirm which roles actually exist. Connect as a known superuser (or the postgres OS user on Debian/Ubuntu) and list roles.

sudo -u postgres psql -c "\du"
02

Create a role for your user (Debian/Ubuntu)

On Debian/Ubuntu, the postgres OS user is the bootstrap superuser. Create a superuser role matching your login name.

sudo -u postgres createuser --superuser $USER
03

Create the role (Homebrew)

On Homebrew, the installing macOS user is already the superuser. Create the postgres role (or any role you need) directly.

createuser -s postgres
04

Or connect with -U explicitly

Alternatively, keep the role as-is and always specify it explicitly with -U, which also avoids the database-name default problem.

psql -U postgres

Interpret what you see

You ran bare psql on macOS Homebrew

What it suggests: Bare psql uses your OS login name as both the database name and the role. On a Mac whose user is not postgres, the role postgres was never created.

Next check: Run psql -U postgres or check existing roles with \du from a working connection.

You are on Debian or Ubuntu

What it suggests: Debian and Ubuntu create a postgres OS user that owns the postgres role. Your own login has no role until you create one.

Next check: Connect via sudo -u postgres psql and create a role for your user.

Fresh install, first connection attempt

What it suggests: A fresh initdb creates only the bootstrap superuser named after the OS user that ran it. Any other name must be created explicitly.

Next check: Run CREATE ROLE or createuser from an existing superuser connection.

Why this happens

  • psql defaults the role name to your operating-system username, which has no matching database role.
  • The postgres superuser role was never created during installation or initialization.

Still not working?

Do not run initdb again on an existing data directory to fix this; you will create a second cluster or damage the current one. Create the missing role against the running server instead.

Official sources

These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.

Related PostgreSQL guides