patroni.postgresql.bootstrap module

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

Bases: object

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]]) 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]]) 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: bool
post_bootstrap(config: Dict[str, Any], task: patroni.async_executor.CriticalTask) Optional[bool]
static process_user_options(tool: str, options: Union[Any, Dict[str, str], List[Union[str, Dict[str, Any]]]], not_allowed_options: Tuple[str, ...], error_handler: Callable[[str], None]) List[str]

Format options in a list or dictionary format into command line long form arguments.

Note

The format of the output of this method is to prepare arguments for use in the initdb method of self._postgres.

Example

The options can be defined as a dictionary of key, values to be converted into arguments: >>> Bootstrap.process_user_options(‘foo’, {‘foo’: ‘bar’}, (), print) [’–foo=bar’]

Or as a list of single string arguments >>> Bootstrap.process_user_options(‘foo’, [‘yes’], (), print) [’–yes’]

Or as a list of key, value options >>> Bootstrap.process_user_options(‘foo’, [{‘foo’: ‘bar’}], (), print) [’–foo=bar’]

Or a combination of single and key, values >>> Bootstrap.process_user_options(‘foo’, [‘yes’, {‘foo’: ‘bar’}], (), print) [’–yes’, ‘–foo=bar’]

Options that contain spaces are passed as is to subprocess.call >>> Bootstrap.process_user_options(‘foo’, [{‘foo’: ‘bar baz’}], (), print) [’–foo=bar baz’]

Options that are quoted will be unquoted, so the quotes aren’t interpreted literally by the postgres command >>> Bootstrap.process_user_options(‘foo’, [{‘foo’: ‘“bar baz”’}], (), print) [’–foo=bar baz’]

Note

The error_handler is called when any of these conditions are met:

  • Key, value dictionaries in the list form contains multiple keys.

  • If a key is listed in not_allowed_options.

  • If the options list is not in the required structure.

Parameters
  • tool – The name of the tool used in error reports to error_handler

  • options – Options to parse as a list of key, values or single values, or a dictionary

  • not_allowed_options – List of keys that cannot be used in the list of key, value formatted options

  • error_handler – A function which will be called when an error condition is encountered

Returns

List of long form arguments to pass to the named tool

property running_custom_bootstrap: bool