patroni.config module

class patroni.config.Config(configfile: str, validator: Optional[Callable[[Dict[str, Any]], List[str]]] = <function default_validator>)

Bases: object

This class is responsible for:

  1. Building and giving access to effective_configuration from: * Config.__DEFAULT_CONFIG – some sane default values * dynamic_configuration – configuration stored in DCS * local_configuration – configuration from config.yml or environment

  2. Saving and loading dynamic_configuration into ‘patroni.dynamic.json’ file located in local_configuration[‘postgresql’][‘data_dir’] directory. This is necessary to be able to restore dynamic_configuration if DCS was accidentally wiped

  3. Loading of configuration file in the old format and converting it into new format

  4. Mimicking some of the dict interfaces to make it possible to work with it as with the old config object.

PATRONI_CONFIG_VARIABLE = 'PATRONI_CONFIGURATION'
property config_file: Optional[str]
copy() Dict[str, Any]
property dynamic_configuration: Dict[str, Any]
get(key: str, default: Optional[Any] = None) Any
get_global_config(cluster: Optional[patroni.dcs.Cluster]) patroni.config.GlobalConfig

Instantiate GlobalConfig based on input.

Use the configuration from provided cluster (the most up-to-date) or from the local cache if cluster.config is not initialized or doesn’t have a valid config. :param cluster: the currently known cluster state from DCS :returns: GlobalConfig object

reload_local_configuration() Optional[bool]
save_cache() None
set_dynamic_configuration(configuration: Union[patroni.dcs.ClusterConfig, Dict[str, Any]]) bool
class patroni.config.GlobalConfig(config: Dict[str, Any])

Bases: object

A class that wrapps global configuration and provides convinient methods to access/check values.

It is instantiated by calling Config.global_config() method which picks either a configuration from provided Cluster object (the most up-to-date) or from the local cache if :class::ClusterConfig is not initialized or doesn’t have a valid config.

check_mode(mode: str) bool

Checks whether the certain parameter is enabled.

Parameters

mode – parameter name could be: synchronous_mode, failsafe_mode, pause, check_timeline, and so on

Returns

True if mode is enabled in the global configuration.

get(name: str) Any

Gets global configuration value by name.

Parameters

name – parameter name

Returns

configuration value or None if it is missing

get_int(name: str, default: int = 0) int

Gets current value from the global configuration and trying to return it as int.

Parameters
  • name – name of the parameter

  • default – default value if name is not in the configuration or invalid

Returns

currently configured value from the global configuration or default if it is not set or invalid.

get_standby_cluster_config() Union[Dict[str, Any], Any]
Returns

“standby_cluster” configuration.

property is_paused: bool

True if cluster is in maintenance mode.

Type

returns

property is_standby_cluster: bool

True if global configuration has a valid “standby_cluster” section.

Type

returns

property is_synchronous_mode: bool

True if synchronous replication is requested.

Type

returns

property is_synchronous_mode_strict: bool

True if at least one synchronous node is required.

Type

returns

property maximum_lag_on_failover: int

currently configured value from the global configuration or 1048576 if it is not set or invalid.

Type

returns

property maximum_lag_on_syncnode: int

currently configured value from the global configuration or -1 if it is not set or invalid.

Type

returns

property min_synchronous_nodes: int

the minimal number of synchronous nodes based on whether strict mode is requested or not.

Type

returns

property primary_start_timeout: int

currently configured value from the global configuration or 300 if it is not set or invalid.

Type

returns

property primary_stop_timeout: int

currently configured value from the global configuration or 300 if it is not set or invalid.

Type

returns

property synchronous_node_count: int

currently configured value from the global configuration or 1 if it is not set or invalid.

Type

returns

patroni.config.default_validator(conf: Dict[str, Any]) List[str]
patroni.config.get_global_config(cluster: Optional[patroni.dcs.Cluster], default: Optional[Dict[str, Any]] = None) patroni.config.GlobalConfig

Instantiates GlobalConfig based on the input.

Parameters
  • cluster – the currently known cluster state from DCS

  • default – default configuration, which will be used if there is no valid cluster.config

Returns

GlobalConfig object