patroni.postgresql.bootstrap module

class patroni.postgresql.bootstrap.Bootstrap(postgresql: Postgresql)

Bases: object

__init__(postgresql: Postgresql) → None

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

_custom_bootstrap(config: Any) → bool

Bootstrap a fresh Patroni cluster using a custom method provided by the user.

Parameters

config – configuration used for running a custom bootstrap method. It comes from the Patroni YAML file, so it is expected to be a dict.

Note

config must contain a command key, which value is the command or script to perform the custom bootstrap procedure. The exit code of the command dictates if the bootstrap succeeded or failed.

When calling command, Patroni will pass the following arguments to the command call:

  • --scope: contains the value of scope configuration;

  • --data_dir: contains the value of the postgresql.data_dir configuration.

You can avoid that behavior by filling the optional key no_params with the value False in the configuration file, which will instruct Patroni to not pass these parameters to the command call.

Besides that, a couple more keys are supported in config, but optional:

  • keep_existing_recovery_conf: if True, instruct Patroni to not remove the existing recovery.conf (PostgreSQL <= 11), to not discard recovery parameters from the configuration (PostgreSQL >= 12), and to not remove the files recovery.signal or standby.signal (PostgreSQL >= 12). This is specially useful when you are restoring backups through tools like pgBackRest and Barman, in which case they generated the appropriate recovery settings for you;

  • recovery_conf: a section containing a map, where each key is the name of a recovery related setting, and the value is the value of the corresponding setting.

Any key/value other than the ones that were described above will be interpreted as additional arguments for the command call. They will all be added to the call in the format --key=value.

Returns

True if the bootstrap was successful, i.e. the execution of the custom command from config exited with code 0, False otherwise.

_initdb(config: Any) → bool
static _log_output_line(name: str, line: bytes) → None

Log a single line of pg_basebackup output.

Parameters
  • name – name of the stream the line was read from, stdout or stderr.

  • line – one line of output without the trailing newline.

_post_restore() → None
basebackup(conn_url: str, env: Dict[str, str], options: Dict[str, Any]) → Optional[int]
bootstrap(config: Dict[str, Any]) → bool

Initialize a new node from scratch and start it.

call_post_bootstrap(config: Dict[str, Any]) → bool

runs a script after initdb or custom bootstrap script is called and waits until completion.

clone(clone_member: Optional[Union[patroni.dcs.Leader, patroni.dcs.Member]], clone_from_leader: bool = False) → bool
  • initialize the replica from an existing member (primary or replica)

  • initialize the replica using the replica creation method that works without the replication connection (i.e. restore from on-disk base backup)

create_or_update_role(name: str, password: Optional[str], options: List[str]) → None
create_replica(clone_member: Optional[Union[patroni.dcs.Leader, patroni.dcs.Member]], clone_from_leader: bool = False) → Optional[int]

create the replica according to the replica_method defined by the user. this is a list, so we need to loop through all methods the user supplies

property keep_existing_recovery_conf
post_bootstrap(config: Dict[str, Any], task: patroni.async_executor.CriticalTask) → Optional[bool]
property running_custom_bootstrap