Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 断开dplyr中的src_tbls连接_Sql_R_Dplyr - Fatal编程技术网

Sql 断开dplyr中的src_tbls连接

Sql 断开dplyr中的src_tbls连接,sql,r,dplyr,Sql,R,Dplyr,是否有一种方法可以强制断开dplyr中的src\u tbls对象的连接,类似于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: (cann

是否有一种方法可以强制断开
dplyr
中的
src\u tbls
对象的连接,类似于
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)
之后,您可以再次运行
src\u postgres
命令。

您可以执行以下操作:

RPostgreSQL::dbDisconnect(src_temp$con)
强行断开连接

这就是在
dplyr
中通过该函数对垃圾收集的调用(通过
dbi-s3.r
源文件):

#创建一个在数据库运行时断开数据库连接的环境
#垃圾收集

db_隔离开关换句话说,您只需
rm()
旧连接,它们将在下一次gc时消失。这对我来说是不会发生的:在
rm(list=ls())
之后,我仍然在postgresqlNewConnection(drv,…)中得到
错误:RS-DBI驱动程序:(�P�_�无法分配新连接(最多16个已打开的连接)
当我尝试打开新的
dplyr::src_postgres(…)
@Dambo时,现在我只需关闭并重新打开项目。这很可靠。@Gabi,因为上面的dplyr版本@Dambo。
RPostgreSQL::dbDisconnect(src_temp$con)
# 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()
}