pg_terminate_backend: Terminate all connections to a database

Description Usage Arguments Value Warning Examples

Description

Terminates all connections to a database in case administrative tasks require all connections to be closed. This function requires that you have administrative permissions to the database and that you supply superuser credentials to the pg_con() function.

Usage

1
pg_terminate_backend(host_label, dbname, user_label, pw_label, port = "5432")

Arguments

host_label

a string label to identify the server host

dbname

a database on a PostgreSQL server

user_label

a string label to identify the server username

pw_label

a string label to identify the server password

port

a port string used to connect to the database

Value

A boolean TRUE or FALSE

Warning

If pointing this function to any server other than your localhost, verify first that you are not disrupting any important connections. You may seriously mess up the work of others unless you understand what you are doing.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Not run: 
# Check for open connections to database
db_con_local = pg_con(
  host_label = "my_pg_host_local",
  dbname = "sport_sampling",
  user_label = "my_pg_username_local",
  pw_label = "my_pg_password_local")
open_connections = DBI::dbGetQuery(db_con_local,
                                   "SELECT * FROM pg_stat_activity")
DBI::dbDisconnect(db_con_local)

# Inspect
open_connections

# Terminate all connections to a PostgreSQL database on localhost
pg_message = pg_terminate_backend(
  host_label = "my_pg_host_local",
  dbname = "sport_sampling",
  user_label = "my_pg_super_username_local",
  pw_label = "my_pg_super_password_local")

# Inspect. Should return: [1] TRUE
pg_message

# Verify in pgAdmin that all connections, except the current, are closed.

## End(Not run)

arestrom/repg documentation built on May 9, 2019, 2:25 p.m.