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
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/
Report errors "FATAL: role "XXX" does not exist" when POSTGRES_USER is customized.
postgresql - psql: fatal database does not exist error - Database Administrators Stack Exchange
cloudsql postgres user cannot connect
FATAL: database "..." does not exist
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.
From the terminal, just Run the command on your command prompt window. (Not inside psql).
createdb <user>
And then try to run postgres again.
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.
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...