patroni
--generate-config
machinery.
- class patroni.config_generator. AbstractConfigGenerator ( output_file : str | None ) View on GitHub
-
Bases:
ABCObject representing the generated Patroni config.
- Variables :
-
-
output_file – full path to the output file to be used.
-
pg_major – integer representation of the major PostgreSQL version.
-
config – dictionary used for the generated configuration storage.
-
- __init__ ( output_file : str | None ) None View on GitHub
-
Set up the output file (if passed), helper vars and the minimal config structure.
- Parameters :
-
output_file – full path to the output file to be used.
- _abc_impl = <_abc._abc_data object>
- static _format_block ( block : Any , line_prefix : str = '' ) str View on GitHub
-
Format a single YAML block.
Note
Optionally the formatted block could be indented with the line_prefix
- Parameters :
-
-
block – the object that should be formatted to YAML.
-
line_prefix – is used for indentation.
-
- Returns :
-
a formatted and indented block .
- _format_config ( ) Iterator [ str ] View on GitHub
-
Format current
configand enrich it with some comments.- Yields :
-
formatted lines or blocks that represent a text output of the YAML document.
- _format_config_section ( section_name : str ) Iterator [ str ] View on GitHub
-
Format and yield as single section of the current
config.Note
If the section is a
dictobject we put an empty line before it.- Parameters :
-
section_name – a section name in the
config. - Yields :
-
a formatted section in case if it exists in the
config.
- _write_config_to_fd ( fd : TextIO ) None View on GitHub
-
Format and write current
configto provided file descriptor.- Parameters :
-
fd – where to write the config file. Could be
sys.stdoutor the real file.
- abstract generate ( ) None View on GitHub
-
Generate config and store in
config.
- classmethod get_template_config ( ) Dict [ str , Any ] View on GitHub
-
Generate a template config for further extension (e.g. in the inherited classes).
- Returns :
-
dictionary with the values gathered from Patroni env, hopefully defined hostname and ip address (otherwise set to
NO_VALUE_MSG), and some sane defaults.
- write_config ( ) None View on GitHub
-
Write current
configto the output file if provided, to stdout otherwise.
- class patroni.config_generator. RunningClusterConfigGenerator ( output_file : str | None = None , dsn : str | None = None ) View on GitHub
-
Bases:
AbstractConfigGeneratorObject representing the Patroni config generated using information gathered from the running instance.
- Variables :
-
-
dsn – DSN string for the local instance to get GUC values from (if provided).
-
parsed_dsn – DSN string parsed into a dictionary (see
parse_dsn()).
-
- __init__ ( output_file : str | None = None , dsn : str | None = None ) None View on GitHub
-
Additionally store the passed dsn (if any) in both original and parsed version and run config generation.
- Parameters :
-
-
output_file – full path to the output file to be used.
-
dsn – DSN string for the local instance to get GUC values from.
-
- Raises :
-
PatroniException: if DSN parsing failed.
- _abc_impl = <_abc._abc_data object>
- _enrich_config_from_running_instance ( ) None View on GitHub
-
Extend
configwith the values gathered from the running instance.Retrieve the following information from the running PostgreSQL instance:
-
superuser auth parameters (see
_set_su_params()); -
some GUC values (see
_set_pg_params()); -
postgresql.connect_address,postgresql.listen; -
postgresql.pg_hbaandpostgresql.pg_ident(see_set_conf_files())
And redefine
scopewith thecluster_nameGUC value if set.- Raises :
-
PatroniException: if the provided user doesn’t have superuser privileges.
-
- _get_bin_dir_from_running_instance ( ) str View on GitHub
-
Define the directory postgres binaries reside using postmaster’s pid executable.
- Returns :
-
path to the PostgreSQL binaries directory.
- Raises :
-
PatroniException: if:-
pid could not be obtained from the
postmaster.pidfile; or -
OSErroroccurred duringpostmaster.pidfile handling; or -
the obtained postmaster pid doesn’t exist.
-
- _get_connection_cursor ( ) Iterator [ cursor | Cursor [ Any ] ] View on GitHub
-
Get cursor for the PG connection established based on the stored information.
- Raises :
-
PatroniException: ifpsycopg.Erroroccurred.
- property _get_hba_conn_types : Tuple [ str , ... ] View on GitHub
-
Return the connection types allowed.
If
pg_majoris defined, adds additional parameters for PostgreSQL version >=16.- Returns :
-
tuple of the connection methods allowed.
- property _required_pg_params : List [ str ] View on GitHub
-
PG configuration parameters that have to be always present in the generated config.
- Returns :
-
list of the parameter names.
- _set_conf_files ( ) None View on GitHub
-
Extend
configwithpg_hba.confandpg_ident.confcontent.Note
This function only defines
postgresql.pg_hbaandpostgresql.pg_identwhenhba_fileandident_fileare set to the defaults. It may happen these files are located outside ofPGDATAand Patroni doesn’t have write permissions for them.- Raises :
-
PatroniException: ifOSErroroccurred during the conf files handling.
- _set_pg_params ( cur : cursor | Cursor [ Any ] ) None View on GitHub
-
Extend
configwith the actual PG GUCs values.THe following GUC values are set:
-
Non-internal having configuration file, postmaster command line or environment variable as a source.
-
List of the always required parameters (see
_required_pg_params()).
- Parameters :
-
cur – connection cursor to use.
-
- _set_su_params ( ) None View on GitHub
-
Extend
configwith the superuser auth information.Information set is based on the options used for connection.
- generate ( ) None View on GitHub
-
Generate config using the info gathered from the specified running PG instance.
Result is written to
config.
- class patroni.config_generator. SampleConfigGenerator ( output_file : str | None ) View on GitHub
-
Bases:
AbstractConfigGeneratorObject representing the generated sample Patroni config.
Sane defaults are used based on the gathered PG version.
- _abc_impl = <_abc._abc_data object>
- _get_int_major_version ( ) int View on GitHub
-
Get major PostgreSQL version from the binary as an integer.
- Returns :
-
an integer PostgreSQL major version representation gathered from the PostgreSQL binary. See
postgres_major_version_to_int()andget_major_version().
- generate ( ) None View on GitHub
-
Generate sample config using some sane defaults and update
config.
- property get_auth_method : str View on GitHub
-
Return the preferred authentication method for a specific PG version if provided or the default
md5.- Returns :
-
strvalue for the preferred authentication method.
- patroni.config_generator. generate_config ( output_file : str , sample : bool , dsn : str | None ) None View on GitHub
-
Generate Patroni configuration file.
- Parameters :
-
-
output_file – Full path to the configuration file to be used. If not provided, result is sent to
stdout. -
sample – Optional flag. If set, no source instance will be used - generate config with some sane defaults.
-
dsn – Optional DSN string for the local instance to get GUC values from.
-
- patroni.config_generator. get_address ( ) Tuple [ str , str ] View on GitHub
-
Try to get hostname and the ip address for it returned by
gethostname().Note
Can also return local ip.
- Returns :
-
tuple consisting of the hostname returned by
gethostname()and the first element in the sorted list of the addresses returned bygetaddrinfo(). Sorting guarantees it will prefer IPv4. If an exception occurred, hostname and ip values are equal toNO_VALUE_MSG.