Skip to contents

Checks whether a connection to the PostgreSQL database can be established with the current configuration.

Usage

is_db_connect()

Value

Logical. TRUE if the database can be connected successfully, FALSE otherwise.

Details

This function attempts to create a database connection using the credentials in environment variables or taskqueue_options(). It returns FALSE if the connection fails for any reason (wrong credentials, network issues, PostgreSQL not running, etc.).

Useful for testing database configuration before running workers or adding tasks.

Examples

if (FALSE) { # \dontrun{
# Not run:
# Test connection
if (is_db_connect()) {
  message("Database is accessible")
  db_init()
} else {
  stop("Cannot connect to database. Check .Renviron settings.")
}
} # }