It appears that your package manager failed to create the database named $user for you. The reason that

psql -d template1

works for you is that template1 is a database created by postgres itself, and is present on all installations. You are apparently able to log in to template1, so you must have some rights assigned to you by the database. Try this at a shell prompt:

createdb

and then see if you can log in again with

psql -h localhost

This will simply create a database for your login user, which I think is what you are looking for. If createdb fails, then you don't have enough rights to make your own database, and you will have to figure out how to fix the homebrew package.

Answer from Kirk Roybal on Stack Overflow
🌐
Medium
medium.com › @benpickles › database-postgres-does-not-exist-665a57d56514
Database “postgres” does not exist | by Ben Pickles | Medium
May 20, 2016 - psql: FATAL: database "postgres" does not exist DETAIL: The database subdirectory "base/12641" is missing.
Discussions

Database current username does not exist issue
When logging into a Postgres server with the psql client if you do not specify a database user with the -U option then it will default to using the current OS username for the database username it attempts to log\ in with. If there is not a database user with that name then it will fail. If you do not specify a database name to log into then it will default to looking for a database with the same name as the database user it is attempting to log in with and if there is not a database with that name then the login will fail. When a new cluster is created with initdb it always starts with three databases: postgres, template1, and template0. Here's info on the template databases. You can just ignore them. If you do not specify a superuser with the -U option when running initdb then it will use the current OS user name. By convention, most package managers and other install scripts will create an OS user named postgres and specify that the superuser database user account also be named postgres when initializing a new cluster with initdb. So: Why doesnt psql let me login into psql without specifying a specific database by throwing the error message psql: error: could not connect to server: FATAL: database "" does not exist? Instead, the commands psql -d my_application_development and sudo -u postgres psql work even though the latter does not say which database Because in the former case since you are not specifying the database name it is looking for a database with the same name as the database username it is attempting to log in with and the latter case works because there is a database named postgres to match the postgres user your are logging in with. More on reddit.com
🌐 r/PostgreSQL
7
1
January 31, 2021
database "postgres" does not exist
Self Checks This is only for bug report, if you would like to ask a question, please head to Discussions. I have searched for existing issues search for existing issues, including closed ones. I co... More on github.com
🌐 github.com
2
September 9, 2024
The Postgresql DB does not exist
I have tried to reinstall this because I have problems with it every time I try to run gvm-start this pops up “See “systemctl status gvmd.service” and “journalctl -xeu gvmd.service” for details.” when I tried to reinstall Greenbone, this pops up WARNING: database “postgres” ... More on forum.greenbone.net
🌐 forum.greenbone.net
1
0
July 19, 2023
FATAL: database "postgres" does not exist
Yes - do NOT ever delete the postgres database. You can create new copy of it but you should be backing up all databases on the system. Step 1 - reinstall or fix PostgreSQL Step 2 - install & configure pgbackrest for full & differential backups (supports compression & S3) More on reddit.com
🌐 r/SQL
3
10
April 8, 2019
🌐
Oracle DBA Training
learnomate.org › home › postgresql › fatal: database “dbname” does not exist
5 Simple Fixes for PostgreSQL Database Does Not Exist ...
September 19, 2025 - Getting the error “FATAL: PostgreSQL database does not exist” in PostgreSQL? Learn 5 simple fixes to create missing databases, assign owners, and resolve connection issues quickly.
🌐
Reddit
reddit.com › r/postgresql › database current username does not exist issue
r/PostgreSQL on Reddit: Database current username does not exist issue
January 31, 2021 -

I have existing multiple *_development and *_test databases on postgres 12. Postgres by default creates a postgres user upon installation. I am always logged in as the current linux user on my system.

Why doesnt psql let me login into psql without specifying a specific database by throwing the error message psql: error: could not connect to server: FATAL: database "<current username>" does not exist?

Instead, the commands psql -d my_application_development and sudo -u postgres psql work even though the latter does not say which database

PS what is template0 and template1? was it a mistake in name

Top answer
1 of 2
2
When logging into a Postgres server with the psql client if you do not specify a database user with the -U option then it will default to using the current OS username for the database username it attempts to log\ in with. If there is not a database user with that name then it will fail. If you do not specify a database name to log into then it will default to looking for a database with the same name as the database user it is attempting to log in with and if there is not a database with that name then the login will fail. When a new cluster is created with initdb it always starts with three databases: postgres, template1, and template0. Here's info on the template databases. You can just ignore them. If you do not specify a superuser with the -U option when running initdb then it will use the current OS user name. By convention, most package managers and other install scripts will create an OS user named postgres and specify that the superuser database user account also be named postgres when initializing a new cluster with initdb. So: Why doesnt psql let me login into psql without specifying a specific database by throwing the error message psql: error: could not connect to server: FATAL: database "" does not exist? Instead, the commands psql -d my_application_development and sudo -u postgres psql work even though the latter does not say which database Because in the former case since you are not specifying the database name it is looking for a database with the same name as the database username it is attempting to log in with and the latter case works because there is a database named postgres to match the postgres user your are logging in with.
2 of 2
1
psql always tries to connect with the current logged in user's name. If you use sudo -u postgres, then it will connect with the postgres user. By default it tries to connect to the database with the same name as the user. The relevant page from the documentation about template0 and template1, https://www.postgresql.org/docs/current/manage-ag-templatedbs.html In short, template1 is used as a template when creating new databases, you can specify your own template db.
🌐
GitHub
github.com › langgenius › dify › issues › 8147
database "postgres" does not exist · Issue #8147 · langgenius/dify
September 9, 2024 - docker-db-1 | 2024-09-09 08:39:55.421 UTC [47] FATAL: database "postgres" does not exist docker-db-1 | 2024-09-09 08:40:07.395 UTC [126] FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption docker-worker-1 | ERROR [root] Database migration failed, error: (psycopg2.OperationalError) connection to server at "db" (172.18.0.5), port 5432 failed: FATAL: no pg_hba.conf entry for host "172.18.0.6", user "postgres", database "dify", no encryption ·
Author   langgenius
🌐
Sentry
sentry.io › sentry answers › postgres › psql fatal database "root" does not exist
psql FATAL Database "root" Does Not Exist | Sentry
July 12, 2022 - When getting started with Postgres, you might come across this error: psql: FATAL: database "root" does not exist or psql: FATAL: database "<your user name>" does not exist. This can happen particularly when running psql with no arguments from your command line.
Find elsewhere
🌐
Reddit
reddit.com › r/sql › fatal: database "postgres" does not exist
r/SQL on Reddit: FATAL: database "postgres" does not exist
April 8, 2019 -

Hi guys, I've been googling around on how to solve the problem with resolving my issue into getting back into postgresql 11...

I dropped the postgres database in my software then it led to me not able to reconnect to the server.

I've tried doing some code on the command line with adding a database and entering password but not working or recovering the access with psql -u postgres.

None haven't worked. IDK where to go because I'ved seen like several sources and no luck. I wanna resume coding on postgresql.

Thanks...

🌐
SitNGo Wizard
forums.holdemmanager.com › showthread.php
ERROR FATAL: 3D000:database "postgres" does not exist
If you cannot access the database ... reimport them as restoring a corrupt database will just restore all the problems you had. 1) Uninstall PostgreSQL from the Windows Control Panel....
🌐
OneUptime
oneuptime.com › home › blog › how to fix 'role does not exist' errors in postgresql
How to Fix 'role does not exist' Errors in PostgreSQL
January 25, 2026 - # Python application error: # psycopg2.OperationalError: FATAL: role "app_user" does not exist # Fix: Create the application role # sudo -u postgres psql · CREATE ROLE app_user WITH LOGIN PASSWORD 'app_password' NOSUPERUSER NOCREATEDB NOCREATEROLE; GRANT CONNECT ON DATABASE mydb TO app_user; GRANT USAGE ON SCHEMA public TO app_user; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO app_user;
🌐
Benpickles
benpickles.com › articles › 56-database-postgres-does-not-exist
Database “postgres” does not exist
April 14, 2016 - If your luck is as good as mine then you should have a fully working PostgreSQL install with your previous database(s). I think this problem was caused by me not reading the instructions and blindly upgrading PostgreSQL with brew upgrade postgresql to go from 9.4 to 9.5. Or was it 9.3 to 9.4… · Here’s how to properly upgrade PostgreSQL data using pg_upgrade - though I’m sure I did this!
🌐
IONOS
ionos.com › digital guide › server › configuration › solve the postgresql error "psql: fatal: database "root" does not exist"
Solve the PostgreSQL Error "psql: FATAL: database "root" does not exist" - IONOS
December 11, 2020 - When you log into Post­greSQL as any user other than the postgres user, it will attempt to log you into a database of the same name as your user account. This means that if you try to use the psql command as root, it will try to log you into the database root. If you try to log in while signed on as jdoe it will look for the database jdoe, and so forth. Unable to find this database, Post­greSQL gives the error message that "database [your username] does not exist."
Top answer
1 of 2
2

A FATAL error in PostgreSQL is an error that terminates a database connection.

That is your clue: such an error message is logged when somebody tries to connect to a non-existing database. After the successful authentication, PostgreSQL cannot connect the session to the database, raises the error you observe and terminates the connection.

Usually, that is a harmless error that you can ignore. If it happens too often, search for automated tools that are trying to connect to that non-existing database.

2 of 2
2

Something is trying to connect to your cluster, expecting ABCD to be available.

My bet is someone saved a misconfigured connection profile in a database client like DBeaver, DataGrip, pgAdmin and it's just checking it from time to time, or that somewhere in your codebase someone left an example line without modifying the dbname that ends up in a connection string. There could also be a test case or rarely used code path doing something else and simply ignoring the failed connection attempt.

demo at db<>fiddle

select pg_rotate_logfile();
create extension dblink;
select dblink_connect('','dbname=ABCD');
ERROR:  could not establish connection
DETAIL:  connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: 
FATAL:  database "ABCD" does not exist
create function readlog()returns text return
 pg_read_file('log/'||(array(select (pg_ls_logdir()).name order by 1 desc))[1]);
select readlog();
readlog
2026-02-28 10:00:08.099 GMT [791] FATAL: database "ABCD" does not exist
2026-02-28 10:00:08.101 GMT [790] ERROR: could not establish connection
2026-02-28 10:00:08.101 GMT [790] DETAIL: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "ABCD" does not exist
2026-02-28 10:00:08.101 GMT [790] STATEMENT: select dblink_connect('','dbname=ABCD');

Ask other users of the database about dead connection profiles and grep your repo for this ABCD.

🌐
GitHub
github.com › PostgresApp › PostgresApp › issues › 139
FATAL: database "dave" does not exist · Issue #139 · PostgresApp/PostgresApp
October 19, 2013 - Last login: Sat Oct 19 07:59:28 on ttys009 /Applications/Postgres.app/Contents/MacOS/bin/psql ; exit; Daves-MacBook-Pro:~ dave$ /Applications/Postgres.app/Contents/MacOS/bin/psql ; exit; psql: FATAL: database "dave" does not exist logout
Author   PostgresApp
🌐
GitHub
github.com › docker-library › postgres › discussions › 1155
Report errors "FATAL: role "XXX" does not exist" when POSTGRES_USER is customized. · docker-library/postgres · Discussion #1155
you are right, thank you!, i got the similar problem, and i used"ps aux | grep postgres"to check, and i found another pgsql existed, when i removed it, theproblem was solved.
Author   docker-library
🌐
Reddit
reddit.com › r/docker › postgresql in docker: database "admin" does not exist error
r/docker on Reddit: PostgreSQL in docker: database "admin" does not exist error
January 14, 2024 -

Hi,
I'm running the alpine PostgreSQL image in docker using the following docker-compose file below. After building and starting, the container gives the following fatal error message: "FATAL: database "admin" does not exist". After some googling it looks like postgresql needs a database to exist same to the user name that I declared in the docker-compose. Anyone an idea how to solve the error?

version: '3.8'

x-systeminfo: &systeminfo
  # Database
  POSTGRES_ADDRESS: database
  POSTGRES_DB: dev
  POSTGRES_USER: admin
  POSTGRES_PASSWORD: ****************
  POSTGRES_PORT: 5432

services:
  database:
build: ./Database
restart: always
ports:
   - 5432:5432
environment: *systeminfo
volumes:
   - postgresqldata:/var/lib/postgresql/data
healthcheck:
  test: pg_isready -U $$POSTGRES_USER
  interval: 10s
  timeout: 5s
  retries: 20

volumes:
  postgresqldata:

The docker file inside ./Database looks like this:

FROM postgres:alpine
COPY . /docker-entrypoint-initdb.d/