我正在R中运行一个代码,该代码连接到postgresql数据库。连接是在循环外部定义的,但是它超时并不断断开。如果我将连接放入循环中,并在每次使用时将其杀死。我们达到了连接限制。
另外,当我们在循环中运行r代码时,答案/输出将其存储在db中,它在开始的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是到数据库的连接
答案 0 :(得分:0)
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()具有数据库连接详细信息