断开dplyr中的src_tbls连接 [英] Disconnecting src_tbls connection in dplyr
本文介绍了断开dplyr中的src_tbls连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以强制断开 dplyr
中的 src_tbls
对象,类似于 RPostgreSQL :: dbDisconnect
?
Is there a way to force disconnection of a src_tbls
object in dplyr
similar to RPostgreSQL::dbDisconnect
?
例如参见
> src_temp <- src_postgres(dbname = "temp", host = "127.0.0.1", port = 5432, user = "x", password = "y")
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (cannot allocate a new connection -- maximum of 16 connections already opened)
作为旁注,它会在几秒钟后很快自动断开连接:
As a side note, it does auto-disconnect quite quickly after a few seconds:
Auto-disconnecting postgres connection (3734, 26)
之后,您可以运行 src_postgres $再次单击c $ c>命令。
after which you can run the src_postgres
command again.
推荐答案
您可以执行以下操作:
RPostgreSQL::dbDisconnect(src_temp$con)
断开连接。
这就是通过 dplyr
(通过 dbi- s3.r
源文件):
That's what's called on garbage collection from this function in dplyr
(via the dbi-s3.r
source file):
# Creates an environment that disconnects the database when it's
# garbage collected
db_disconnector <- function(con, name, quiet = FALSE) {
reg.finalizer(environment(), function(...) {
if (!quiet) {
message("Auto-disconnecting ", name, " connection ",
"(", paste(con@Id, collapse = ", "), ")")
}
dbDisconnect(con)
})
environment()
}
这篇关于断开dplyr中的src_tbls连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文