有没有办法强制断开与src_tbls
相似的dplyr
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)
作为旁注,几秒后它会很快自动断开连接:
Auto-disconnecting postgres connection (3734, 26)
之后您可以再次运行src_postgres
命令。
答案 0 :(得分:10)
你可以这样做:
RPostgreSQL::dbDisconnect(src_temp$con)
强制断开连接。
在dplyr
中通过dbi-s3.r
(通过# 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()
}
源文件)调用垃圾收集的内容:
{{1}}