I created a postgresql RDS database instance and connected to an EC2 instance. I am able to ssh into the EC2 instance and access the database from there, but I am unable to connect to the database using psql
or using prisma to connect to the db.
The error I get in prisma-
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "greengainsdb.cfyqeu2ws1b6.us-west-2.rds.amazonaws.com"
Error: P1001: Can't reach database server at `greengainsdb.cfyqeu2ws1b6.us-west-2.rds.amazonaws.com`:`5432`
Please make sure your database server is running at `greengainsdb.cfyqeu2ws1b6.us-west-2.rds.amazonaws.com`:`5432`.
and the error I get using psql
psql --host=greengainsdb.cfyqeu2ws1b6.us-west-2.rds.amazonaws.com --port=5432 --username=postgres --password --dbname=postgres
Password:
psql: error: connection to server at "greengainsdb.cfyqeu2ws1b6.us-west-2.rds.amazonaws.com" (35.155.218.201), port 5432 failed: Operation timed out
Is the server running on that host and accepting TCP/IP connections?
And this the security group I have on the database.
I tried changing the security group to allow all connections on TCP on anywhere IP to test it out to see if I am able to connect to the database but I still can’t connect to the database. SSH into EC2 works perfectly fine. Am i missing something? I have a feeling that I am on a private subnet but I don’t know how to change the subnet settings to make it public.