patroni.postgresql.bootstrap module¶
- class patroni.postgresql.bootstrap.Bootstrap(postgresql: Postgresql)¶
Bases:
object
- 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[Leader, 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_replica(clone_member: Optional[Union[Leader, 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
- 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