0

I'm trying to figure out how to connect via my ruby app using PGConn in order to connect to my postgres database on the aws ec2 linux server.

db_connection = PGconn.connect("ip-172-31-90.9.us-west-2.compute.internal", 5432, '', '', "testdb", "username", "password")

I keep getting an error

app.rb:21:in `initialize': could not translate host name "ip-172-31-90-9.us-west-2.compute.internal." to address: nodename nor servname provided, or not known (PG::ConnectionBad)

I ran /sbin/ifconfig -a on the linux server to get the IP address, but it still can't connect. I also edited the files per the instructions from the site http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html

1 Answer 1

2

IP of "ip-172-31-90-9" seems private IP address.

So what you need do:

  1. assign public IP or Elastic IP to that ec2 instance.
  2. set inbound rule in its security group and open the port 5432 to 0.0.0.0/0 or any IP ranges in your case
  3. test the port from your local

    telnet NEW_Public_IP 5432

If can, then you should be fine to connect the database.

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

2 Comments

I tried this, but it still says connection refused.
I also ended up having to also make the changes per this document to get it to work. cyberciti.biz/tips/… Thanks for your help!

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.