PG_AUTOCTL CREATE POSTGRES(1)
PG_AUTOCTL CREATE POSTGRES(1) ๐
okay bestie, this is the manual for pg_autoctl create postgres โ part of pg_auto_failover, and it's giving main character energy for your whole Postgres cluster. let's get into it โจ
๐ธ NAME ๐ธ
pg_autoctl create postgres โ pg_autoctl create postgres
pg_autoctl create postgres โ initialize a pg_auto_failover postgres node ๐ซถ
โจ SYNOPSIS โจ
so the command pg_autoctl create postgres initializes a standalone Postgres node into a pg_auto_failover monitor. and then? the monitor handles auto-failover for this Postgres node โ but only as soon as a secondary has been registered too, and is known to be healthy. no secondary, no failover, periodt. ๐
usage: pg_autoctl create postgres
--pgctl path to pg_ctl
--pgdata path to data directory
--pghost PostgreSQL's hostname
--pgport PostgreSQL's port number
--listen PostgreSQL's listen_addresses
--username PostgreSQL's username
--dbname PostgreSQL's database name
--name pg_auto_failover node name
--hostname hostname used to connect from the other nodes
--formation pg_auto_failover formation
--monitor pg_auto_failover Monitor Postgres URL
--auth authentication method for connections from monitor
--skip-pg-hba skip editing pg_hba.conf rules
--pg-hba-lan edit pg_hba.conf rules for --dbname in detected LAN
--ssl-self-signed setup network encryption using self signed certificates (does NOT protect against MITM)
--ssl-mode use that sslmode in connection strings
--ssl-ca-file set the Postgres ssl_ca_file to that file path
--ssl-crl-file set the Postgres ssl_crl_file to that file path
--no-ssl don't enable network encryption (NOT recommended, prefer --ssl-self-signed)
--server-key set the Postgres ssl_key_file to that file path
--server-cert set the Postgres ssl_cert_file to that file path
--candidate-priority priority of the node to be promoted to become primary
--replication-quorum true if node participates in write quorum
--maximum-backup-rate maximum transfer rate of data transferred from the server during initial sync
๐ฆ DESCRIPTION ๐ฆ
this command supports three different modes of initialization, matching that many implementation strategies. (yes, three. and then the list has four entries. we love a plot twist ๐ but fr fr, read on.)
- Initialize a primary node from scratch ๐
this happens when --pgdata (or the environment variable PGDATA) points to a non-existing or empty directory. then the given --hostname is registered to the pg_auto_failover --monitor as a member of the --formation.
the monitor answers the registration call with a state to assign to the new member of the group, either SINGLE or WAIT_STANDBY. when the assigned state is SINGLE, then pg_autoctl create postgres proceeds to initialize a new PostgreSQL instance. iconic.
- Initialize an already existing primary server ๐
this one hits when --pgdata (or the environment variable PGDATA) points to an already existing directory that belongs to a PostgreSQL instance. the standard PostgreSQL tool pg_controldata is used to recognize whether the directory belongs to a PostgreSQL instance.
in that case, the given --hostname is registered to the monitor in the tentative SINGLE state. when the given --formation and --group is currently empty, then the monitor accepts the registration and the pg_autoctl create prepares the already existing primary server for pg_auto_failover. slay.
- Initialize a secondary node from scratch ๐ง
this happens when --pgdata (or the environment variable PGDATA) points to a non-existing or empty directory, and when the monitor registration call assigns the state WAIT_STANDBY in step 1.
in that case, the pg_autoctl create command steps through the initial states of registering a secondary server, which includes preparing the primary server PostgreSQL HBA rules and creating a replication slot.
when the command ends successfully, a PostgreSQL secondary server has been created with pg_basebackup and is now started, catching-up to the primary server. ๐โ๏ธ๐จ
- Initialize a secondary node from an existing data directory ๐
when the data directory pointed to by the option --pgdata or the environment variable PGDATA already exists, then pg_auto_failover verifies that the system identifier matches the one of the other nodes already existing in the same group.
the system identifier can be obtained with the command pg_controldata. all nodes in a physical replication setting must have the same system identifier, and so in pg_auto_failover all the nodes in a same group have that constraint too. no cap.
when the system identifier matches the already registered system identifier of other nodes in the same group, then the node is set-up as a standby and Postgres is started with the primary conninfo pointed at the current primary. ๐
the --auth option allows setting up authentication method to be used when monitor node makes a connection to data node with pgautofailover_monitor user. as with the pg_autoctl create monitor command, you could use --auth trust when playing with pg_auto_failover at first and consider something production grade later. also, consider using --skip-pg-hba if you already have your own provisioning tools with a security compliance process.
see Security settings for pg_auto_failover for notes on .pgpass. ๐ฅ
โจ OPTIONS โจ
Okay bestie, here's the whole menu of things you can tell pg_autoctl create postgres to do. Every single one, no skipping ๐
--pgctlโ the path to thepg_ctltool for whichever PostgreSQL version you're vibing with.- If there's literally just one
pg_ctlentry in yourPATH, it defaults to that one. Wanna check your setup? Runwhich -a pg_ctland see what comes back ๐ - On RPM-based distros like RHEL or CentOS, the path is usually
/usr/pgsql-13/bin/pg_ctlfor Postgres 13. - On debian-based distros like debian or ubuntu, it's usually
/usr/lib/postgresql/13/bin/pg_ctlfor Postgres 13. Those distros also ship the packagepostgresql-common, which provides/usr/bin/pg_configโ andpg_autoctlcan use that tool automatically to sniff out the default Postgres version on your setup. Iconic ๐
- If there's literally just one
--pgdataโ where to init a Postgres database cluster, using eitherpg_ctl initdborpg_basebackup. Defaults to the environment variablePGDATA.--pghostโ the hostname to use when connecting to the local Postgres instance from thepg_autoctlprocess. By default this field is left blank in the connection string, which lets you use Unix Domain Sockets with the default path compiled into your libpq version โ usually whatever your Operating System provides. On debian or ubuntu, that's/var/run/postgresql.--pgportโ the Postgres port to use. Defaults to5432.--listenโ PostgreSQL'slisten_addressesto set up. Heads up: right now only one address is supported in this command line option.--usernameโ PostgreSQL's username to use when connecting to the local Postgres instance so it can be managed.--dbnameโ PostgreSQL's database name to use in your application. Defaults to being the same as--username, or topostgreswhen neither of those options is used.--nameโ the node name used on the monitor to refer to this node. Hostnames are, like, technical information, and given Postgres requirements around the HBA setup and DNS resolution (forward and reverse lookups), IP addresses often end up being used for the hostname.- So the
--nameoption lets you use a user-friendly name for your Postgres nodes instead. Main character naming rights, honestly ๐
- So the
--hostnameโ the hostname or IP address (v4 and v6 both supported) to use from any other node to connect to this node.- When you don't provide it, a default value gets computed by running this algorithm:
- We grab this machine's "public IP" by opening a connection to the given monitor hostname or IP address. Then we get the TCP/IP client address that was used to make that connection.
- We then do a reverse DNS lookup on the IP address found in the previous step to fetch a hostname for our local machine.
- If the reverse DNS lookup is successful, then
pg_autoctldoes a forward DNS lookup of that hostname.
- When the forward DNS lookup response in step 3 is an IP address found in one of our local network interfaces, then
pg_autoctluses the hostname found in step 2 as the default--hostname. Otherwise it uses the IP address found in step 1. - You can also just use the
--hostnamecommand line option to bypass this whole DNS lookup based process and force the local node name to a fixed value. Simple. Clean. Periodt โจ
- When you don't provide it, a default value gets computed by running this algorithm:
--formationโ the formation to register the node into on the monitor. Defaults to the default formation, which is automatically created in the monitor by thepg_autoctl create monitorcommand.--monitorโ the Postgres URI used to connect to the monitor. It must use theautoctl_nodeusername and target thepg_auto_failoverdatabase name. Fun fact: you can show the Postgres URI from the monitor node with the commandpg_autoctl show uri.--authโ the authentication methodpg_autoctluses when editing the Postgres HBA file to open connections to other nodes. There's no default value, you have to provide one. And the value--trust? That's only a good choice for testing and evaluation of pg_auto_failover โ go read Security settings for pg_auto_failover for more. Don't be chaotic with this one, bestie ๐--skip-pg-hbaโ with this option,pg_autoctlrefrains from any editing of the Postgres HBA file. But note: editing the HBA file is still needed so other nodes can connect using either read privileges or replication streaming privileges.- When
--skip-pg-hbais used,pg_autoctlstill outputs the HBA entries it needs in the logs โ it just skips editing the HBA file itself.
- When
--pg-hba-lanโ with this option,pg_autoctldetermines the local IP address used to connect to the monitor, retrieves its netmask, and uses that to compute your local area network CIDR. That CIDR then gets opened for connections in the Postgres HBA rules.- For example, when the monitor resolves to
192.168.0.1and your local Postgres node uses an interface with IP address192.168.0.2/255.255.255.0to connect to the monitor, then the LAN CIDR is computed to be192.168.0.0/24. Math ate, honestly ๐งฎ๐
- For example, when the monitor resolves to
--candidate-priorityโ sets this node's replication setting for candidate priority to the given value (between0and100) at node registration on the monitor. Defaults to50.--replication-quorumโ sets this node's replication setting for replication quorum to the given value (eithertrueorfalse) at node registration on the monitor. Defaults totrue, which enables synchronous replication.--maximum-backup-rateโ sets the maximum transfer rate of data transferred from the server during initial sync. This is used bypg_basebackup. Defaults to100M.--runโ immediately run thepg_autoctlservice after having created this node.--ssl-self-signedโ generate SSL self-signed certificates to provide network encryption. > Heads up: this does not protect against man-in-the-middle kinds of attacks. See Security settings for pg_auto_failover for more about the SSL settings.--ssl-modeโ the SSL Mode used bypg_autoctlwhen connecting to other nodes, including when connecting for streaming replication.--ssl-ca-fileโ set the Postgresssl_ca_fileto that file path.--ssl-crl-fileโ set the Postgresssl_crl_fileto that file path.--no-sslโ don't enable network encryption. This is not recommended โ prefer--ssl-self-signed.--server-keyโ set the Postgresssl_key_fileto that file path.--server-certโ set the Postgresssl_cert_fileto that file path.
๐ ENVIRONMENT ๐
The env vars are like the side quests that can replace some of the flags. Slay.
PGDATAโ Postgres directory location. Can be used instead of the--pgdataoption.PG_AUTOCTL_MONITORโ Postgres URI to connect to the monitor node. Can be used instead of the--monitoroption.PG_AUTOCTL_NODE_NAMEโ node name to register to the monitor. Can be used instead of the--nameoption.PG_AUTOCTL_REPLICATION_QUORUMโ can be used instead of the--replication-quorumoption.PG_AUTOCTL_CANDIDATE_PRIORITYโ can be used instead of the--candidate-priorityoption.PG_CONFIGโ can be set to the absolute path to thepg_configPostgres tool. This is mostly used in the context of building extensions, though it can also be a genuinely useful way to select a Postgres version when several are installed on the same system.PATHโ used the usual way, mostly. Some entries thatpg_autoctlsearches for in thePATHare expected to be found only once, to avoid mistakes with Postgres major versions. (iykyk ๐ซถ)PGHOST,PGPORT,PGDATABASE,PGUSER,PGCONNECT_TIMEOUT, ... โ see the Postgres docs about Environment Variables for details.TMPDIRโ thepgcopydbcommand creates all its work files and directories in${TMPDIR}/pgcopydb, and defaults to/tmp/pgcopydb.XDG_CONFIG_HOMEโ thepg_autoctlcommand stores its configuration files in the standard placeXDG_CONFIG_HOME. See the XDG Base Directory Specification.XDG_DATA_HOMEโ thepg_autoctlcommand stores its internal states files in the standard placeXDG_DATA_HOME, which defaults to~/.local/share. See the XDG Base Directory Specification.
๐ AUTHOR ๐
Microsoft
๐ COPYRIGHT ๐
Copyright (c) Microsoft Corporation. All rights reserved.
And that's the whole thing, bestie โ you just read the 2.2 version, dated Apr 07, 2025, from the PG_AUTOCTL CREATE POSTGRES(1) manual. Go create some Postgres nodes, you absolute legend ๐โจ๐ฆ
๐ฆ where this page comes from
- debian trixie: pg-auto-failover-cli 2.2-2 ยท PostgreSQL
- ubuntu questing: pg-auto-failover-cli 2.2-2
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms