简体   繁体   English

连接:连接超时

[英]connect: connection timed out

I have successfully connected to a Postgres database using the go sql package: 我已经使用go sql包成功连接到Postgres数据库:

...
db, err := sql.Open("postgres", connStr)

I then use the returned database to execute a (long running) query: 然后,我使用返回的数据库执行(长期运行)查询:

rows, err := db.Query(...)

And am getting the error: 并得到错误:

dial tcp xx.xxx.xxx.xx:5432: connect: connection timed out

I have a couple of questions regarding this: 我对此有两个问题:

  1. why is the connection timing out? 为什么连接超时?
  2. is there anything I can do to prevent it timing out? 我有什么办法可以防止它超时?

sql.Open() may just validate its arguments without creating a connection to the database. sql.Open()可以仅验证其参数, 而无需创建与数据库的连接 To verify that the data source name is valid, call Ping . 要验证数据源名称是否有效, 请调用Ping

The sql.Open() function has only created an object, your pool is currently empty. sql.Open()函数仅创建了一个对象,您的池当前为空。 In simple words connection with the database hasn't been established yet. 简而言之,尚未建立与数据库的连接。

You need to call db.Ping() to make sure your pool has a working connection. 您需要调用db.Ping()来确保您的池具有有效的连接。

暂无
暂无

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

相关问题 PostgreSQL:无法连接到服务器:连接超时 - PostgreSQL: could not connect to server: Connection timed out heroku postgresql无法连接到服务器:连接超时 - heroku postgresql could not connect to server: Connection timed out getsockopt:连接超时 - getsockopt: connection timed out Appfog + Rails 3 + Postgresql + IronWorker =>无法连接到服务器:连接超时(PG :: Error) - Appfog + Rails 3 + Postgresql + IronWorker => could not connect to server: Connection timed out (PG::Error) 无法通过 SSH 隧道从本地 docker 容器连接到远程 PostgreSQL 数据库; 连接超时 - Could not connect to a remote PostgreSQL database from a local docker container through an SSH tunnel; connection timed out 与 postgres 的配置数据库连接:无法连接到数据库:5000 毫秒后超时 - Metabase DB connection to postgres :Failed to connect to database: Timed out after 5000 milliseconds kubernetes 上的 Postgres+django:django.db.utils.OperationalError:无法连接到服务器:连接超时 - Postgres+django on kubernetes: django.db.utils.OperationalError: could not connect to server: Connection timed out 获取“连接超时”和“操作系统错误”的错误 - Getting Error of “Connection Timed Out” and “OS Error” 连接被拒绝:Postgres 中的操作超时 - Connection refused: Operation Timed out in Postgres * 10上游超时(110:连接超时),同时使用uwsgi从上游读取响应头 - *10 upstream timed out (110: Connection timed out) while reading response header from upstream with uwsgi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM