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 OverflowIt 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.
From the terminal, just Run the command on your command prompt window. (Not inside psql).
createdb <user>
And then try to run postgres again.
FATAL: database does not exist [docker compose]
The Postgresql DB does not exist
postgresql - psql: fatal database does not exist error - Database Administrators Stack Exchange
Django with Postgresql on MacOS. FATAL error: "Database does not exist"
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.
In Database Navigator > Right click on PostgreSQL > Edit Connection
In Connection settings > general tab, enter your host (e.g. localhost), database (e.g. postgres) and leave User blank. Check Show all databases.
Right click on PostgreSQL and refresh. You should get a green checkmark in the PostgreSQL icon.
That's how I fixed mine, hopefully it'll work for you too.
Like Joseph, I had to leave the localhost but I had to clear all the fields, tick Show Databases:

Then refreshing on the databases I got prompted for the Username and Password (must have been an old version in cache):

This works, and you'll see there's potentially more than one schema:
