user2974739
user2974739

Reputation: 639

Connect to postgres database on local linux install

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

Upvotes: 0

Views: 323

Answers (1)

BMW
BMW

Reputation: 45243

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.

Upvotes: 2

Related Questions