AWS Postgres DB "does not exist" when connecting with PG
Asked Answered
F

8

42

I can't seem to connect to my DB instance in AWS. I'm using the pg package and following the examples from the website is not working.

A search for "aws postgres database does not exist" really isn't returning anything helpful. Going through the open/closed issues on the PG github isnt helpful either.

Running $nc <RDS endpoint> <port number> returns a success message so it's definitely there. Every value placed in the Client config is copy/pasted from my DB instance.

I'm starting to wonder if the databases have a different name than what it shows in the "Instances" section of RDS on AWS?

const client = new Client({
  host     : '<<RDS ENDPOINT>>',
  database : '<<RDS NAME>>', // maybe this isnt the real name?
  user     : '<<username>>',
  password : '<<password>>',
  port     : <<port>>
});
client.connect()
  .then(data => {
    console.log('connected');
  })
  .catch(err => {
    console.log(err);
  })
Fearsome answered 24/6, 2018 at 23:3 Comment(4)
It looks like it's different for PostgreSQL than what I'm used to with MySQL/Aurora: docs.aws.amazon.com/AmazonRDS/latest/UserGuide/… It sounds like DB name is optional for postgres. Try removing the database parameter from your connection settings.Annalee
This might be true going off the link you provided. But when creating a new instance (I do not have direct control over the original DB Instance) with a different AWS account it states that if you do not supply a name the DB will not be created so who actually knows. It seems though that the person that created the DB instance I am trying to access DID NOT provide a dbname. When creating the alternative instance I supplied a dbname and it has a DB NAME attribute in the details like you said. Lastly, not supplying a database in the client config just uses my linux username, weird stuff.Fearsome
@MarkB is right, Was able to connect without specifying any database name as well.Hannover
also see https://mcmap.net/q/391173/-how-can-i-change-the-quot-database-name-quot-in-aws-rds-for-postgresqlSeedtime
K
144

I ran into this issue as well. It looks like the DB Instance Name and the actual DB name are two different things and even when you add a name when you create your DB, it defaults to 'postgres'. When I put in the name of my DB it gave me the same error. However, when I just put in 'postgres' it worked fine. Try that and see if it works for you.

Kekkonen answered 19/1, 2020 at 2:19 Comment(4)
after searching for hours, this helped me. everone(me also) confused with dbname. so try postgres in database name, because postgres database is available in default. It worked for me.Placenta
As @aaron and @mike stated, there is a difference between DB Instance Name and Initial Database Name. DB Instance Name is the initial part of the AWS RDS DB Endpoint and you can change it. But, Initial Database Name is set when you create the db and I have not found a way to change it not have I found a way to find out what the name is after creating the db. I was able to connect to my db when I used the Initial Database Name as well as postgres. Here's a related link: #43099655Romie
I want to scream. AHHHHHHHHHHHHHHHHHHHHH!!! Thank you!Sevastopol
Although I created an initial database, I was not able to connect to my AWS Postgres database. This helped.Windsor
B
19

The initial configuration of RDS instances is quite messy, since the parameter "database name" is only the name of the instance, not the proper name of the database. If you want AWS to create a database at the moment you create the db instance, you have to select "Additional configuration" and explicitly add a parameter called "Initial database name". Check the screenshot I attach here.

Burley answered 6/4, 2020 at 21:24 Comment(0)
M
14

Try adding postgres as dbname. It worked for me!

Mlle answered 27/6, 2021 at 2:55 Comment(2)
This worked for me to. very strange for RDS... Does anyone know why this is the case?Jut
This worked for me after I spun up a new RDS instance from a snapshot. Saved a lot of time! Thanks.Rosemaryrosemond
S
4

I ran into the same issue after creating a DB instance on AWS RDS. I wanted to test the connection of my database using PostBird, and I used my actual DB instance name but it could not work.

But I used "postgres in field of DB_name and it worked. That means that my default username was posgres and db_name was also "posgres.

I hope it will help you too.This image can help you see what I mean

Simoniac answered 5/8, 2022 at 17:13 Comment(1)
Thank you! It is weird but it worked for me too. I wonder why doesn't aws just use the name I inserted!!Wenda
B
2

After connecting with postgres as db name, you can type \l to list all database on that PSQL cluster, that will return a bunch of default dbs and also the one you created (the name) so you can connect to it

Berlyn answered 27/9, 2021 at 20:27 Comment(2)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewBoz
Oh! The intention of my comment was to enhance the answer more than be an answer by itself, sorry if that wasn't clear...Berlyn
K
0

Try this if the above answer does not work. Remove the:5439/lab ending so that the Host value ends with: .com

Kmeson answered 19/7, 2021 at 7:45 Comment(0)
F
0

Most of the solutions provided here are not recommended. The error clearly states that DB name is not correct. db instance name and DB name are different thing.

follow this to solve the issue:

  1. open the db instance
  2. click configuration tab
  3. copy the DB name and use it.
Folderol answered 12/9, 2023 at 15:1 Comment(0)
A
0

In aws, there is a name for the database on your DB instance. If you don't provide a name, Amazon RDS doesn't create a database on the DB instance (except for Oracle and PostgreSQL).

Inside the db instance

  • go to configuration
  • copy the db name

If the db name is not given, then you can need to use "postgres" as db name in your db_url

Amalekite answered 6/3 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.