4

I am brand new to RDS and have only used postgres through Rails and/or Heroku for the most part, so not that deep into database management. All I am trying to do is verify I can connect to the RDS instance I just created on AWS, but it is hanging, psql reporting this after hanging for about 30 seconds or a few minutes I guess:

$ psql postgresql://myuser:[email protected]:5432/my-db-name
psql: error: could not connect to server: Operation timed out
  Is the server running on host "myawshost.rds.amazonaws.com" (<the ip address>) and accepting
  TCP/IP connections on port 5432?

How do I connect to my AWS RDS instance from localhost?

  • I am sure I have the correct username and password.
  • I am sure the host is correct.
  • I am not sure if I should be including the port.
  • I am not sure if I am supposed to put a DB name, as under the "Configuration" tab in the RDS admin console for my database, it says DB instance ID: my-db-name, Engine version: 13.3, DB name: -, I am not sure if that - is my actual postgres db name or my-db-name is....

I tried this with the db name and it still hangs:

$ psql postgresql://myuser:[email protected]:5432/-
  • I edited the security group which is linked under the VPC security groups section of the Connectivity & security tab of https://console.aws.amazon.com/rds/home, so it allows all incoming connections. I also tried limiting to just my IP address as incoming connections.

Any help would be appreciated, thanks. Not sure why it would just be hanging. I have used a local version of postgres just fine, but connecting to postgres RDS is not working.

Underneath the Connectivity and Security > Security section I just noticed it says Public accessibility: No. Must I enable something else? There is also one VPC, one Subnet group, and several Subnets, which I don't know too much about, must I do something there?

Finally, "status" says Available with a green light, so things seem fine there.

4
  • You are connecting from where? Ec2 instance or from outside of AWS? Commented Aug 11, 2021 at 3:18
  • From outside of AWS, like described here with DATABASE_URL. Commented Aug 11, 2021 at 3:23
  • Public accessibility must be Yes. ALso what are your security groups? Commented Aug 11, 2021 at 3:24
  • Security groups are allow all inbound traffic from any IP, what should they be? (I am going to connect to this from a Next.js app hosted on Vercel). Looks like it's answered here. Commented Aug 11, 2021 at 3:30

1 Answer 1

2

I found a useful link in AWS knowledge center, I hope this will help you. Btw if your RDS is deployed in a public subnet, yes you need to enable if you want to access RDS over the internet.

My DB instance is in a public subnet, and I can't connect to it over the internet from my local computer This issue can occur when the Publicly Accessible property of the DB instance is set to No. To check whether a DB instance is publicly accessible, you can use the Amazon RDS Console or the AWS CLI.

To change the Publicly Accessible property of the Amazon RDS instance to Yes:

  1. Verify that your VPC has an internet gateway attached to it. Make sure that the inbound rules for the security group allow connections.

  2. Open the Amazon RDS console.

  3. Choose Databases from the navigation pane, and then select the DB instance.

  4. Choose Modify.

  5. Under Connectivity, extend the Additional configuration section, and then choose Publicly accessible.

  6. Choose Continue.

  7. Choose Modify DB Instance.

Note: You don't need to choose Apply Immediately. For more information about how Apply Immediately can affect downtime, see Using the Apply Immediately parameter.

https://aws.amazon.com/premiumsupport/knowledge-center/rds-connectivity-instance-subnet-vpc/

Sign up to request clarification or add additional context in comments.

4 Comments

Ok great, this looks like it. Thank you. It seems to take a few minutes to propagate. Is this how you should be setting up a database when connecting from a web app like a Node.js or Next.js app? (Connecting to publicly accessible RDS instance). Or is there better practice?
Now I am getting psql: error: FATAL: database "-" does not exist, what is my database name and how do I change it? Looks like it is called postgres... Nowhere was that specified... Can/should I change that? Can I have multiple "dbs" per RDS instance?
I'm not recommending accessing the DB over the internet. You must deploy your RDS in a private subnet. If your application ( assume it runs on ec2 ) can connect to the DB via service linked role. docs.aws.amazon.com/AmazonRDS/latest/UserGuide/… If you still want to run some queries from the database, think of a Bastian host and connect to the db via it. aws.amazon.com/quickstart/architecture/linux-bastion
yes you can have multiple dbs with RDS 40 for MySQL, MariaDB, or PostgreSQL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.