Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
  })
like image 256
Brandon Benefield Avatar asked Jun 24 '18 23:06

Brandon Benefield


People also ask

How do I connect to a postgres database from AWS?

Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/ . Open the RDS console and then choose Databases to display a list of your DB instances. Choose the PostgreSQL DB instance name to display its details. On the Connectivity & security tab, copy the endpoint.

How do I connect pgAdmin to Aurora PostgreSQL database?

Open the client and authenticate with pgAdmin. Open the context (right-click) menu for Servers, and then choose Create, Server. Enter information in the Create - Server dialog box. On the Connection tab, add the Aurora PostgreSQL cluster address for Host and the PostgreSQL port number (by default, 5432) for Port.

How does pgAdmin connect to database?

To open the Server Group dialog, right-click on the Servers node of the tree control, and select Server Group from the Create menu. Use the fields on the Server dialog to define the connection properties for each new server that you wish to manage with pgAdmin.


2 Answers

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.

like image 167
Aaron Billings Avatar answered Sep 21 '22 15:09

Aaron Billings


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.

like image 36
Mike.forest Avatar answered Sep 19 '22 15:09

Mike.forest