Botica.Batteries.PostgreSQL (Botica v2.2.0)

Copy Markdown View Source

Predefined health check for PostgreSQL database connectivity.

This module provides a ready-to-use check that verifies PostgreSQL is accessible. It prefers the pg_isready binary and falls back to a raw TCP port check (via Trebejo.safe_port_open/3) when the binary is not installed.

All command execution uses arg lists — never interpolated into shell strings — to prevent shell injection. Routed through Trebejo.safe_run_cmd_legacy/3 for consistent timeout handling and structured errors.

Usage

config = %{
  app_name: "myapp",
  checks: [
    Botica.Batteries.PostgreSQL.check()
  ]
}

Options

  • :host - PostgreSQL host (default: "localhost")
  • :port - PostgreSQL port (default: 5432)
  • :user - PostgreSQL user (default: "postgres")
  • :timeout - Check timeout in ms (default: 5000)

Summary

Functions

Checks if PostgreSQL is ready to accept connections.

Attempts to start the PostgreSQL service via systemctl.

Functions

check_connection(host, port, user)

@spec check_connection(String.t(), non_neg_integer(), String.t()) ::
  Botica.Types.check_result()

Checks if PostgreSQL is ready to accept connections.

Uses pg_isready when available. Falls back to a TCP probe on the configured port via Trebejo.safe_port_open/3 when the binary is not installed.

start_service()

@spec start_service() :: Botica.Types.fix_result()

Attempts to start the PostgreSQL service via systemctl.