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
🌐
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.
Discussions

FATAL: database does not exist [docker compose]
There was an error while loading. Please reload this page · We have docker compose.yml More on github.com
🌐 github.com
11
January 26, 2018
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
postgresql - psql: fatal database does not exist error - Database Administrators Stack Exchange
I have a linux user account, postgresql role, and associated database, all called foo. from the linux user foo, I ran the command dropdb foo Now when I try to run psql from the linux user foo, I... More on dba.stackexchange.com
🌐 dba.stackexchange.com
Django with Postgresql on MacOS. FATAL error: "Database does not exist"
. ( lots of traceback removed ) ...onalError: connection to server at "localhost" (::1), port 5432 failed: FATAL: database "/Users/kak/Library/Application Support/Postgres/var-15/ytptest1" does not exist... More on reddit.com
🌐 r/djangolearning
8
3
April 4, 2023
🌐
Reddit
reddit.com › r/aws › "database does not exist" when connecting to postgres aws rds db
r/aws on Reddit: "database does not exist" when connecting to postgres AWS RDS db
December 17, 2018 -

I keep getting the error:

psycopg2.OperationalError: FATAL:  database "aa1ktrt0k1bv3s6" does not exist

whenever attempting to connect to the db. I think I have all the security groups correctly set up, but it thinks the database doesn't exist. I've triple checked the name and hostname (I disabled the security group and it timesout instead of giving this error).

I'm not sure what I'm doing wrong. I'm sure the db name is correct, but it doesn't connect.

    db_name = "aa1ktrt0k1bv3s6"
    user_name = ''
    db_pword = ''
    db_host = 'aa1ktrt0k1bv3s6.ctsxwr4cvxhd.us-east-1.rds.amazonaws.com'
    db_port = '5432'

    query = """
            
            """
    params = (self.project_id,)

    conn = psycopg2.connect(database=db_name, user=user_name, password=db_pword, host=db_host, port=db_port)
    cur = conn.cursor()

...etc....

Am I missing some security setting somewhere? I can't find anyone else on the internet with this issue.

Edit: In case it matters, the DB was set up by elastic beanstalk in a dev environment.

🌐
DigitalOcean
docs.digitalocean.com › how do i fix the "database does not exist" error when connecting to postgresql?
How do I fix the "Database Does Not Exist" error when connecting to PostgreSQL? | DigitalOcean Documentation
November 20, 2024 - A Database Does Not Exist error ... "defaultdb" does not exist · If you are getting this error, first verify that you are using the correct hostname to connect by following How to Connect to PostgreSQL Database Cluste...
🌐
GitHub
github.com › docker-library › postgres › issues › 403
FATAL: database does not exist [docker compose] · Issue #403 · docker-library/postgres
January 26, 2018 - psql: FATAL: database "test" does not exist · Everything works fine witout compose · docker run -it -e POSTGRES_USER=test -e POSTGRES_PASSWORD=qwerty -e POSTGRES_DATABSE=mydb postgres docker exec -it <CONTAINER_ID> /bin/bash psql -U test · results: root@cb18469bc86e:/# psql -U test psql (10.1) Type "help" for help.
Author   docker-library
🌐
Medium
medium.com › @benpickles › database-postgres-does-not-exist-665a57d56514
Database “postgres” does not exist | by Ben Pickles | Medium
May 20, 2016 - Better to keep the existing data just in case this process needs to be rolled back: ... $ brew uninstall postgresql $ brew install postgresql $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist ... 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.
🌐
Bobcares
bobcares.com › blog › postgresql-fatal-database-root-does-not-exist
PostgreSQL FATAL database root does not exist
August 14, 2025 - Getting the PostgreSQL FATAL database root does not exist error is common when the system defaults to using your OS username. This typically happens when no specific database is mentioned during connection.
Find elsewhere
🌐
Teratail
teratail.com › questions › cgzz8whsbg0tc6
PostgreSQLの環境構築ができないFATAL: database "t" does not exist
If not, wait a few seconds and retry. 82022-01-28 14:27:14.408 JST [94892] WARNING: could not create listen socket for "localhost" 92022-01-28 14:27:14.408 JST [94892] FATAL: could not create any TCP/IP sockets 102022-01-28 14:27:14.409 JST [94892] LOG: database system is shut down
🌐
REVSYS
revsys.com › writings › postgresql › errors.html
Common PostgreSQL Errors and Solutions
Managing Databases The official docs on creating and maintaining databases · Typically this error means PostgreSQL is not currently running on the system you are logged into.
🌐
Philip McClarence
philipmcclarence.com › how-do-i-find-the-cause-and-fix-the-error-fatal-database-dbname-does-not-exist-in-postgres
How do I find the cause and fix the error - FATAL: database "dbname" does not exist in Postgres
May 1, 2024 - The error FATAL: database "dbname" does not exist in PostgreSQL indicates that the client is attempting to connect to a database named “dbname” that does not exist on the PostgreSQL server instance. Here are the steps to diagnose and fix this issue: Diagnose Fix Once you’ve diagnosed ...
🌐
Sada Tech
tech.sadaalomma.com › sql › postgresql-fatal-database-does-not-exist
postgreSQL fatal database does not exist - SADA Tech
February 17, 2024 - The IT department discovers that an automated script designed to clean up test databases had erroneously removed the production database due to a misconfiguration. This led to the error being displayed to all users attempting to access the now non-existent database. When faced with the “fatal database does not exist” error, there are several steps you can take to diagnose and resolve the issue.
🌐
Reddit
reddit.com › r/djangolearning › django with postgresql on macos. fatal error: "database does not exist"
r/djangolearning on Reddit: Django with Postgresql on MacOS. FATAL error: "Database does not exist"
April 4, 2023 - Make sure db settings are correct; DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'ytptest1', 'USER': 'kak', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '', } }
🌐
Velog
velog.io › @wijoonwu › FATAL-role-postgres-does-not-exist-오류-해결-기록
FATAL: role "postgres" does not exist 오류 해결 기록
June 16, 2022 - 오류 메시지가 FATAL: role "postgres" does not exist에서 failed: FATAL: database "username" does not exist 으로 변했다.
🌐
Postgrespro
postgrespro.ru › list › id › 1155685965.28246.6.camel@dell.home.lan
Re: psql: FATAL: Database "postgres" does not exist in - Архив списков рассылки pgsql-admin : Компания Postgres Professional
If you run psql without a database name as an option, it tries to connect to a database with the same name as the $USER psql runs as. So if you run it as user "postgres", and a db with that name does not exist (yet), it will complain.