This is the multi-page printable view of this section. .
Patroni configuration
- 1: Dynamic Configuration Settings
- 2: YAML Configuration Settings
- 3: Environment Configuration Settings
Source: https://patroni.readthedocs.io/en/latest/patroni_configuration.html
There are 3 types of Patroni configuration:
-
Global dynamic configuration.
These options are stored in the DCS (Distributed Configuration Store) and applied on all cluster nodes. Dynamic configuration can be set at any time using patronictl_edit_config tool or Patroni REST API. If the options changed are not part of the startup configuration, they are applied asynchronously (upon the next wake up cycle) to every node, which gets subsequently reloaded. If the node requires a restart to apply the configuration (for PostgreSQL parameters with context postmaster, if their values have changed), a special flagpending_restartindicating this is set in the members.data JSON. Additionally, the node status indicates this by showing"restart_pending": true. -
Local configuration file (patroni.yml).
These options are defined in the configuration file and take precedence over dynamic configuration.patroni.ymlcan be changed and reloaded at runtime (without restart of Patroni) by sending SIGHUP to the Patroni process, performingPOST /reloadREST-API request or executing patronictl_reload. Local configuration can be either a single YAML file or a directory. When it is a directory, all YAML files in that directory are loaded one by one in sorted order. In case a key is defined in multiple files, the occurrence in the last file takes precedence. -
Environment configuration.
It is possible to set/override some of the “Local” configuration parameters with environment variables. Environment configuration is very useful when you are running in a dynamic environment and you don’t know some of the parameters in advance (for example it’s not possible to know your external IP address when you are running insidedocker).
Important rules
PostgreSQL parameters controlled by Patroni
Some of the PostgreSQL parameters must hold the same values on the primary and the replicas. For those, values set either in the local patroni configuration files or via the environment variables take no effect. To alter or set their values one must change the shared configuration in the DCS. Below is the actual list of such parameters together with the default and minimal values:
- max_connections: default value 100, minimal value 25
- max_locks_per_transaction: default value 64, minimal value 32
- max_worker_processes: default value 8, minimal value 2
- max_prepared_transactions: default value 0, minimal value 0
- wal_level: default value hot_standby, accepted values: hot_standby, replica, logical
- track_commit_timestamp: default value off
For the parameters below, PostgreSQL does not require equal values among the primary and all the replicas. However, considering the possibility of a replica to become the primary at any time, it doesn’t really make sense to set them differently; therefore, Patroni restricts setting their values to the dynamic configuration.
- max_wal_senders: default value 10, minimal value 3
- max_replication_slots: default value 10, minimal value 4
- wal_keep_segments: default value 8, minimal value 1
- wal_keep_size: default value 128MB, minimal value 16MB
- wal_log_hints: on
These parameters are validated to ensure they are sane, or meet a minimum value.
There are some other Postgres parameters controlled by Patroni:
- listen_addresses - is set either from
postgresql.listenor fromPATRONI_POSTGRESQL_LISTENenvironment variable - port - is set either from
postgresql.listenor fromPATRONI_POSTGRESQL_LISTENenvironment variable - cluster_name - is set either from
scopeor fromPATRONI_SCOPEenvironment variable - hot_standby: on
To be on the safe side parameters from the above lists are written into postgresql.conf, and passed as a list of arguments to the postgres which gives them the highest precedence (except wal_keep_segments and wal_keep_size), even above ALTER SYSTEM
There also are some parameters like postgresql.listen, postgresql.data_dir that can be set only locally, i.e. in the Patroni config file or via configuration variable. In most cases the local configuration will override the dynamic configuration.
When applying the local or dynamic configuration options, the following actions are taken:
- The node first checks if there is a
postgresql.base.conffile or if thecustom_confparameter is set. - If the
custom_confparameter is set, the file it specifies is used as the base configuration, ignoringpostgresql.base.confandpostgresql.conf. - If the
custom_confparameter is not set andpostgresql.base.confexists, it contains the renamed “original” configuration and is used as the base configuration. - If there is no
custom_confnorpostgresql.base.conf, the originalpostgresql.confis renamed topostgresql.base.confand used as the base configuration. - The dynamic options (with the exceptions above) are dumped into the
postgresql.confand an include is set inpostgresql.confto the base configuration (eitherpostgresql.base.confor the file atcustom_conf). Therefore, we would be able to apply new options without re-reading the configuration file to check if the include is present or not. - Some parameters that are essential for Patroni to manage the cluster are overridden using the command line.
- If an option that requires restart is changed (we should look at the context in pg_settings and at the actual values of those options), a pending_restart flag is set on that node. This flag is reset on any restart.
The parameters would be applied in the following order (run-time are given the highest priority):
- load parameters from file
postgresql.base.conf(or from acustom_conffile, if set) - load parameters from file
postgresql.conf - load parameters from file
postgresql.auto.conf - run-time parameter using
-o --name=value
This allows configuration for all the nodes (2), configuration for a specific node using ALTER SYSTEM (3) and ensures that parameters essential to the running of Patroni are enforced (4), as well as leaves room for configuration tools that manage postgresql.conf directly without involving Patroni (1).
PostgreSQL parameters that touch shared memory
PostgreSQL has some parameters that determine the size of the shared memory used by them:
- max_connections
- max_prepared_transactions
- max_locks_per_transaction
- max_wal_senders
- max_worker_processes
Changing these parameters require a PostgreSQL restart to take effect, and their shared memory structures cannot be smaller on the standby nodes than on the primary node.
As explained before, Patroni restrict changing their values through dynamic configuration, which usually consists of:
- Applying changes through patronictl_edit_config (or via REST API
/configendpoint) - Restarting nodes through patronictl_restart (or via REST API
/restartendpoint)
Note: please keep in mind that you should perform a restart of the PostgreSQL nodes through patronictl_restart command, or via REST API /restart endpoint. An attempt to restart PostgreSQL by restarting the Patroni daemon, e.g. by executing systemctl restart patroni, can cause a failover to occur in the cluster, if you are restarting the primary node.
However, as those settings manage shared memory, some extra care should be taken when restarting the nodes:
-
If you want to increase the value of any of those settings:
- Restart all standbys first
- Restart the primary after that
-
If you want to decrease the value of any of those settings:
- Restart the primary first
- Restart all standbys after that
Note: if you attempt to restart all nodes in one go after decreasing the value of any of those settings, Patroni will ignore the change and restart the standby with the original setting value, thus requiring that you restart the standbys again later. Patroni does that to prevent the standby to enter in an infinite crash loop, because PostgreSQL quits with a FATAL message if you attempt to set any of those parameters to a value lower than what is visible in pg_controldata on the Standby node. In other words, we can only decrease the setting on the standby once its pg_controldata is up-to-date with the primary in regards to these changes on the primary.
More information about that can be found at PostgreSQL Administrator’s Overview.
Patroni configuration parameters
Also the following Patroni configuration options can be changed only dynamically:
- ttl: 30
- loop_wait: 10
- retry_timeout: 10
- maximum_lag_on_failover: 1048576
- max_timelines_history: 0
- check_timeline: false
- postgresql.use_slots: true
Upon changing these options, Patroni will read the relevant section of the configuration stored in DCS and change its run-time values.
Patroni nodes are dumping the state of the DCS options to disk upon for every change of the configuration into the file patroni.dynamic.json located in the Postgres data directory. Only the leader is allowed to restore these options from the on-disk dump if these are completely absent from the DCS or if they are invalid.
Configuration generation and validation
Patroni provides command-line interfaces for a Patroni local configuration generation and validation. Using the patroni executable you can:
- Create a sample local Patroni configuration;
- Create a Patroni configuration file for the locally running PostgreSQL instance (e.g. as a preparation step for the Patroni integration);
- Validate a given Patroni configuration file.
Sample Patroni configuration
Description
Generate a sample Patroni configuration file in yaml format. Parameter values are defined using the Environment configuration, otherwise, if not set, the defaults used in Patroni or the #FIXME string for the values that should be later defined by the user.
Some default values are defined based on the local setup:
- postgresql.listen: the IP address returned by
gethostnamecall for the current machine’s hostname and the standard5432port.- postgresql.connect_address: the IP address returned by
gethostnamecall for the current machine’s hostname and the standard5432port.- postgresql.authentication.rewind: is only defined if the PostgreSQL version can be defined from the binary and the version is 11 or later.
- restapi.listen: IP address returned by
gethostnamecall for the current machine’s hostname and the standard8008port.- restapi.connect_address: IP address returned by
gethostnamecall for the current machine’s hostname and the standard8008port.
Parameters
configfile - full path to the configuration file used to store the result. If not provided, the result is sent to stdout.
Patroni configuration for a running instance
Description
Generate a Patroni configuration in yaml format for the locally running PostgreSQL instance. Either the provided DSN (takes precedence) or PostgreSQL environment variables will be used for the PostgreSQL connection. If the password is not provided, it should be entered via prompt.
All the non-internal GUCs defined in the source Postgres instance, independently if they were set through a configuration file, through the postmaster command-line, or through environment variables, will be used as the source for the following Patroni configuration parameters:
- scope:
cluster_nameGUC value;- postgresql.listen:
listen_addressesandportGUC values;- postgresql.datadir:
data_directoryGUC value;- postgresql.parameters:
archive_command,restore_command,archive_cleanup_command,recovery_end_command,ssl_passphrase_command,hba_file,ident_file,config_fileGUC values;- bootstrap.dcs: all other gathered PostgreSQL GUCs.
If scope, postgresql.listen or postgresql.datadir is not set from the Postgres GUCs, the respective Environment configuration value is used.
Other rules applied for the values definition:
- name:
PATRONI_NAMEenvironment variable value if set, otherwise the current machine’s hostname.- postgresql.bin_dir: path to the Postgres binaries gathered from the running instance.
- postgresql.connect_address: the IP address returned by
gethostnamecall for the current machine’s hostname and the port used for the instance connection or theportGUC value.- postgresql.authentication.superuser: the configuration used for the instance connection;
- postgresql.pg_hba: the lines gathered from the source instance’s
hba_file.- postgresql.pg_ident: the lines gathered from the source instance’s
ident_file.- restapi.listen: IP address returned by
gethostnamecall for the current machine’s hostname and the standard8008port.- restapi.connect_address: IP address returned by
gethostnamecall for the current machine’s hostname and the standard8008port.
Other parameters defined using Environment configuration are also included into the configuration.
Parameters
configfile
Full path to the configuration file used to store the result. If not provided, result is sent to stdout.
dsn
Optional DSN string for the local PostgreSQL instance to get GUC values from.
Validate Patroni configuration
Description
Validate the given Patroni configuration and print the information about the failed checks.
Parameters
configfile
Full path to the configuration file to check. If not given or file does not exist, will try to read from the PATRONI_CONFIG_VARIABLE environment variable or, if not set, from the Patroni environment variables.
--ignore-listen-port | -i
Optional flag to ignore bind failures for listen ports that are already in use when validating the configfile.
--print | -p
Optional flag to print out local configuration (including environment configuration overrides) after it has been successfully validated.
1 - Dynamic Configuration Settings
Source: https://patroni.readthedocs.io/en/latest/dynamic_configuration.html
Dynamic configuration is stored in the DCS (Distributed Configuration Store) and applied on all cluster nodes.
In order to change the dynamic configuration you can use either patronictl_edit_config tool or Patroni REST API.
- loop_wait: the number of seconds the loop will sleep. Default value: 10, minimum possible value: 1
- ttl: the TTL to acquire the leader lock (in seconds). Think of it as the length of time before initiation of the automatic failover process. Default value: 30, minimum possible value: 20
- retry_timeout: timeout for DCS and PostgreSQL operation retries (in seconds). DCS or network issues shorter than this will not cause Patroni to demote the leader. Default value: 10, minimum possible value: 3
when changing values of loop_wait, retry_timeout, or ttl you have to follow the rule:
- maximum_lag_on_failover: the maximum bytes a follower may lag to be able to participate in leader election.
- primary_race_backoff: postpones leader race on standbys by
primary_race_backoffseconds if WAL replication from the primary is still advancing. It allows to minimize unnecessary failovers caused by briefly unresponsive Patroni. Default value: 0 (disabled). - maximum_lag_on_syncnode: the maximum bytes a synchronous follower may lag before it is considered as an unhealthy candidate and swapped by healthy asynchronous follower. Patroni utilize the max replica lsn if there is more than one follower, otherwise it will use leader’s current wal lsn. Default is -1, Patroni will not take action to swap synchronous unhealthy follower when the value is set to 0 or below. Please set the value high enough so Patroni won’t swap synchrounous follower frequently during high transaction volume.
- max_timelines_history: maximum number of timeline history items kept in DCS. Default value: 0. When set to 0, it keeps the full history in DCS.
- primary_start_timeout: the amount of time a primary is allowed to recover from failures before failover is triggered (in seconds). Default is 300 seconds. When set to 0 failover is done immediately after a crash is detected if possible. When using asynchronous replication a failover can cause lost transactions. Worst case failover time for primary failure is: loop_wait + primary_start_timeout + loop_wait, unless primary_start_timeout is zero, in which case it’s just loop_wait. Set the value according to your durability/availability tradeoff.
- primary_stop_timeout: The number of seconds Patroni is allowed to wait when stopping Postgres and effective only when synchronous_mode is enabled. When set to > 0 and the synchronous_mode is enabled, Patroni sends SIGKILL to the postmaster if the stop operation is running for more than the value set by primary_stop_timeout. Set the value according to your durability/availability tradeoff. If the parameter is not set or set <= 0, primary_stop_timeout does not apply.
- synchronous_mode: turns on synchronous replication mode. Possible values:
off,on,quorum. In this mode the leader takes care of management ofsynchronous_standby_names, and only the last known leader, or one of synchronous replicas, are allowed to participate in leader race. Synchronous mode makes sure that successfully committed transactions will not be lost at failover, at the cost of losing availability for writes when Patroni cannot ensure transaction durability. See replication modes documentation for details. - synchronous_mode_strict: prevents disabling synchronous replication if no synchronous replicas are available, blocking all client writes to the primary. When this option is set and no eligible replica is streaming, Patroni keeps
synchronous_standby_namespointing to the last known synchronous nodes from the/syncDCS key, or uses the internal placeholder__patroni_strict_sync_replica_placeholder__when no prior sync state exists. The nodenameinpatroni.yamlmust not be set to__patroni_strict_sync_replica_placeholder__. See replication modes documentation for details. - synchronous_node_count: if synchronous_mode is enabled, this parameter is used by Patroni to manage the precise number of synchronous standby instances and adjusts the state in DCS and the
synchronous_standby_namesparameter in PostgreSQL as members join and leave. If the parameter is set to a value higher than the number of eligible nodes, it will be automatically adjusted. Defaults to1. - failsafe_mode: Enables DCS Failsafe Mode. Defaults to
false. - postgresql:
- use_pg_rewind: whether or not to use pg_rewind. Defaults to
false. Note that either the cluster must be initialized withdata page checksums(--data-checksumsoption forinitdb) and/orwal_log_hintsmust be set toon, orpg_rewindwill not work. - use_slots: whether or not to use replication slots. Defaults to
trueon PostgreSQL 9.4+. - recovery_conf: additional configuration settings written to recovery.conf when configuring follower. There is no recovery.conf anymore in PostgreSQL 12, but you may continue using this section, because Patroni handles it transparently.
- parameters: configuration parameters (GUCs) for Postgres in format
{max_connections: 100, wal_level: "replica", max_wal_senders: 10, wal_log_hints: "on"}. Many of these are required for replication to work. - parameters_primary: (optional) role-specific parameter overrides for primary. These values are merged with and override the base parameters.
- parameters_replica: (optional) role-specific parameter overrides for replica. These values are merged with and override the base parameters.
- parameters_standby_leader: (optional) role-specific parameter overrides for standby_leader. These values are merged with and override the base parameters.
- pg_hba: list of lines that Patroni will use to generate
pg_hba.conf. Patroni ignores this parameter ifhba_filePostgreSQL parameter is set to a non-default value.- - host all all 0.0.0.0/0 md5
- - host replication replicator 127.0.0.1/32 md5: A line like this is required for replication.
- pg_hba_primary: (optional) role-specific pg_hba entries for primary. These completely replace pg_hba (no merging). If not defined, pg_hba is used.
- pg_hba_replica: (optional) role-specific pg_hba entries for replica. These completely replace pg_hba (no merging). If not defined, pg_hba is used.
- pg_hba_standby_leader: (optional) role-specific pg_hba entries for standby_leader. These completely replace pg_hba (no merging). If not defined, pg_hba is used.
- pg_ident: list of lines that Patroni will use to generate
pg_ident.conf. Patroni ignores this parameter ifident_filePostgreSQL parameter is set to a non-default value.- - mapname1 systemname1 pguser1
- - mapname1 systemname2 pguser2
- pg_ident_primary: (optional) role-specific pg_ident entries for primary. These completely replace pg_ident (no merging). If not defined, pg_ident is used.
- pg_ident_replica: (optional) role-specific pg_ident entries for replica. These completely replace pg_ident (no merging). If not defined, pg_ident is used.
- pg_ident_standby_leader: (optional) role-specific pg_ident entries for standby_leader. These completely replace pg_ident (no merging). If not defined, pg_ident is used.
- use_pg_rewind: whether or not to use pg_rewind. Defaults to
- standby_cluster: if this section is defined, we want to bootstrap a standby cluster.
- host: an address of remote node
- port: a port of remote node
- primary_slot_name: which slot on the remote node to use for replication. This parameter is optional, the default value is derived from the instance name (see function
slot_name_from_member_name). - create_replica_methods: an ordered list of methods that can be used to bootstrap standby leader from the remote primary, can be different from the list defined in postgresql_settings
- restore_command: command to restore WAL records from the remote primary to nodes in a standby cluster, can be different from the list defined in postgresql_settings
- archive_cleanup_command: cleanup command for standby leader
- recovery_min_apply_delay: how long to wait before actually apply WAL records on a standby leader
- member_slots_ttl: retention time of physical replication slots for replicas when they are shut down. Default value:
30min. Set it to0if you want to keep the old behavior (when the member key expires from DCS, the slot is immediately removed). The feature works only starting from PostgreSQL 11. - slots: define permanent replication slots. These slots will be preserved during switchover/failover. Permanent slots that don’t exist will be created by Patroni. With PostgreSQL 11 onwards permanent physical slots are created on all nodes and their position is advanced every loop_wait seconds. For PostgreSQL versions older than 11 permanent physical replication slots are maintained only on the current primary. The logical slots are copied from the primary to a standby with restart, and after that their position advanced every loop_wait seconds (if necessary). Copying logical slot files performed via
libpqconnection and using either rewind or superuser credentials (see postgresql.authentication section). There is always a chance that the logical slot position on the replica is a bit behind the former primary, therefore application should be prepared that some messages could be received the second time after the failover. The easiest way of doing so - trackingconfirmed_flush_lsn. Enabling permanent replication slots requires postgresql.use_slots to be set totrue. If there are permanent logical replication slots defined Patroni will automatically enable thehot_standby_feedback. Since the failover of logical replication slots is unsafe on PostgreSQL 9.6 and older and PostgreSQL version 10 is missing some important functions, the feature only works with PostgreSQL 11+.- my_slot_name: the name of the permanent replication slot. If the permanent slot name matches with the name of the current node it will not be created on this node. If you add a permanent physical replication slot which name matches the name of a Patroni member, Patroni will ensure that the slot that was created is not removed even if the corresponding member becomes unresponsive, situation which would normally result in the slot’s removal by Patroni. Although this can be useful in some situations, such as when you want replication slots used by members to persist during temporary failures or when importing existing members to a new Patroni cluster (see Convert a Standalone to a Patroni Cluster for details), caution should be exercised by the operator that these clashes in names are not persisted in the DCS, when the slot is no longer required, due to its effect on normal functioning of Patroni.
- type: slot type. Could be
physicalorlogical. If the slot is logical, you have to additionally definedatabaseandplugin. If the slot is physical, you can optionally definecluster_type. - database: the database name where logical slots should be created.
- plugin: the plugin name for the logical slot.
- cluster_type: the type of cluster (
primaryorstandby) the slot should only be created on, otherwise it will not be created or an already existing slot will be dropped.
- type: slot type. Could be
- my_slot_name: the name of the permanent replication slot. If the permanent slot name matches with the name of the current node it will not be created on this node. If you add a permanent physical replication slot which name matches the name of a Patroni member, Patroni will ensure that the slot that was created is not removed even if the corresponding member becomes unresponsive, situation which would normally result in the slot’s removal by Patroni. Although this can be useful in some situations, such as when you want replication slots used by members to persist during temporary failures or when importing existing members to a new Patroni cluster (see Convert a Standalone to a Patroni Cluster for details), caution should be exercised by the operator that these clashes in names are not persisted in the DCS, when the slot is no longer required, due to its effect on normal functioning of Patroni.
- ignore_slots: list of sets of replication slot properties for which Patroni should ignore matching slots. This configuration/feature/etc. is useful when some replication slots are managed outside of Patroni. Any subset of matching properties will cause a slot to be ignored.
- name: the name of the replication slot.
- type: slot type. Can be
physicalorlogical. If the slot is logical, you may additionally definedatabaseand/orplugin. - database: the database name (when matching a
logicalslot). - plugin: the logical decoding plugin (when matching a
logicalslot).
Note: slots is a hashmap while ignore_slots is an array. For example:
Note: When running PostgreSQL v11 or newer Patroni maintains physical replication slots on all nodes that could potentially become a leader, so that replica nodes keep WAL segments reserved if they are potentially required by other nodes. In case the node is absent and its member key in DCS gets expired, the corresponding replication slot is dropped after member_slots_ttl (default value is 30min). You can increase or decrease retention based on your needs. Alternatively, if your cluster topology is static (fixed number of nodes that never change their names) you can configure permanent physical replication slots with names corresponding to the names of the nodes to avoid slots removal and recycling of WAL files while replica is temporarily down:
Permanent replication slots are synchronized only from the primary/standby_leader to replica nodes. That means, applications are supposed to be using them only from the leader node. Using them on replica nodes will cause indefinite growth of pg_wal on all other nodes in the cluster. An exception to that rule are physical slots that match the Patroni member names (created and maintained by Patroni). Those will be synchronized among all nodes as they are used for replication among them.
Setting nostream tag on standby disables copying and synchronization of permanent logical replication slots on the node itself and all its cascading replicas if any.
2 - YAML Configuration Settings
Source: https://patroni.readthedocs.io/en/latest/yaml_configuration.html
Global/Universal
- thread_pool_size: size of thread pool used by Patroni to execute asynchronous tasks and communicate via REST API with other members during leader race or failsafe checks. Minimal value is
5, default value is5. - thread_stack_size: specifies the stack size to be used for threads started by Patroni. Value must be aligned by
64kB. Minimal value is64kB, default value (set by Patroni) is512kB. - name: the name of the host. Must be unique for the cluster. The value
__patroni_strict_sync_replica_placeholder__is reserved for internal use by Patroni and cannot be used as a node name. - namespace: path within the configuration store where Patroni will keep information about the cluster. Default value: “/service”
- scope: cluster name
Log
- type: sets the format of logs. Can be either plain or json. To use json format, you must have the jsonlogger installed. The default value is plain.
- level: sets the general logging level. Default value is INFO (see the docs for Python logging)
- traceback_level: sets the level where tracebacks will be visible. Default value is ERROR. Set it to DEBUG if you want to see tracebacks only if you enable log.level=DEBUG.
- format: sets the log formatting string. If the log type is plain, the log format should be a string. Refer to the LogRecord attributes for available attributes. If the log type is json, the log format can be a list in addition to a string. Each list item should correspond to LogRecord attributes. Be cautious that only the field name is required, and the %( and ) should be omitted. If you wish to print a log field with a different key name, use a dictionary where the dictionary key is the log field, and the value is the name of the field you want to be printed in the log. Default value is %(asctime)s %(levelname)s: %(message)s
- dateformat: sets the datetime formatting string. (see the formatTime() documentation)
- static_fields: add additional fields to the log. This option is only available when the log type is set to json.
- max_queue_size: Patroni is using two-step logging. Log records are written into the in-memory queue and there is a separate thread which pulls them from the queue and writes to stderr or file. The maximum size of the internal queue is limited by default by 1000 records, which is enough to keep logs for the past 1h20m.
- dir: Directory to write application logs to. The directory must exist and be writable by the user executing Patroni. If you set this value, the application will retain 4 25MB logs by default. You can tune those retention values with
file_numandfile_size(see below). - mode: Permissions for log files (for example,
0644). If not specified, permissions will be set based on the current umask value. - file_num: The number of application logs to retain.
- file_size: Size of patroni.log file (in bytes) that triggers a log rolling.
- loggers: This section allows redefining logging level per python module
- patroni.postmaster: WARNING
- urllib3: DEBUG
- deduplicate_heartbeat_logs: If set to
true, successive heartbeat logs that are identical shall not be output. Default value isfalse.
The time the HA loop executes at can be very valuable information in diagnosing failovers due to resource exhaustion and similar problems. When deduplicate_heartbeat_logs is set to true there will be no log generated for the HA loop execution (unless the leader changes) and hence this potentially useful information will not be available from the logs.
Here is an example of how to config patroni to log in json format.
Bootstrap configuration
Once Patroni has initialized the cluster for the first time and settings have been stored in the DCS, all future changes to the bootstrap.dcs section of the YAML configuration will not take any effect! If you want to change them please use either patronictl_edit_config or the Patroni REST API.
- bootstrap:
-
dcs: This section will be written into /<namespace>/<scope>/config of the given configuration store after initializing the new cluster. The global dynamic configuration for the cluster. You can put any of the parameters described in the Dynamic Configuration settings under
bootstrap.dcsand after Patroni has initialized (bootstrapped) the new cluster, it will write this section into /<namespace>/<scope>/config of the configuration store. -
method: custom script to use for bootstrapping this cluster.
See custom bootstrap methods documentation for details. When
initdbis specified revert to the defaultinitdbcommand.initdbis also triggered when nomethodparameter is present in the configuration file. -
initdb: (optional) list options to be passed on to initdb.
- - data-checksums: Must be enabled when pg_rewind is needed on 9.3.
- - encoding: UTF8: default encoding for new databases.
- - locale: UTF8: default locale for new databases.
-
post_bootstrap or post_init: An additional script that will be executed after initializing the cluster. The script receives a connection string URL (with the cluster superuser as a user name). The PGPASSFILE variable is set to the location of pgpass file.
-
Citus
Enables integration Patroni with Citus. If configured, Patroni will take care of registering Citus worker nodes on the coordinator. You can find more information about Citus support here.
- group: the Citus group id, integer. Use
0for coordinator and1,2, etc… for workers - database: the database where citus extension should be created. Must be the same on the coordinator and all workers. Currently only one database is supported.
Consul
Most of the parameters are optional, but you have to specify one of the host or url
- host: the host:port for the Consul local agent.
- url: url for the Consul local agent, in format: http(s)://host:port.
- port: (optional) Consul port.
- scheme: (optional) http or https, defaults to http.
- token: (optional) ACL token.
- verify: (optional) whether to verify the SSL certificate for HTTPS requests.
- cacert: (optional) The ca certificate. If present it will enable validation.
- cert: (optional) file with the client certificate.
- key: (optional) file with the client key. Can be empty if the key is part of cert.
- dc: (optional) Datacenter to communicate with. By default the datacenter of the host is used.
- consistency: (optional) Select consul consistency mode. Possible values are
default,consistent, orstale(more details in consul API reference) - checks: (optional) list of Consul health checks used for the session. By default an empty list is used.
- register_service: (optional) whether or not to register a service with the name defined by the scope parameter and the tag master, primary, replica, or standby-leader depending on the node’s role. Defaults to false.
- service_tags: (optional) additional static tags to add to the Consul service apart from the role (
primary/replica/standby-leader). By default an empty list is used. - service_check_interval: (optional) how often to perform health check against registered url. Defaults to ‘5s’.
- service_check_tls_server_name: (optional) override SNI host when connecting via TLS, see also consul agent check API reference.
The token needs to have the following ACL permissions:
service_prefix "${scope}" {
policy = "write"
}
key_prefix "${namespace}/${scope}" {
policy = "write"
}
session_prefix "" {
policy = "write"
}
Etcd
Most of the parameters are optional, but you have to specify one of the host, hosts, url, proxy or srv
- host: the host:port for the etcd endpoint.
- hosts: list of etcd endpoint in format host1:port1,host2:port2,etc… Could be a comma separated string or an actual yaml list.
- use_proxies: If this parameter is set to true, Patroni will consider hosts as a list of proxies and will not perform a topology discovery of etcd cluster.
- url: url for the etcd.
- proxy: proxy url for the etcd. If you are connecting to the etcd using proxy, use this parameter instead of url.
- srv: Domain to search the SRV record(s) for cluster autodiscovery. Patroni will try to query these SRV service names for specified domain (in that order until first success):
_etcd-client-ssl,_etcd-client,_etcd-ssl,_etcd,_etcd-server-ssl,_etcd-server. If SRV records for_etcd-server-sslor_etcd-serverare retrieved then ETCD peer protocol is used do query ETCD for available members. Otherwise hosts from SRV records will be used. - srv_suffix: Configures a suffix to the SRV name that is queried during discovery. Use this flag to differentiate between multiple etcd clusters under the same domain. Works only with conjunction with srv. For example, if
srv_suffix: fooandsrv: example.orgare set, the following DNS SRV query is made:_etcd-client-ssl-foo._tcp.example.com(and so on for every possible ETCD SRV service name). - protocol: (optional) http or https, if not specified http is used. If the url or proxy is specified - will take protocol from them.
- username: (optional) username for etcd authentication.
- password: (optional) password for etcd authentication.
- cacert: (optional) The ca certificate. If present it will enable validation.
- cert: (optional) file with the client certificate.
- key: (optional) file with the client key. Can be empty if the key is part of cert.
Etcdv3
If you want that Patroni works with Etcd cluster via protocol version 3, you need to use the etcd3 section in the Patroni configuration file. All configuration parameters are the same as for etcd.
Keys created with protocol version 2 are not visible with protocol version 3 and the other way around, therefore it is not possible to switch from etcd to etcd3 just by updating Patroni config file. In addition, Patroni uses Etcd’s gRPC-gateway (proxy) to communicate with the V3 API, which means that TLS common name authentication is not possible.
ZooKeeper
- hosts: List of ZooKeeper cluster members in format: .
- use_ssl: (optional) Whether SSL is used or not. Defaults to
false. If set tofalse, all SSL specific parameters are ignored. - cacert: (optional) The CA certificate. If present it will enable validation.
- cert: (optional) File with the client certificate.
- key: (optional) File with the client key.
- key_password: (optional) The client key password.
- verify: (optional) Whether to verify certificate or not. Defaults to
true. - set_acls: (optional) If set, configures Kazoo to apply a default ACL to each ZNode that it creates. ACLs can use either the
x509schema (default) or other supported ZooKeeper schemes such asdigest. They should be specified as a dictionary where the key is the full principal (optionally prefixed with the scheme) and the value is a list of permissions. Permissions may be one or more ofCREATE,READ,WRITE,DELETE,ADMIN, orALL. For example,set_acls: {CN=principal1: [CREATE, READ], digest:principal2:+pjROuBuuwNNSujKyH8dGcEnFPQ=: [ALL]}. - auth_data: (optional) Authentication credentials to use for the connection. Should be a dictionary in the form that
schemeis the key andcredentialis the value. Defaults to empty dictionary.
It is required to install kazoo>=2.6.0 to support SSL.
Exhibitor
- hosts: initial list of Exhibitor (ZooKeeper) nodes in format: ‘host1,host2,etc…’. This list updates automatically whenever the Exhibitor (ZooKeeper) cluster topology changes.
- poll_interval: how often the list of ZooKeeper and Exhibitor nodes should be updated from Exhibitor.
- port: Exhibitor port.
Kubernetes
- bypass_api_service: (optional) When communicating with the Kubernetes API, Patroni is usually relying on the kubernetes service, the address of which is exposed in the pods via the
KUBERNETES_SERVICE_HOSTenvironment variable. Ifbypass_api_serviceis set totrue, Patroni will resolve the list of API nodes behind the service and connect directly to them. - namespace: (optional) Kubernetes namespace where Patroni pod is running. Default value is
default. - labels: Labels in format
{label1: value1, label2: value2}. These labels will be used to find existing objects (Pods and either Endpoints or ConfigMaps) associated with the current cluster. Also Patroni will set them on every object (Endpoint or ConfigMap) it creates. - scope_label: (optional) name of the label containing cluster name. Default value is
cluster-name. - bootstrap_labels: (optional) Labels in format
{label1: value1, label2: value2}. These labels will be assigned to a Patroni pod when its state is eitherinitializing new cluster,running custom bootstrap script,starting after custom bootstraporcreating replica. - role_label: (optional) name of the label containing role (
primary,replica, or other custom value). Patroni will set this label on the pod it runs in. Default value isrole. - leader_label_value: (optional) value of the pod label when Postgres role is
primary. Default value isprimary. - follower_label_value: (optional) value of the pod label when Postgres role is
replica. Default value isreplica. - standby_leader_label_value: (optional) value of the pod label when Postgres role is
standby_leader. Default value isprimary. - tmp_role_label: (optional) name of the temporary label containing role (
primaryorreplica). Value of this label will always use the default of corresponding role. Set only when necessary. - use_endpoints: (optional) if set to true, Patroni will use Endpoints instead of ConfigMaps to run leader elections and keep cluster state.
- pod_ip: (optional) IP address of the pod Patroni is running in. This value is required when
use_endpointsis enabled and is used to populate the leader endpoint subsets when the pod’s PostgreSQL is promoted. - ports: (optional) if the Service object has the name for the port, the same name must appear in the Endpoint object, otherwise service won’t work. For example, if your service is defined as
{Kind: Service, spec: {ports: [{name: postgresql, port: 5432, targetPort: 5432}]}}, then you have to setkubernetes.ports: [{"name": "postgresql", "port": 5432}]and Patroni will use it for updating subsets of the leader Endpoint. This parameter is used only ifkubernetes.use_endpointsis set. - cacert: (optional) Specifies the file with the CA_BUNDLE file with certificates of trusted CAs to use while verifying Kubernetes API SSL certs. If not provided, patroni will use the value provided by the ServiceAccount secret.
- retriable_http_codes: (optional) list of HTTP status codes from K8s API to retry on. By default Patroni is retrying on
500,503, and504, or if K8s API response hasretry-afterHTTP header.
Raft (deprecated)
-
self_addr:
ip:portto listen on for Raft connections. Theself_addrmust be accessible from other nodes of the cluster. If not set, the node will not participate in consensus. -
bind_addr: (optional)
ip:portto listen on for Raft connections. If not specified theself_addrwill be used. -
partner_addrs: list of other Patroni nodes in the cluster in format:
-
data_dir: directory where to store Raft log and snapshot. If not specified the current working directory is used.
-
password: (optional) Encrypt Raft traffic with a specified password, requires
cryptographypython module. -
min_timeout: (optional) minimum election timeout in seconds for the underlying pysyncobj Raft implementation. Must be greater than 3 *
append_entries_period. Default:0.4. -
max_timeout: (optional) maximum election timeout in seconds for the underlying pysyncobj Raft implementation. Must be greater than
min_timeout. Default:1.4. -
connection_timeout: (optional) time in seconds after which a connection with no data received is considered dead. Must be greater than or equal to
max_timeout. Default:3.5. -
append_entries_period: (optional) interval in seconds for sending heartbeat (append_entries) commands. Must be less than one-third of
min_timeout. Default:0.1. -
connection_retry_time: (optional) interval in seconds between reconnection attempts to offline nodes. Default:
5.0. -
leader_fallback_timeout: (optional) time in seconds after which a leader with no response from the majority falls back to follower state. Must be greater than
append_entries_period. Default:30.0.
These timeout parameters are useful for high-latency networks where the default pysyncobj timeouts are too aggressive. The following constraints must be satisfied: min_timeout > 3 * append_entries_period, max_timeout > min_timeout, connection_timeout >= max_timeout, and leader_fallback_timeout > append_entries_period. Patroni validates these at startup and will refuse to start if they are violated. These values cannot be changed at runtime and require a restart.
[!WARNING]
These knobs only relax the pysyncobj election and connection timeouts; they do not extend the per-command deadline that Patroni applies to Raft operations. Each Raft command (leader-lock refresh, cluster-state write) must still complete within retry_timeout (default 10). On very high-latency links - roughly above a few seconds of round-trip time - a single command can exceed retry_timeout even when connection_timeout is raised well above the RTT, so the DCS will appear unreachable and the primary may demote. On such links you must also raise retry_timeout and ttl accordingly, keeping loop_wait + 2 * retry_timeout <= ttl.
Short FAQ about Raft implementation
-
Q: How to list all the nodes providing consensus?
A:
syncobj_admin -conn host:port -statuswhere the host:port is the address of one of the cluster nodes -
Q: Node that was a part of consensus and has gone and I can’t reuse the same IP for other node. How to remove this node from the consensus?
A:
syncobj_admin -conn host:port -remove host2:port2where thehost2:port2is the address of the node you want to remove from consensus. -
Q: Where to get the
syncobj_adminutility?A: It is installed together with
pysyncobjmodule (python RAFT implementation), which is Patroni dependency. -
Q: it is possible to run Patroni node without adding in to the consensus?
A: Yes, just comment out or remove
raft.self_addrfrom Patroni configuration. -
Q: It is possible to run Patroni and PostgreSQL only on two nodes?
A: Yes, on the third node you can run
patroni_raft_controller(without Patroni and PostgreSQL). In such a setup, one can temporarily lose one node without affecting the primary.
PostgreSQL
- postgresql:
-
authentication:
- superuser:
- username: name for the superuser, set during initialization (initdb) and later used by Patroni to connect to the postgres.
- password: password for the superuser, set during initialization (initdb).
- sslmode: (optional) maps to the sslmode connection parameter, which allows a client to specify the type of TLS negotiation mode with the server. For more information on how each mode works, please visit the PostgreSQL documentation. The default mode is
prefer. - sslkey: (optional) maps to the sslkey connection parameter, which specifies the location of the secret key used with the client’s certificate.
- sslpassword: (optional) maps to the sslpassword connection parameter, which specifies the password for the secret key specified in
sslkey. - sslcert: (optional) maps to the sslcert connection parameter, which specifies the location of the client certificate.
- sslrootcert: (optional) maps to the sslrootcert connection parameter, which specifies the location of a file containing one or more certificate authorities (CA) certificates that the client will use to verify a server’s certificate.
- sslcrl: (optional) maps to the sslcrl connection parameter, which specifies the location of a file containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- sslcrldir: (optional) maps to the sslcrldir connection parameter, which specifies the location of a directory with files containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- sslnegotiation: (optional) maps to the sslnegotiation connection parameter, which controls how SSL encryption is negotiated with the server, if SSL is used.
- gssencmode: (optional) maps to the gssencmode connection parameter, which determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server
- channel_binding: (optional) maps to the channel_binding connection parameter, which controls the client’s use of channel binding.
- replication:
- username: replication username; the user will be created during initialization. Replicas will use this user to access the replication source via streaming replication
- password: replication password; the user will be created during initialization.
- sslmode: (optional) maps to the sslmode connection parameter, which allows a client to specify the type of TLS negotiation mode with the server. For more information on how each mode works, please visit the PostgreSQL documentation. The default mode is
prefer. - sslkey: (optional) maps to the sslkey connection parameter, which specifies the location of the secret key used with the client’s certificate.
- sslpassword: (optional) maps to the sslpassword connection parameter, which specifies the password for the secret key specified in
sslkey. - sslcert: (optional) maps to the sslcert connection parameter, which specifies the location of the client certificate.
- sslrootcert: (optional) maps to the sslrootcert connection parameter, which specifies the location of a file containing one or more certificate authorities (CA) certificates that the client will use to verify a server’s certificate.
- sslcrl: (optional) maps to the sslcrl connection parameter, which specifies the location of a file containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- sslcrldir: (optional) maps to the sslcrldir connection parameter, which specifies the location of a directory with files containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- sslnegotiation: (optional) maps to the sslnegotiation connection parameter, which controls how SSL encryption is negotiated with the server, if SSL is used.
- gssencmode: (optional) maps to the gssencmode connection parameter, which determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server
- channel_binding: (optional) maps to the channel_binding connection parameter, which controls the client’s use of channel binding.
- rewind:
- username: (optional) name for the user for
pg_rewind; the user will be created during initialization of postgres 11+ and all necessary permissions will be granted. - password: (optional) password for the user for
pg_rewind; the user will be created during initialization. - sslmode: (optional) maps to the sslmode connection parameter, which allows a client to specify the type of TLS negotiation mode with the server. For more information on how each mode works, please visit the PostgreSQL documentation. The default mode is
prefer. - sslkey: (optional) maps to the sslkey connection parameter, which specifies the location of the secret key used with the client’s certificate.
- sslpassword: (optional) maps to the sslpassword connection parameter, which specifies the password for the secret key specified in
sslkey. - sslcert: (optional) maps to the sslcert connection parameter, which specifies the location of the client certificate.
- sslrootcert: (optional) maps to the sslrootcert connection parameter, which specifies the location of a file containing one or more certificate authorities (CA) certificates that the client will use to verify a server’s certificate.
- sslcrl: (optional) maps to the sslcrl connection parameter, which specifies the location of a file containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- sslcrldir: (optional) maps to the sslcrldir connection parameter, which specifies the location of a directory with files containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- sslnegotiation: (optional) maps to the sslnegotiation connection parameter, which controls how SSL encryption is negotiated with the server, if SSL is used.
- gssencmode: (optional) maps to the gssencmode connection parameter, which determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server
- channel_binding: (optional) maps to the channel_binding connection parameter, which controls the client’s use of channel binding.
- username: (optional) name for the user for
- superuser:
-
callbacks: callback scripts to run on certain actions. Patroni will pass the action, role and cluster name. (See scripts/aws.py as an example of how to write them.)
- on_reload: run this script when configuration reload is triggered.
- on_restart: run this script when the postgres restarts (without changing role).
- on_role_change: run this script when the postgres is being promoted or demoted.
- on_start: run this script when the postgres starts.
- on_stop: run this script when the postgres stops.
-
connect_address: IP address + port through which Postgres is accessible from other nodes and applications.
-
proxy_address: IP address + port through which a connection pool (e.g. pgbouncer) running next to Postgres is accessible. The value is written to the member key in DCS as
proxy_urland could be used/useful for service discovery. -
create_replica_methods: an ordered list of the create methods for turning a Patroni node into a new replica. “basebackup” is the default method; other methods are assumed to refer to scripts, each of which is configured as its own config item. See custom replica creation methods documentation for further explanation.
-
data_dir: The location of the Postgres data directory, either existing or to be initialized by Patroni.
-
config_dir: The location of the Postgres configuration directory, defaults to the data directory. Must be writable by Patroni.
-
bin_dir: (optional) Path to PostgreSQL binaries (pg_ctl, initdb, pg_controldata, pg_basebackup, postgres, pg_isready, pg_rewind). If not provided or is an empty string, PATH environment variable will be used to find the executables.
-
bin_name: (optional) Make it possible to override Postgres binary names, if you are using a custom Postgres distribution:
- pg_ctl: (optional) Custom name for
pg_ctlbinary. - initdb: (optional) Custom name for
initdbbinary. - pgcontroldata: (optional) Custom name for
pg_controldatabinary. - pg_basebackup: (optional) Custom name for
pg_basebackupbinary. - postgres: (optional) Custom name for
postgresbinary. - pg_isready: (optional) Custom name for
pg_isreadybinary. - pg_rewind: (optional) Custom name for
pg_rewindbinary.
- pg_ctl: (optional) Custom name for
-
listen: IP address + port that Postgres listens to; must be accessible from other nodes in the cluster, if you’re using streaming replication. Multiple comma-separated addresses are permitted, as long as the port component is appended after to the last one with a colon, i.e.
listen: 127.0.0.1,127.0.0.2:5432. Patroni will use the first address from this list to establish local connections to the PostgreSQL node. -
use_unix_socket: specifies that Patroni should prefer to use unix sockets to connect to the cluster. Default value is
false. Ifunix_socket_directoriesis defined, Patroni will use the first suitable value from it to connect to the cluster and fallback to tcp if nothing is suitable. Ifunix_socket_directoriesis not specified inpostgresql.parameters, Patroni will assume that the default value should be used and omithostfrom the connection parameters. -
use_unix_socket_repl: specifies that Patroni should prefer to use unix sockets for replication user cluster connection. Default value is
false. Ifunix_socket_directoriesis defined, Patroni will use the first suitable value from it to connect to the cluster and fallback to tcp if nothing is suitable. Ifunix_socket_directoriesis not specified inpostgresql.parameters, Patroni will assume that the default value should be used and omithostfrom the connection parameters. -
pgpass: path to the .pgpass password file. Patroni creates this file before executing pg_basebackup, the post_init script and under some other circumstances. The location must be writable by Patroni.
-
recovery_conf: additional configuration settings written to recovery.conf when configuring follower.
-
custom_conf : path to an optional custom
postgresql.conffile, that will be used in place ofpostgresql.base.conf. The file must exist on all cluster nodes, be readable by PostgreSQL and will be included from its location on the realpostgresql.conf. Note that Patroni will not monitor this file for changes, nor backup it. However, its settings can still be overridden by Patroni’s own configuration facilities - see dynamic configuration for details. -
parameters: configuration parameters (GUCs) for Postgres in format
{ssl: "on", ssl_cert_file: "cert_file"}. -
parameters_primary: (optional) role-specific parameter overrides for primary. These values are merged with and override the base parameters.
-
parameters_replica: (optional) role-specific parameter overrides for replica. These values are merged with and override the base parameters.
-
parameters_standby_leader: (optional) role-specific parameter overrides for standby_leader. These values are merged with and override the base parameters.
-
pg_hba: list of lines that Patroni will use to generate
pg_hba.conf. Patroni ignores this parameter ifhba_filePostgreSQL parameter is set to a non-default value. Together with dynamic configuration this parameter simplifies management ofpg_hba.conf.- - host all all 0.0.0.0/0 md5
- - host replication replicator 127.0.0.1/32 md5: A line like this is required for replication.
-
pg_hba_primary: (optional) role-specific pg_hba entries for primary. These completely replace pg_hba (no merging). If not defined, pg_hba is used.
-
pg_hba_replica: (optional) role-specific pg_hba entries for replica. These completely replace pg_hba (no merging). If not defined, pg_hba is used.
-
pg_hba_standby_leader: (optional) role-specific pg_hba entries for standby_leader. These completely replace pg_hba (no merging). If not defined, pg_hba is used.
-
pg_ident: list of lines that Patroni will use to generate
pg_ident.conf. Patroni ignores this parameter ifident_filePostgreSQL parameter is set to a non-default value. Together with dynamic configuration this parameter simplifies management ofpg_ident.conf.- - mapname1 systemname1 pguser1
- - mapname1 systemname2 pguser2
-
pg_ident_primary: (optional) role-specific pg_ident entries for primary. These completely replace pg_ident (no merging). If not defined, pg_ident is used.
-
pg_ident_replica: (optional) role-specific pg_ident entries for replica. These completely replace pg_ident (no merging). If not defined, pg_ident is used.
-
pg_ident_standby_leader: (optional) role-specific pg_ident entries for standby_leader. These completely replace pg_ident (no merging). If not defined, pg_ident is used.
-
pg_ctl_timeout: How long should pg_ctl wait when doing
start,stoporrestart. Default value is 60 seconds. -
use_pg_rewind: try to use pg_rewind on the former leader when it joins cluster as a replica. Either the cluster must be initialized with
data page checksums(--data-checksumsoption forinitdb) and/orwal_log_hintsmust be set toon, orpg_rewindwill not work. -
rewind: (optional) custom options to pass to the
pg_rewindcommand. Can be specified as a list of strings and/or single key-value dictionaries. Not allowed options include:target-pgdata,source-pgdata,source-server,write-recovery-conf,dry-run,restore-target-wal,config-file,no-ensure-shutdown,version, andhelp. Example usage:YAML -
remove_data_directory_on_rewind_failure: If this option is enabled, Patroni will remove the PostgreSQL data directory and recreate the replica. Otherwise it will try to follow the new leader. Default value is false.
-
remove_data_directory_on_diverged_timelines: Patroni will remove the PostgreSQL data directory and recreate the replica if it notices that timelines are diverging and the former primary can not start streaming from the new primary. This option is useful when
pg_rewindcan not be used. While performing timelines divergence check on PostgreSQL v10 and older Patroni will try to connect with replication credential to the “postgres” database. Hence, such access should be allowed in the pg_hba.conf. Default value is false. -
replica_method: for each create_replica_methods other than basebackup, you would add a configuration section of the same name. At a minimum, this should include “command” with a full path to the actual script to be executed. Other configuration parameters will be passed along to the script in the form “parameter=value”.
-
pre_promote: a fencing script that executes during a failover after acquiring the leader lock but before promoting the replica. If the script exits with a non-zero code, Patroni does not promote the replica and removes the leader key from DCS.
-
before_stop: a script that executes immediately prior to stopping postgres. As opposed to a callback, this script runs synchronously, blocking shutdown until it has completed. The return code of this script does not impact whether shutdown proceeds afterwards.
-
REST API
- restapi:
- thread_pool_size: size of thread pool used by Patroni to process REST API requests. Minimal value is
5, default value is5. - connect_address: IP address (or hostname) and port, to access the Patroni’s REST API. All the members of the cluster must be able to connect to this address, so unless the Patroni setup is intended for a demo inside the localhost, this address must be a non “localhost” or loopback address (ie: “localhost” or “127.0.0.1”). It can serve as an endpoint for HTTP health checks (read below about the “listen” REST API parameter), and also for user queries (either directly or via the REST API), as well as for the health checks done by the cluster members during leader elections (for example, to determine whether the leader is still running, or if there is a node which has a WAL position that is ahead of the one doing the query; etc.) The connect_address is put in the member key in DCS, making it possible to translate the member name into the address to connect to its REST API.
- listen: IP address (or hostname) and port that Patroni will listen to for the REST API - to provide also the same health checks and cluster messaging between the participating nodes, as described above. to provide health-check information for HAProxy (or any other load balancer capable of doing a HTTP “OPTION” or “GET” checks).
- authentication: (optional)
- username: Basic-auth username to protect unsafe REST API endpoints.
- password: Basic-auth password to protect unsafe REST API endpoints.
- certfile: (optional): Specifies the file with the certificate in the PEM format. If the certfile is not specified or is left empty, the API server will work without SSL.
- keyfile: (optional): Specifies the file with the secret key in the PEM format.
- keyfile_password: (optional): Specifies a password for decrypting the keyfile.
- cafile: (optional): Specifies the file with the CA_BUNDLE with certificates of trusted CAs to use while verifying client certs.
- ciphers: (optional): Specifies the permitted cipher suites (e.g. “ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:!SSLv1:!SSLv2:!SSLv3:!TLSv1:!TLSv1.1”)
- verify_client: (optional):
none(default),optionalorrequired. WhennoneREST API will not check client certificates. Whenrequiredclient certificates are required for all REST API calls. Whenoptionalclient certificates are required for all unsafe REST API endpoints. Whenrequiredis used, then client authentication succeeds, if the certificate signature verification succeeds. Foroptionalthe client cert will only be checked forPUT,POST,PATCH, andDELETErequests. - allowlist: (optional): Specifies the set of hosts that are allowed to call unsafe REST API endpoints. The single element could be a host name, an IP address or a network address using CIDR notation. By default
allow allis used. In case ifallowlistorallowlist_include_membersare set, anything that is not included is rejected. - allowlist_include_members: (optional): If set to
trueit allows accessing unsafe REST API endpoints from other cluster members registered in DCS (IP address or hostname is taken from the membersapi_url). Be careful, it might happen that OS will use a different IP for outgoing connections. - http_extra_headers: (optional): HTTP headers let the REST API server pass additional information with an HTTP response.
- https_extra_headers: (optional): HTTPS headers let the REST API server pass additional information with an HTTP response when TLS is enabled. This will also pass additional information set in
http_extra_headers. - request_queue_size: (optional): Sets request queue size for TCP socket used by Patroni REST API. Once the queue is full, further requests get a “Connection denied” error. The default value is 5.
- server_tokens: (optional): Configures the value of the
ServerHTTP header.Minimal: The header will contain only the Patroni version, e.g.Patroni/4.0.0.ProductOnly: The header will contain only the product name, e.g.Patroni.Original(default): The header will expose the original behaviour and display the BaseHTTP and Python versions, e.g.BaseHTTP/0.6 Python/3.12.3.
- thread_pool_size: size of thread pool used by Patroni to process REST API requests. Minimal value is
Here is an example of both http_extra_headers and https_extra_headers:
Warning
- The
restapi.connect_addressmust be accessible from all nodes of a given Patroni cluster. Internally Patroni is using it during the leader race to find nodes with minimal replication lag. - If you enabled client certificates validation (
restapi.verify_clientis set torequired), you also must provide valid client certificates in thectl.certfile,ctl.keyfile,ctl.keyfile_password. If not provided, Patroni will not work correctly.
CTL
- ctl: (optional)
- authentication:
- username: Basic-auth username for accessing protected REST API endpoints. If not provided patronictl will use the value provided for REST API “username” parameter.
- password: Basic-auth password for accessing protected REST API endpoints. If not provided patronictl will use the value provided for REST API “password” parameter.
- insecure: Allow connections to REST API without verifying SSL certs.
- cacert: Specifies the file with the CA_BUNDLE file or directory with certificates of trusted CAs to use while verifying REST API SSL certs. If not provided patronictl will use the value provided for REST API “cafile” parameter.
- certfile: Specifies the file with the client certificate in the PEM format.
- keyfile: Specifies the file with the client secret key in the PEM format.
- keyfile_password: Specifies a password for decrypting the client keyfile.
- authentication:
Watchdog
- mode:
off,automaticorrequired. Whenoffwatchdog is disabled. Whenautomaticwatchdog will be used if available, but ignored if it is not. Whenrequiredthe node will not become a leader unless watchdog can be successfully enabled. - device: Path to watchdog device. Defaults to
/dev/watchdog. - safety_margin: Number of seconds of safety margin between watchdog triggering and leader key expiration.
Tags
- clonefrom:
trueorfalse. If set totrueother nodes might prefer to use this node for bootstrap (takepg_basebackupfrom). If there are several nodes withclonefromtag set totruethe node to bootstrap from will be chosen randomly. The default value isfalse. - noloadbalance:
trueorfalse. If set totruethe node will return HTTP Status Code 503 for theGET /replicaREST API health-check and therefore will be excluded from the load-balancing. Defaults tofalse. - replicatefrom: The name of another replica to replicate from. Used to support cascading replication.
- nosync:
trueorfalse. If set totruethe node will never be selected as a synchronous replica. - sync_priority: integer, controls the priority this node should have during synchronous replica selection when synchronous_mode is set to
on. Nodes with higher priority will be preferred over lower-priority nodes. If thesync_priorityis 0 or negative - such node is not allowed to be written tosynchronous_standby_namesPostgreSQL parameter (similar tonosync: true). Keep in mind, that this parameter has the opposite meaning tosync_priorityvalue reported inpg_stat_replicationview. - nofailover:
trueorfalse, controls whether this node is allowed to participate in the leader race and become a leader. Defaults tofalse, meaning this node can_ participate in leader races. - failover_priority: integer, controls the priority this node should have during failover. Nodes with higher priority will be preferred over lower-priority nodes if they received/replayed the same amount of WAL. However, nodes with higher values of receive/replay LSN are preferred regardless of their priority. If the
failover_priorityis 0 or negative - such node is not allowed to participate in the leader race and to become a leader (similar tonofailover: true). Known limitation:failover_prioritycurrently doesn’t work with quorum-based synchronous replication. - nostream:
trueorfalse. If set totruethe node will not use replication protocol to stream WAL. It will rely instead on archive recovery (ifrestore_commandis configured) andpg_wal/pg_xlogpolling. It also disables copying and synchronization of permanent logical replication slots on the node itself and all its cascading replicas. Setting this tag on primary node has no effect.
Provide only one of nofailover or failover_priority. Providing nofailover: true is the same as failover_priority: 0, and providing nofailover: false will give the node priority 1.
In addition to these predefined tags, you can also add your own ones:
- key1:
true - key2:
false - key3:
1.4 - key4:
"RandomString"
Tags are visible in the REST API and patronictl_list You can also check for an instance health using these tags. If the tag isn’t defined for an instance, or if the respective value doesn’t match the querying value, it will return HTTP Status Code 503.
3 - Environment Configuration Settings
Source: https://patroni.readthedocs.io/en/latest/ENVIRONMENT.html
It is possible to override some of the configuration parameters defined in the Patroni configuration file using the system environment variables. This document lists all environment variables handled by Patroni. The values set via those variables always take precedence over the ones set in the Patroni configuration file.
Global/Universal
- PATRONI_CONFIGURATION: it is possible to set the entire configuration for the Patroni via PATRONI_CONFIGURATION environment variable. In this case any other environment variables will not be considered!
- PATRONI_THREAD_POOL_SIZE: size of thread pool used by Patroni to execute asynchronous tasks and communicate via REST API with other members during leader race or failsafe checks. Minimal value is
5, default value is5. - PATRONI_THREAD_STACK_SIZE: specifies the stack size to be used for threads started by Patroni. Value must be aligned by
64kB. Minimal value is64kB, default value (set by Patroni) is512kB. - PATRONI_NAME: name of the node where the current instance of Patroni is running. Must be unique for the cluster. The value
__patroni_strict_sync_replica_placeholder__is reserved for internal use by Patroni and cannot be used as a node name. - PATRONI_NAMESPACE: path within the configuration store where Patroni will keep information about the cluster. Default value: “/service”
- PATRONI_SCOPE: cluster name
- PG_MALLOC_ARENA_MAX: custom value for
MALLOC_ARENA_MAXenvironment variable forpostmasterprocess. If not set,postmasterwill inheritMALLOC_ARENA_MAXvalue.
Log
- PATRONI_LOG_TYPE: sets the format of logs. Can be either plain or json. To use json format, you must have the jsonlogger installed. The default value is plain.
- PATRONI_LOG_LEVEL: sets the general logging level. Default value is INFO (see the docs for Python logging)
- PATRONI_LOG_TRACEBACK_LEVEL: sets the level where tracebacks will be visible. Default value is ERROR. Set it to DEBUG if you want to see tracebacks only if you enable PATRONI_LOG_LEVEL=DEBUG.
- PATRONI_LOG_FORMAT: sets the log formatting string. If the log type is plain, the log format should be a string. Refer to the LogRecord attributes for available attributes. If the log type is json, the log format can be a list in addition to a string. Each list item should correspond to LogRecord attributes. Be cautious that only the field name is required, and the %( and ) should be omitted. If you wish to print a log field with a different key name, use a dictionary where the dictionary key is the log field, and the value is the name of the field you want to be printed in the log. Default value is %(asctime)s %(levelname)s: %(message)s
- PATRONI_LOG_DATEFORMAT: sets the datetime formatting string. (see the formatTime() documentation)
- PATRONI_LOG_STATIC_FIELDS: add additional fields to the log. This option is only available when the log type is set to json. Example
PATRONI_LOG_STATIC_FIELDS="{app: patroni}" - PATRONI_LOG_MAX_QUEUE_SIZE: Patroni is using two-step logging. Log records are written into the in-memory queue and there is a separate thread which pulls them from the queue and writes to stderr or file. The maximum size of the internal queue is limited by default by 1000 records, which is enough to keep logs for the past 1h20m.
- PATRONI_LOG_DIR: Directory to write application logs to. The directory must exist and be writable by the user executing Patroni. If you set this env variable, the application will retain 4 25MB logs by default. You can tune those retention values with
PATRONI_LOG_FILE_NUMandPATRONI_LOG_FILE_SIZE(see below). - PATRONI_LOG_MODE: Permissions for log files (for example,
0644). If not specified, permissions will be set based on the current umask value. - PATRONI_LOG_FILE_NUM: The number of application logs to retain.
- PATRONI_LOG_FILE_SIZE: Size of patroni.log file (in bytes) that triggers a log rolling.
- PATRONI_LOG_LOGGERS: Redefine logging level per python module. Example
PATRONI_LOG_LOGGERS="{patroni.postmaster: WARNING, urllib3: DEBUG}" - PATRONI_LOG_DEDUPLICATE_HEARTBEAT_LOGS: If set to
true, successive heartbeat logs that are identical shall not be output. Default value isfalse.
The time the HA loop executes at can be very valuable information in diagnosing failovers due to resource exhaustion and similar problems. When PATRONI_LOG_DEDUPLICATE_HEARTBEAT_LOGS is set to true there will be no log generated for the HA loop execution (unless the leader changes) and hence this potentially useful information will not be available from the logs.
Citus
Enables integration Patroni with Citus. If configured, Patroni will take care of registering Citus worker nodes on the coordinator. You can find more information about Citus support here.
- PATRONI_CITUS_GROUP: the Citus group id, integer. Use
0for coordinator and1,2, etc… for workers - PATRONI_CITUS_DATABASE: the database where citus extension should be created. Must be the same on the coordinator and all workers. Currently only one database is supported.
Consul
- PATRONI_CONSUL_HOST: the host:port for the Consul local agent.
- PATRONI_CONSUL_URL: url for the Consul local agent, in format: http(s)://host:port
- PATRONI_CONSUL_PORT: (optional) Consul port
- PATRONI_CONSUL_SCHEME: (optional) http or https, defaults to http
- PATRONI_CONSUL_TOKEN: (optional) ACL token
- PATRONI_CONSUL_VERIFY: (optional) whether to verify the SSL certificate for HTTPS requests
- PATRONI_CONSUL_CACERT: (optional) The ca certificate. If present it will enable validation.
- PATRONI_CONSUL_CERT: (optional) File with the client certificate
- PATRONI_CONSUL_KEY: (optional) File with the client key. Can be empty if the key is part of certificate.
- PATRONI_CONSUL_DC: (optional) Datacenter to communicate with. By default the datacenter of the host is used.
- PATRONI_CONSUL_CONSISTENCY: (optional) Select consul consistency mode. Possible values are
default,consistent, orstale(more details in consul API reference) - PATRONI_CONSUL_CHECKS: (optional) list of Consul health checks used for the session. By default an empty list is used.
- PATRONI_CONSUL_REGISTER_SERVICE: (optional) whether or not to register a service with the name defined by the scope parameter and the tag master, primary, replica, or standby-leader depending on the node’s role. Defaults to false
- PATRONI_CONSUL_SERVICE_TAGS: (optional) additional static tags to add to the Consul service apart from the role (
primary/replica/standby-leader). By default an empty list is used. - PATRONI_CONSUL_SERVICE_CHECK_INTERVAL: (optional) how often to perform health check against registered url
- PATRONI_CONSUL_SERVICE_CHECK_TLS_SERVER_NAME: (optional) override SNI host when connecting via TLS, see also consul agent check API reference.
Etcd
- PATRONI_ETCD_PROXY: proxy url for the etcd. If you are connecting to the etcd using proxy, use this parameter instead of PATRONI_ETCD_URL
- PATRONI_ETCD_URL: url for the etcd, in format: http(s)://(username:password@)host:port
- PATRONI_ETCD_HOSTS: list of etcd endpoints in format ‘host1:port1’,‘host2:port2’,etc…
- PATRONI_ETCD_USE_PROXIES: If this parameter is set to true, Patroni will consider hosts as a list of proxies and will not perform a topology discovery of etcd cluster but stick to a fixed list of hosts.
- PATRONI_ETCD_PROTOCOL: http or https, if not specified http is used. If the url or proxy is specified - will take protocol from them.
- PATRONI_ETCD_HOST: the host:port for the etcd endpoint.
- PATRONI_ETCD_SRV: Domain to search the SRV record(s) for cluster autodiscovery. Patroni will try to query these SRV service names for specified domain (in that order until first success):
_etcd-client-ssl,_etcd-client,_etcd-ssl,_etcd,_etcd-server-ssl,_etcd-server. If SRV records for_etcd-server-sslor_etcd-serverare retrieved then ETCD peer protocol is used do query ETCD for available members. Otherwise hosts from SRV records will be used. - PATRONI_ETCD_SRV_SUFFIX: Configures a suffix to the SRV name that is queried during discovery. Use this flag to differentiate between multiple etcd clusters under the same domain. Works only with conjunction with PATRONI_ETCD_SRV. For example, if
PATRONI_ETCD_SRV_SUFFIX=fooandPATRONI_ETCD_SRV=example.orgare set, the following DNS SRV query is made:_etcd-client-ssl-foo._tcp.example.com(and so on for every possible ETCD SRV service name). - PATRONI_ETCD_USERNAME: username for etcd authentication.
- PATRONI_ETCD_PASSWORD: password for etcd authentication.
- PATRONI_ETCD_CACERT: The ca certificate. If present it will enable validation.
- PATRONI_ETCD_CERT: File with the client certificate.
- PATRONI_ETCD_KEY: File with the client key. Can be empty if the key is part of certificate.
Etcdv3
Environment names for Etcdv3 are similar as for Etcd, you just need to use ETCD3 instead of ETCD in the variable name. Example: PATRONI_ETCD3_HOST, PATRONI_ETCD3_CACERT, and so on.
Keys created with protocol version 2 are not visible with protocol version 3 and the other way around, therefore it is not possible to switch from Etcd to Etcdv3 just by updating Patroni configuration. In addition, Patroni uses Etcd’s gRPC-gateway (proxy) to communicate with the V3 API, which means that TLS common name authentication is not possible.
ZooKeeper
- PATRONI_ZOOKEEPER_HOSTS: Comma separated list of ZooKeeper cluster members: “‘host1:port1’,‘host2:port2’,’etc…’”. It is important to quote every single entity!
- PATRONI_ZOOKEEPER_USE_SSL: (optional) Whether SSL is used or not. Defaults to
false. If set tofalse, all SSL specific parameters are ignored. - PATRONI_ZOOKEEPER_CACERT: (optional) The CA certificate. If present it will enable validation.
- PATRONI_ZOOKEEPER_CERT: (optional) File with the client certificate.
- PATRONI_ZOOKEEPER_KEY: (optional) File with the client key.
- PATRONI_ZOOKEEPER_KEY_PASSWORD: (optional) The client key password.
- PATRONI_ZOOKEEPER_VERIFY: (optional) Whether to verify certificate or not. Defaults to
true. - PATRONI_ZOOKEEPER_SET_ACLS: (optional) If set, configures Kazoo to apply a default ACL to each ZNode that it creates. ACLs can use either the
x509schema (default) or other supported ZooKeeper schemes such asdigest. They should be specified as a dictionary where the key is the full principal (optionally prefixed with the scheme) and the value is a list of permissions. Permissions may be one or more ofCREATE,READ,WRITE,DELETE,ADMIN, orALL. For example,set_acls: {CN=principal1: [CREATE, READ], digest:principal2:+pjROuBuuwNNSujKyH8dGcEnFPQ=: [ALL]}. - PATRONI_ZOOKEEPER_AUTH_DATA: (optional) Authentication credentials to use for the connection. Should be a dictionary in the form that
schemeis the key andcredentialis the value. Defaults to empty dictionary.
It is required to install kazoo>=2.6.0 to support SSL.
Exhibitor
- PATRONI_EXHIBITOR_HOSTS: initial list of Exhibitor (ZooKeeper) nodes in format: ‘host1,host2,etc…’. This list updates automatically whenever the Exhibitor (ZooKeeper) cluster topology changes.
- PATRONI_EXHIBITOR_PORT: Exhibitor port.
Kubernetes
- PATRONI_KUBERNETES_BYPASS_API_SERVICE: (optional) When communicating with the Kubernetes API, Patroni is usually relying on the kubernetes service, the address of which is exposed in the pods via the
KUBERNETES_SERVICE_HOSTenvironment variable. IfPATRONI_KUBERNETES_BYPASS_API_SERVICEis set totrue, Patroni will resolve the list of API nodes behind the service and connect directly to them. - PATRONI_KUBERNETES_NAMESPACE: (optional) Kubernetes namespace where the Patroni pod is running. Default value is
default. - PATRONI_KUBERNETES_LABELS: Labels in format
{label1: value1, label2: value2}. These labels will be used to find existing objects (Pods and either Endpoints or ConfigMaps) associated with the current cluster. Also Patroni will set them on every object (Endpoint or ConfigMap) it creates. - PATRONI_KUBERNETES_SCOPE_LABEL: (optional) name of the label containing cluster name. Default value is
cluster-name. - PATRONI_KUBERNETES_BOOTSTRAP_LABELS: (optional) Labels in format
{label1: value1, label2: value2}. These labels will be assigned to a Patroni pod when its state is eitherinitializing new cluster,running custom bootstrap script,starting after custom bootstraporcreating replica. - PATRONI_KUBERNETES_ROLE_LABEL: (optional) name of the label containing role (
primary,replicaor other custom value). Patroni will set this label on the pod it runs in. Default value isrole. - PATRONI_KUBERNETES_LEADER_LABEL_VALUE: (optional) value of the pod label when Postgres role is
primary. Default value isprimary. - PATRONI_KUBERNETES_FOLLOWER_LABEL_VALUE: (optional) value of the pod label when Postgres role is
replica. Default value isreplica. - PATRONI_KUBERNETES_STANDBY_LEADER_LABEL_VALUE: (optional) value of the pod label when Postgres role is
standby_leader. Default value isprimary. - PATRONI_KUBERNETES_TMP_ROLE_LABEL: (optional) name of the temporary label containing role (
primaryorreplica). Value of this label will always use the default of corresponding role. Set only when necessary. - PATRONI_KUBERNETES_USE_ENDPOINTS: (optional) if set to true, Patroni will use Endpoints instead of ConfigMaps to run leader elections and keep cluster state.
- PATRONI_KUBERNETES_POD_IP: (optional) IP address of the pod Patroni is running in. This value is required when
PATRONI_KUBERNETES_USE_ENDPOINTSis enabled and is used to populate the leader endpoint subsets when the pod’s PostgreSQL is promoted. - PATRONI_KUBERNETES_PORTS: (optional) if the Service object has the name for the port, the same name must appear in the Endpoint object, otherwise service won’t work. For example, if your service is defined as
{Kind: Service, spec: {ports: [{name: postgresql, port: 5432, targetPort: 5432}]}}, then you have to setPATRONI_KUBERNETES_PORTS='[{"name": "postgresql", "port": 5432}]'and Patroni will use it for updating subsets of the leader Endpoint. This parameter is used only ifPATRONI_KUBERNETES_USE_ENDPOINTSis set. - PATRONI_KUBERNETES_CACERT: (optional) Specifies the file with the CA_BUNDLE file with certificates of trusted CAs to use while verifying Kubernetes API SSL certs. If not provided, patroni will use the value provided by the ServiceAccount secret.
- PATRONI_RETRIABLE_HTTP_CODES: (optional) list of HTTP status codes from K8s API to retry on. By default Patroni is retrying on
500,503, and504, or if K8s API response hasretry-afterHTTP header.
Raft (deprecated)
- PATRONI_RAFT_SELF_ADDR:
ip:portto listen on for Raft connections. Theself_addrmust be accessible from other nodes of the cluster. If not set, the node will not participate in consensus. - PATRONI_RAFT_BIND_ADDR: (optional)
ip:portto listen on for Raft connections. If not specified theself_addrwill be used. - PATRONI_RAFT_PARTNER_ADDRS: list of other Patroni nodes in the cluster in format
"'ip1:port1','ip2:port2'". It is important to quote every single entity! - PATRONI_RAFT_DATA_DIR: directory where to store Raft log and snapshot. If not specified the current working directory is used.
- PATRONI_RAFT_PASSWORD: (optional) Encrypt Raft traffic with a specified password, requires
cryptographypython module. - PATRONI_RAFT_MIN_TIMEOUT: (optional) minimum election timeout in seconds for the underlying pysyncobj Raft implementation. Must be greater than 3 *
PATRONI_RAFT_APPEND_ENTRIES_PERIOD. Default:0.4. - PATRONI_RAFT_MAX_TIMEOUT: (optional) maximum election timeout in seconds for the underlying pysyncobj Raft implementation. Must be greater than
PATRONI_RAFT_MIN_TIMEOUT. Default:1.4. - PATRONI_RAFT_CONNECTION_TIMEOUT: (optional) time in seconds after which a connection with no data received is considered dead. Must be greater than or equal to
PATRONI_RAFT_MAX_TIMEOUT. Default:3.5. - PATRONI_RAFT_APPEND_ENTRIES_PERIOD: (optional) interval in seconds for sending heartbeat commands. Must be less than one-third of
PATRONI_RAFT_MIN_TIMEOUT. Default:0.1. - PATRONI_RAFT_CONNECTION_RETRY_TIME: (optional) interval in seconds between reconnection attempts to offline nodes. Default:
5.0. - PATRONI_RAFT_LEADER_FALLBACK_TIMEOUT: (optional) time in seconds after which a leader with no response from the majority falls back to follower state. Must be greater than
PATRONI_RAFT_APPEND_ENTRIES_PERIOD. Default:30.0.
Patroni validates these constraints at startup and will refuse to start if they are violated. These values cannot be changed at runtime and require a restart. See Raft settings for details, including the high-latency limitation.
PostgreSQL
- PATRONI_POSTGRESQL_LISTEN: IP address + port that Postgres listens to. Multiple comma-separated addresses are permitted, as long as the port component is appended after to the last one with a colon, i.e.
listen: 127.0.0.1,127.0.0.2:5432. Patroni will use the first address from this list to establish local connections to the PostgreSQL node. - PATRONI_POSTGRESQL_CONNECT_ADDRESS: IP address + port through which Postgres is accessible from other nodes and applications.
- PATRONI_POSTGRESQL_PROXY_ADDRESS: IP address + port through which a connection pool (e.g. pgbouncer) running next to Postgres is accessible. The value is written to the member key in DCS as
proxy_urland could be used/useful for service discovery. - PATRONI_POSTGRESQL_DATA_DIR: The location of the Postgres data directory, either existing or to be initialized by Patroni.
- PATRONI_POSTGRESQL_CONFIG_DIR: The location of the Postgres configuration directory, defaults to the data directory. Must be writable by Patroni.
- PATRONI_POSTGRESQL_BIN_DIR: Path to PostgreSQL binaries. (pg_ctl, initdb, pg_controldata, pg_basebackup, postgres, pg_isready, pg_rewind) The default value is an empty string meaning that PATH environment variable will be used to find the executables.
- PATRONI_POSTGRESQL_BIN_PG_CTL: (optional) Custom name for
pg_ctlbinary. - PATRONI_POSTGRESQL_BIN_INITDB: (optional) Custom name for
initdbbinary. - PATRONI_POSTGRESQL_BIN_PG_CONTROLDATA: (optional) Custom name for
pg_controldatabinary. - PATRONI_POSTGRESQL_BIN_PG_BASEBACKUP: (optional) Custom name for
pg_basebackupbinary. - PATRONI_POSTGRESQL_BIN_POSTGRES: (optional) Custom name for
postgresbinary. - PATRONI_POSTGRESQL_BIN_IS_READY: (optional) Custom name for
pg_isreadybinary. - PATRONI_POSTGRESQL_BIN_PG_REWIND: (optional) Custom name for
pg_rewindbinary. - PATRONI_POSTGRESQL_PGPASS: path to the .pgpass password file. Patroni creates this file before executing pg_basebackup and under some other circumstances. The location must be writable by Patroni.
- PATRONI_REPLICATION_USERNAME: replication username; the user will be created during initialization. Replicas will use this user to access the replication source via streaming replication
- PATRONI_REPLICATION_PASSWORD: replication password; the user will be created during initialization.
- PATRONI_REPLICATION_SSLMODE: (optional) maps to the sslmode connection parameter, which allows a client to specify the type of TLS negotiation mode with the server. For more information on how each mode works, please visit the PostgreSQL documentation. The default mode is
prefer. - PATRONI_REPLICATION_SSLKEY: (optional) maps to the sslkey connection parameter, which specifies the location of the secret key used with the client’s certificate.
- PATRONI_REPLICATION_SSLPASSWORD: (optional) maps to the sslpassword connection parameter, which specifies the password for the secret key specified in
PATRONI_REPLICATION_SSLKEY. - PATRONI_REPLICATION_SSLCERT: (optional) maps to the sslcert connection parameter, which specifies the location of the client certificate.
- PATRONI_REPLICATION_SSLROOTCERT: (optional) maps to the sslrootcert connection parameter, which specifies the location of a file containing one or more certificate authorities (CA) certificates that the client will use to verify a server’s certificate.
- PATRONI_REPLICATION_SSLCRL: (optional) maps to the sslcrl connection parameter, which specifies the location of a file containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- PATRONI_REPLICATION_SSLCRLDIR: (optional) maps to the sslcrldir connection parameter, which specifies the location of a directory with files containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- PATRONI_REPLICATION_SSLNEGOTIATION: (optional) maps to the sslnegotiation connection parameter, which controls how SSL encryption is negotiated with the server, if SSL is used.
- PATRONI_REPLICATION_GSSENCMODE: (optional) maps to the gssencmode connection parameter, which determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server
- PATRONI_REPLICATION_CHANNEL_BINDING: (optional) maps to the channel_binding connection parameter, which controls the client’s use of channel binding.
- PATRONI_SUPERUSER_USERNAME: name for the superuser, set during initialization (initdb) and later used by Patroni to connect to the postgres. Also this user is used by pg_rewind.
- PATRONI_SUPERUSER_PASSWORD: password for the superuser, set during initialization (initdb).
- PATRONI_SUPERUSER_SSLMODE: (optional) maps to the sslmode connection parameter, which allows a client to specify the type of TLS negotiation mode with the server. For more information on how each mode works, please visit the PostgreSQL documentation. The default mode is
prefer. - PATRONI_SUPERUSER_SSLKEY: (optional) maps to the sslkey connection parameter, which specifies the location of the secret key used with the client’s certificate.
- PATRONI_SUPERUSER_SSLPASSWORD: (optional) maps to the sslpassword connection parameter, which specifies the password for the secret key specified in
PATRONI_SUPERUSER_SSLKEY. - PATRONI_SUPERUSER_SSLCERT: (optional) maps to the sslcert connection parameter, which specifies the location of the client certificate.
- PATRONI_SUPERUSER_SSLROOTCERT: (optional) maps to the sslrootcert connection parameter, which specifies the location of a file containing one or more certificate authorities (CA) certificates that the client will use to verify a server’s certificate.
- PATRONI_SUPERUSER_SSLCRL: (optional) maps to the sslcrl connection parameter, which specifies the location of a file containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- PATRONI_SUPERUSER_SSLCRLDIR: (optional) maps to the sslcrldir connection parameter, which specifies the location of a directory with files containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- PATRONI_SUPERUSER_SSLNEGOTIATION: (optional) maps to the sslnegotiation connection parameter, which controls how SSL encryption is negotiated with the server, if SSL is used.
- PATRONI_SUPERUSER_GSSENCMODE: (optional) maps to the gssencmode connection parameter, which determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server
- PATRONI_SUPERUSER_CHANNEL_BINDING: (optional) maps to the channel_binding connection parameter, which controls the client’s use of channel binding.
- PATRONI_REWIND_USERNAME: (optional) name for the user for
pg_rewind; the user will be created during initialization of postgres 11+ and all necessary permissions will be granted. - PATRONI_REWIND_PASSWORD: (optional) password for the user for
pg_rewind; the user will be created during initialization. - PATRONI_REWIND_SSLMODE: (optional) maps to the sslmode connection parameter, which allows a client to specify the type of TLS negotiation mode with the server. For more information on how each mode works, please visit the PostgreSQL documentation. The default mode is
prefer. - PATRONI_REWIND_SSLKEY: (optional) maps to the sslkey connection parameter, which specifies the location of the secret key used with the client’s certificate.
- PATRONI_REWIND_SSLPASSWORD: (optional) maps to the sslpassword connection parameter, which specifies the password for the secret key specified in
PATRONI_REWIND_SSLKEY. - PATRONI_REWIND_SSLCERT: (optional) maps to the sslcert connection parameter, which specifies the location of the client certificate.
- PATRONI_REWIND_SSLROOTCERT: (optional) maps to the sslrootcert connection parameter, which specifies the location of a file containing one or more certificate authorities (CA) certificates that the client will use to verify a server’s certificate.
- PATRONI_REWIND_SSLCRL: (optional) maps to the sslcrl connection parameter, which specifies the location of a file containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- PATRONI_REWIND_SSLCRLDIR: (optional) maps to the sslcrldir connection parameter, which specifies the location of a directory with files containing a certificate revocation list. A client will reject connecting to any server that has a certificate present in this list.
- PATRONI_REWIND_SSLNEGOTIATION: (optional) maps to the sslnegotiation connection parameter, which controls how SSL encryption is negotiated with the server, if SSL is used.
- PATRONI_REWIND_GSSENCMODE: (optional) maps to the gssencmode connection parameter, which determines whether or with what priority a secure GSS TCP/IP connection will be negotiated with the server
- PATRONI_REWIND_CHANNEL_BINDING: (optional) maps to the channel_binding connection parameter, which controls the client’s use of channel binding.
REST API
- PATRONI_RESTAPI_THREAD_POOL_SIZE: size of thread pool used by Patroni to process REST API requests. Minimal value is
5, default value is5. - PATRONI_RESTAPI_CONNECT_ADDRESS: IP address and port to access the REST API.
- PATRONI_RESTAPI_LISTEN: IP address and port that Patroni will listen to, to provide health-check information for HAProxy.
- PATRONI_RESTAPI_USERNAME: Basic-auth username to protect unsafe REST API endpoints.
- PATRONI_RESTAPI_PASSWORD: Basic-auth password to protect unsafe REST API endpoints.
- PATRONI_RESTAPI_CERTFILE: Specifies the file with the certificate in the PEM format. If the certfile is not specified or is left empty, the API server will work without SSL.
- PATRONI_RESTAPI_KEYFILE: Specifies the file with the secret key in the PEM format.
- PATRONI_RESTAPI_KEYFILE_PASSWORD: Specifies a password for decrypting the keyfile.
- PATRONI_RESTAPI_CAFILE: Specifies the file with the CA_BUNDLE with certificates of trusted CAs to use while verifying client certs.
- PATRONI_RESTAPI_CIPHERS: (optional) Specifies the permitted cipher suites (e.g. “ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:!SSLv1:!SSLv2:!SSLv3:!TLSv1:!TLSv1.1”)
- PATRONI_RESTAPI_VERIFY_CLIENT:
none(default),optionalorrequired. WhennoneREST API will not check client certificates. Whenrequiredclient certificates are required for all REST API calls. Whenoptionalclient certificates are required for all unsafe REST API endpoints. Whenrequiredis used, then client authentication succeeds, if the certificate signature verification succeeds. Foroptionalthe client cert will only be checked forPUT,POST,PATCH, andDELETErequests. - PATRONI_RESTAPI_ALLOWLIST: (optional): Specifies the set of hosts that are allowed to call unsafe REST API endpoints. The single element could be a host name, an IP address or a network address using CIDR notation. By default
allow allis used. In case ifallowlistorallowlist_include_membersare set, anything that is not included is rejected. - PATRONI_RESTAPI_ALLOWLIST_INCLUDE_MEMBERS: (optional): If set to
trueit allows accessing unsafe REST API endpoints from other cluster members registered in DCS (IP address or hostname is taken from the membersapi_url). Be careful, it might happen that OS will use a different IP for outgoing connections. - PATRONI_RESTAPI_HTTP_EXTRA_HEADERS: (optional) HTTP headers let the REST API server pass additional information with an HTTP response.
- PATRONI_RESTAPI_HTTPS_EXTRA_HEADERS: (optional) HTTPS headers let the REST API server pass additional information with an HTTP response when TLS is enabled. This will also pass additional information set in
http_extra_headers. - PATRONI_RESTAPI_REQUEST_QUEUE_SIZE: (optional): Sets request queue size for TCP socket used by Patroni REST API. Once the queue is full, further requests get a “Connection denied” error. The default value is 5.
- PATRONI_RESTAPI_SERVER_TOKENS: (optional) Configures the value of the
ServerHTTP header.Original(default) will expose the original behaviour and display the BaseHTTP and Python versions, e.g.BaseHTTP/0.6 Python/3.12.3.Minimal: The header will contain only the Patroni version, e.g.Patroni/4.0.0.ProductOnly: The header will contain only the product name, e.g.Patroni.
Warning
- The
PATRONI_RESTAPI_CONNECT_ADDRESSmust be accessible from all nodes of a given Patroni cluster. Internally Patroni is using it during the leader race to find nodes with minimal replication lag. - If you enabled client certificates validation (
PATRONI_RESTAPI_VERIFY_CLIENTis set torequired), you also must provide valid client certificates in thePATRONI_CTL_CERTFILE,PATRONI_CTL_KEYFILE,PATRONI_CTL_KEYFILE_PASSWORD. If not provided, Patroni will not work correctly.
CTL
- PATRONICTL_CONFIG_FILE: (optional) location of the configuration file.
- PATRONI_CTL_USERNAME: (optional) Basic-auth username for accessing protected REST API endpoints. If not provided patronictl will use the value provided for REST API “username” parameter.
- PATRONI_CTL_PASSWORD: (optional) Basic-auth password for accessing protected REST API endpoints. If not provided patronictl will use the value provided for REST API “password” parameter.
- PATRONI_CTL_INSECURE: (optional) Allow connections to REST API without verifying SSL certs.
- PATRONI_CTL_CACERT: (optional) Specifies the file with the CA_BUNDLE file or directory with certificates of trusted CAs to use while verifying REST API SSL certs. If not provided patronictl will use the value provided for REST API “cafile” parameter.
- PATRONI_CTL_CERTFILE: (optional) Specifies the file with the client certificate in the PEM format.
- PATRONI_CTL_KEYFILE: (optional) Specifies the file with the client secret key in the PEM format.
- PATRONI_CTL_KEYFILE_PASSWORD: (optional) Specifies a password for decrypting the client keyfile.