【问题标题】:R: postgres connection keeps timing out or breakingR:postgres 连接不断超时或中断
【发布时间】:2019-04-05 20:07:33
【问题描述】:

我在 R 中运行一个代码,它连接到 postgresql 数据库。连接是在循环之外定义的,但它会超时并不断中断。如果我将连接放在循环中,并在每次使用时将其终止。我们达到了连接的限制。

此外,当我们在循环中运行 r 代码时,答案/输出将存储在数据库中,它在前 15 分钟内工作,但随后连接中断,说无法连接。

我收到以下错误:

    RS-DBI driver: (could not connect ------ on dbname "abc": could not connect to server: Connection timed out (0x0000274C/10060)
    Is the server running on host "123.456.567.890" and accepting
    TCP/IP connections on port 5432?
)Error in diagnosticTestsPg(project_path, modelbank, modelproduct, modelwaterfall,  : 
  object 'conn' not found
In addition: There were 50 or more warnings (use warnings() to see the first 50)

这里,conn是到数据库的连接

有没有办法解决这个问题或在循环运行之前建立连接?

【问题讨论】:

    标签: r postgresql connection


    【解决方案1】:
    id <- tryCatch(withCallingHandlers(
        id <- f(), error=function(e) {
          write.to.log(sys.calls())
          }, 
        warning=function(w) {
          write.to.log(sys.calls())
          invokeRestart("muffleWarning")
          }
        )
      , error = function(e) { print("recovered from error") }
      )
    
    

    其中 f() 具有数据库连接详细信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-04
      • 2014-10-09
      • 2015-09-08
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      相关资源
      最近更新 更多