Reputation: 1672
Using the node pg package, pg
, I'm trying to connect to a PostgreSQL DB created in AWS-RDS. I believe the DB was NOT given a name when creating an instance, note that an instance is different than a DB. When trying to connect using Client
or Pool
from pg
my syntax is
const client = new Client({
host : <<RDS ENDPOINT>>,
user : <<RDS DB USERNAME>>,
password : <<RDS DB PASSWORD>>,
port : <<RDS DB PORT>>
});
client.connect()
.then(data => {
console.log('connected');
})
.catch(err => {
console.log(err);
})
But every time I am returned with error: database <<linux user name>> does not exist
.
Now creating a different PostgreSQL instance and supplying a name for the DB I am able to add a database
prop to my Client
objects config and everything works and I am returned with a console log of connected
.
So my question is, how am I supposed to connect to the DB on AWS-RDS without supplying a database
prop in my Client
config?
Supplying a database
prop with an empty string will be overwritten with my linux username
Upvotes: 11
Views: 9927
Reputation: 1672
With the node-postgres
package you need to supply a database prop in your Client/Pool config object. If your PostgreSQL DB does not have a name, say if you created it using AWS-RDS then this DB NAME will default to postgres
. Simply supplying the database prop with postgres
should solve any problems you have with an un-named DB.
const client = new Client({
host : <<RDS ENDPOINT>>,
user : <<RDS DB USERNAME>>,
password : <<RDS DB PASSWORD>>,
port : <<RDS DB PORT>>,
database : 'postgres' // supplying a database name with `postgres`
});
Upvotes: 16