patroni.postgresql.misc module

class patroni.postgresql.misc.PostgresqlRole(value)

Bases: str, enum.Enum

Possible values of Postgresql.role.

DEMOTED = 'demoted'
MASTER = 'master'
PRIMARY = 'primary'
PROMOTED = 'promoted'
REPLICA = 'replica'
STANDBY_LEADER = 'standby_leader'
UNINITIALIZED = 'uninitialized'
_generate_next_value_(start, count, last_values)

Generate the next value when not given.

name: the name of the member start: the initial start value or None count: the number of existing members last_value: the last value assigned or None

_member_map_ = {'DEMOTED': PostgresqlRole.DEMOTED, 'MASTER': PostgresqlRole.MASTER, 'PRIMARY': PostgresqlRole.PRIMARY, 'PROMOTED': PostgresqlRole.PROMOTED, 'REPLICA': PostgresqlRole.REPLICA, 'STANDBY_LEADER': PostgresqlRole.STANDBY_LEADER, 'UNINITIALIZED': PostgresqlRole.UNINITIALIZED}
_member_names_ = ['PRIMARY', 'MASTER', 'STANDBY_LEADER', 'REPLICA', 'DEMOTED', 'UNINITIALIZED', 'PROMOTED']
_member_type_

alias of str

_value2member_map_ = {'demoted': PostgresqlRole.DEMOTED, 'master': PostgresqlRole.MASTER, 'primary': PostgresqlRole.PRIMARY, 'promoted': PostgresqlRole.PROMOTED, 'replica': PostgresqlRole.REPLICA, 'standby_leader': PostgresqlRole.STANDBY_LEADER, 'uninitialized': PostgresqlRole.UNINITIALIZED}
class patroni.postgresql.misc.PostgresqlState(value)

Bases: str, enum.Enum

Possible values of Postgresql.state.

Numeric indexes should NEVER change once assigned to maintain backward compatibility with existing monitoring systems.

BOOTSTRAP_STARTING = 'starting after custom bootstrap'
CRASHED = 'crashed'
CREATING_REPLICA = 'creating replica'
CUSTOM_BOOTSTRAP = 'running custom bootstrap script'
CUSTOM_BOOTSTRAP_FAILED = 'custom bootstrap failed'
INITDB = 'initializing new cluster'
INITDB_FAILED = 'initdb failed'
RESTARTING = 'restarting'
RESTART_FAILED = 'restart failed'
RUNNING = 'running'
STARTING = 'starting'
START_FAILED = 'start failed'
STOPPED = 'stopped'
STOPPING = 'stopping'
STOP_FAILED = 'stop failed'
_generate_next_value_(start, count, last_values)

Generate the next value when not given.

name: the name of the member start: the initial start value or None count: the number of existing members last_value: the last value assigned or None

_member_map_ = {'BOOTSTRAP_STARTING': PostgresqlState.BOOTSTRAP_STARTING, 'CRASHED': PostgresqlState.CRASHED, 'CREATING_REPLICA': PostgresqlState.CREATING_REPLICA, 'CUSTOM_BOOTSTRAP': PostgresqlState.CUSTOM_BOOTSTRAP, 'CUSTOM_BOOTSTRAP_FAILED': PostgresqlState.CUSTOM_BOOTSTRAP_FAILED, 'INITDB': PostgresqlState.INITDB, 'INITDB_FAILED': PostgresqlState.INITDB_FAILED, 'RESTARTING': PostgresqlState.RESTARTING, 'RESTART_FAILED': PostgresqlState.RESTART_FAILED, 'RUNNING': PostgresqlState.RUNNING, 'STARTING': PostgresqlState.STARTING, 'START_FAILED': PostgresqlState.START_FAILED, 'STOPPED': PostgresqlState.STOPPED, 'STOPPING': PostgresqlState.STOPPING, 'STOP_FAILED': PostgresqlState.STOP_FAILED}
_member_names_ = ['INITDB', 'INITDB_FAILED', 'CUSTOM_BOOTSTRAP', 'CUSTOM_BOOTSTRAP_FAILED', 'CREATING_REPLICA', 'RUNNING', 'STARTING', 'BOOTSTRAP_STARTING', 'START_FAILED', 'RESTARTING', 'RESTART_FAILED', 'STOPPING', 'STOPPED', 'STOP_FAILED', 'CRASHED']
_member_type_

alias of str

_value2member_map_ = {'crashed': PostgresqlState.CRASHED, 'creating replica': PostgresqlState.CREATING_REPLICA, 'custom bootstrap failed': PostgresqlState.CUSTOM_BOOTSTRAP_FAILED, 'initdb failed': PostgresqlState.INITDB_FAILED, 'initializing new cluster': PostgresqlState.INITDB, 'restart failed': PostgresqlState.RESTART_FAILED, 'restarting': PostgresqlState.RESTARTING, 'running': PostgresqlState.RUNNING, 'running custom bootstrap script': PostgresqlState.CUSTOM_BOOTSTRAP, 'start failed': PostgresqlState.START_FAILED, 'starting': PostgresqlState.STARTING, 'starting after custom bootstrap': PostgresqlState.BOOTSTRAP_STARTING, 'stop failed': PostgresqlState.STOP_FAILED, 'stopped': PostgresqlState.STOPPED, 'stopping': PostgresqlState.STOPPING}
patroni.postgresql.misc.format_lsn(lsn: int, full: bool = False) str
patroni.postgresql.misc.fsync_dir(path: str) None
patroni.postgresql.misc.get_major_from_minor_version(version: int) int

Extract major PostgreSQL version from the provided full version.

Parameters

version – integer representation of PostgreSQL full version (major + minor).

Returns

integer representation of the PostgreSQL major version.

Example
>>> get_major_from_minor_version(100012)
100000
>>> get_major_from_minor_version(90313)
90300
patroni.postgresql.misc.parse_history(data: str) Iterable[Tuple[int, int, str]]
patroni.postgresql.misc.parse_lsn(lsn: str) int
patroni.postgresql.misc.postgres_major_version_to_int(pg_version: str) int
>>> postgres_major_version_to_int('10')
100000
>>> postgres_major_version_to_int('9.6')
90600
patroni.postgresql.misc.postgres_version_to_int(pg_version: str) int

Convert the server_version to integer

>>> postgres_version_to_int('9.5.3')
90503
>>> postgres_version_to_int('9.3.13')
90313
>>> postgres_version_to_int('10.1')
100001
>>> postgres_version_to_int('10')  
Traceback (most recent call last):
    ...
PostgresException: 'Invalid PostgreSQL version format: X.Y or X.Y.Z is accepted: 10'
>>> postgres_version_to_int('9.6')  
Traceback (most recent call last):
    ...
PostgresException: 'Invalid PostgreSQL version format: X.Y or X.Y.Z is accepted: 9.6'
>>> postgres_version_to_int('a.b.c')  
Traceback (most recent call last):
    ...
PostgresException: 'Invalid PostgreSQL version: a.b.c'