Is there a way to force disconnection of a src_tbls
object in dplyr
similar to RPostgreSQL::dbDisconnect
?
See for example:
> 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)
after which you can run the src_postgres
command again.
You can do:
RPostgreSQL::dbDisconnect(src_temp$con)
to force a disconnect.
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()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With