Brandon Benefield
Brandon Benefield

Reputation: 1672

AWS Postgres DB "does not exist" when connecting with PG

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);
  })

Upvotes: 44

Views: 23145

Answers (8)

PaulRwanda
PaulRwanda

Reputation: 185

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 the database name field and it worked. That means that my default username was "postgres" and the database name was also "postgres".

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

Upvotes: 4

pushpendra_pal
pushpendra_pal

Reputation: 61

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

Upvotes: 0

ATQSHL
ATQSHL

Reputation: 401

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.

Upvotes: 0

Erick Dominguez
Erick Dominguez

Reputation: 41

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

Upvotes: 3

Mayank Maheshwari
Mayank Maheshwari

Reputation: 303

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

Upvotes: 0

Sakshi
Sakshi

Reputation: 161

Try adding postgres as dbname. It worked for me!

Upvotes: 16

Mike.forest
Mike.forest

Reputation: 311

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.

Upvotes: 20

Aaron Billings
Aaron Billings

Reputation: 1631

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.

Upvotes: 154

Related Questions