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.Network.port_open?/3) when the
binary is not installed.
All command execution is routed through Arrea.Command.execute/2
so consumers get the full Arrea infra for free: real timeout
cancellation, validation, telemetry, shell handling, and the
sudo allowlist configured in config/config.exs.
Installation
Optional: install pg_isready (ships with the postgresql-client
package on most distros). Without it, the battery degrades to a
raw TCP probe on the configured port.
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
@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.Network.port_open?/3 when the binary is
not installed.
@spec start_service() :: Botica.Types.fix_result()
Attempts to start the PostgreSQL service via systemctl.
Requires sudo NOPASSWD configured for systemctl start postgresql
(or equivalent). The exact sudo commands allowed are configured
via config :arrea, :engine, sudo_allowlist in config/config.exs.