简体   繁体   English

在本地Linux安装上连接到Postgres数据库

[英]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. 我试图弄清楚如何使用PGConn通过我的ruby应用程序进行连接,以便连接到AWS EC2 Linux服务器上的postgres数据库。

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. 我在linux服务器上运行/ sbin / ifconfig -a来获取IP地址,但是它仍然无法连接。 I also edited the files per the instructions from the site http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html 我还按照http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html网站上的说明编辑了文件

IP of "ip-172-31-90-9" seems private IP address. IP“ ip-172-31-90-9”似乎是私有IP地址。

So what you need do: 因此,您需要执行以下操作:

  1. assign public IP or Elastic IP to that ec2 instance. 为该ec2实例分配公共IP或弹性IP。
  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 在其安全组中设置入站规则,然后将端口5432打开到0.0.0.0/0或您所用的任何IP范围
  3. test the port from your local 从本地测试端口

    telnet NEW_Public_IP 5432 远程登录NEW_Public_IP 5432

If can, then you should be fine to connect the database. 如果可以,那么连接数据库应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到本地PostgreSQL数据库 - Unable to connect to local PostgreSQL database 如何使用Auth0连接postgres数据库 - how to connect postgres database with Auth0 如何使用Sequel连接到postgres数据库? - How do I connect to a postgres database with Sequel? 无法将服务器上的 postgres 连接到我本地的 postico - can't connect postgres on the server to postico on my local 无法将我的开发环境连接到新导入的postgres数据库 - Can't connect my development environment to a newly imported postgres database Rails-Heroku在本地计算机上的现有开发Postgres数据库 - Rails - existing development Postgres database on local machine to Heroku Ruby Sinatra/Postgres - 无法使用 PG.connect 连接到 heroku 数据库? - Ruby Sinatra/Postgres - can't connect to heroku database with PG.connect? Ruby Sinatra-根据本地用户数据库对用户进行身份验证(Linux / Mac) - Ruby Sinatra - Authenticate user against local user database (linux / mac) 无法使用宝石“ pg”从我的Ruby Script连接到Postgres(pg)数据库(这不是rails,仅仅是纯红宝石) - cannot connect to Postgres (pg) database from my Ruby Script using gem “pg”(This is not rails, just pure ruby) 如何通过Ruby的pg gem连接到Postgres数据库(Rails外部) - How to connect to Postgres database through Ruby's pg gem (outside of Rails)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM