patroni.postgresql.postmaster module

class patroni.postgresql.postmaster.PostmasterProcess(pid: int)

Bases: psutil.Process

__init__(pid: int) → None

Initialize self. See help(type(self)) for accurate signature.

classmethod _from_pidfile(data_dir: str) → Optional[patroni.postgresql.postmaster.PostmasterProcess]
_is_postmaster_process(pgcommand: str, data_dir: str) → bool

Determine whether this process is the postmaster.

This method applies several heuristics to decide if the PID read from postmaster.pid corresponds to the PostgreSQL postmaster:

  • Excludes the Patroni process itself, its parent, and its direct children.

  • Compares the process start time with the value stored in postmaster.pid, treating a small time difference as a positive match.

  • Checks that the executable name matches the expected binary derived from pgcommand (postgres by default) or postmaster.

  • When possible, verifies that the process current working directory matches the given data directory.

Parameters
  • pgcommand – name of the postgres/postmaster executable that should be running.

  • data_dir – PostgreSQL data directory that contains.

Returns

True if the process is likely the correct postmaster, False otherwise.

static _read_postmaster_pidfile(data_dir: str) → Dict[str, str]

Reads and parses postmaster.pid from the data directory

:returns dictionary of values if successful, empty dictionary otherwise

classmethod from_pid(pid: int) → Optional[patroni.postgresql.postmaster.PostmasterProcess]
static from_pidfile(pgcommand: str, data_dir: str) → Optional[patroni.postgresql.postmaster.PostmasterProcess]
pg_ctl_kill(mode: str, pg_ctl: str) → Optional[bool]
signal_kill() → bool

to suspend and kill postmaster and all children

:returns True if postmaster and children are killed, False if error

signal_stop(mode: str, pg_ctl: str = 'pg_ctl') → Optional[bool]

Signal postmaster process to stop

:returns None if signaled, True if process is already gone, False if error

static start(pgcommand: str, data_dir: str, conf: str, options: List[str]) → Optional[patroni.postgresql.postmaster.PostmasterProcess]
wait_for_user_backends_to_close(stop_timeout: Optional[float]) → Optional[bool]

Wait for all user backend processes to close before the postmaster shuts down.

Auxiliary/background PostgreSQL processes (archiver, checkpointer, wal senders, logical replication workers, and so on) are identified via their command line and excluded, so that only genuine client backends are awaited.

Parameters

stop_timeout – maximum number of seconds to wait for the user backends to close. If None, wait indefinitely.

Returns

True if there were no user backends or all of them closed in time; None if the list of children could not be retrieved or some backends were still alive after stop_timeout.

patroni.postgresql.postmaster.pg_ctl_start(conn: multiprocessing.connection.Connection, cmdline: List[str], env: Dict[str, str]) → None