.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "PG_AUTOCTL CREATE POSTGRES" "1" "Nov 25, 2023" "2.1" "pg_auto_failover" .SH NAME pg_autoctl create postgres \- pg_autoctl create postgres .sp pg_autoctl create postgres \- Initialize a pg_auto_failover postgres node .SH SYNOPSIS .sp The command \fBpg_autoctl create postgres\fP initializes a standalone Postgres node to a pg_auto_failover monitor. The monitor is then handling auto\-failover for this Postgres node (as soon as a secondary has been registered too, and is known to be healthy). .INDENT 0.0 .INDENT 3.5 .sp .EX usage: pg_autoctl create postgres \-\-pgctl path to pg_ctl \-\-pgdata path to data directory \-\-pghost PostgreSQL\(aqs hostname \-\-pgport PostgreSQL\(aqs port number \-\-listen PostgreSQL\(aqs listen_addresses \-\-username PostgreSQL\(aqs username \-\-dbname PostgreSQL\(aqs 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\(aqt 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 .EE .UNINDENT .UNINDENT .SH DESCRIPTION .sp Three different modes of initialization are supported by this command, corresponding to as many implementation strategies. .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .IP 1. 3 Initialize a primary node from scratch .sp This happens when \fB\-\-pgdata\fP (or the environment variable \fBPGDATA\fP) points to an non\-existing or empty directory. Then the given \fB\-\-hostname\fP is registered to the pg_auto_failover \fB\-\-monitor\fP as a member of the \fB\-\-formation\fP\&. .sp The monitor answers to the registration call with a state to assign to the new member of the group, either \fISINGLE\fP or \fIWAIT_STANDBY\fP\&. When the assigned state is \fISINGLE\fP, then \fBpg_autoctl create postgres\fP proceeds to initialize a new PostgreSQL instance. .IP 2. 3 Initialize an already existing primary server .sp This happens when \fB\-\-pgdata\fP (or the environment variable \fBPGDATA\fP) points to an already existing directory that belongs to a PostgreSQL instance. The standard PostgreSQL tool \fBpg_controldata\fP is used to recognize whether the directory belongs to a PostgreSQL instance. .sp In that case, the given \fB\-\-hostname\fP is registered to the monitor in the tentative \fISINGLE\fP state. When the given \fB\-\-formation\fP and \fB\-\-group\fP is currently empty, then the monitor accepts the registration and the \fBpg_autoctl create\fP prepares the already existing primary server for pg_auto_failover. .IP 3. 3 Initialize a secondary node from scratch .sp This happens when \fB\-\-pgdata\fP (or the environment variable \fBPGDATA\fP) points to a non\-existing or empty directory, and when the monitor registration call assigns the state \fIWAIT_STANDBY\fP in step 1. .sp In that case, the \fBpg_autoctl create\fP 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. .sp When the command ends successfully, a PostgreSQL secondary server has been created with \fBpg_basebackup\fP and is now started, catching\-up to the primary server. .IP 4. 3 Initialize a secondary node from an existing data directory .sp When the data directory pointed to by the option \fB\-\-pgdata\fP or the environment variable \fBPGDATA\fP already exists, then pg_auto_failover verifies that the system identifier matches the one of the other nodes already existing in the same group. .sp The system identifier can be obtained with the command \fBpg_controldata\fP\&. 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. .sp 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. .UNINDENT .UNINDENT .UNINDENT .sp The \fB\-\-auth\fP option allows setting up authentication method to be used when monitor node makes a connection to data node with \fBpgautofailover_monitor\fP user. As with the \fI\%pg_autoctl create monitor\fP command, you could use \fB\-\-auth trust\fP when playing with pg_auto_failover at first and consider something production grade later. Also, consider using \fB\-\-skip\-pg\-hba\fP if you already have your own provisioning tools with a security compliance process. .sp See \fI\%Security settings for pg_auto_failover\fP for notes on \fI\&.pgpass\fP .SH OPTIONS .sp The following options are available to \fBpg_autoctl create postgres\fP: .INDENT 0.0 .TP .B \-\-pgctl Path to the \fBpg_ctl\fP tool to use for the version of PostgreSQL you want to use. .sp Defaults to the \fBpg_ctl\fP found in the PATH when there is a single entry for \fBpg_ctl\fP in the PATH. Check your setup using \fBwhich \-a pg_ctl\fP\&. .sp When using an RPM based distribution such as RHEL or CentOS, the path would usually be \fB/usr/pgsql\-13/bin/pg_ctl\fP for Postgres 13. .sp When using a debian based distribution such as debian or ubuntu, the path would usually be \fB/usr/lib/postgresql/13/bin/pg_ctl\fP for Postgres 13. Those distributions also use the package \fBpostgresql\-common\fP which provides \fB/usr/bin/pg_config\fP\&. This tool can be automatically used by \fBpg_autoctl\fP to discover the default version of Postgres to use on your setup. .TP .B \-\-pgdata Location where to initialize a Postgres database cluster, using either \fBpg_ctl initdb\fP or \fBpg_basebackup\fP\&. Defaults to the environment variable \fBPGDATA\fP\&. .TP .B \-\-pghost Hostname to use when connecting to the local Postgres instance from the \fBpg_autoctl\fP process. By default, this field is left blank in the connection string, allowing to use Unix Domain Sockets with the default path compiled in your \fBlibpq\fP version, usually provided by the Operating System. That would be \fB/var/run/postgresql\fP when using debian or ubuntu. .TP .B \-\-pgport Postgres port to use, defaults to 5432. .TP .B \-\-listen PostgreSQL\(aqs \fBlisten_addresses\fP to setup. At the moment only one address is supported in this command line option. .TP .B \-\-username PostgreSQL\(aqs username to use when connecting to the local Postgres instance to manage it. .TP .B \-\-dbname PostgreSQL\(aqs database name to use in your application. Defaults to being the same as the \fB\-\-username\fP, or to \fBpostgres\fP when none of those options are used. .TP .B \-\-name Node name used on the monitor to refer to this node. The hostname is a technical information, and given Postgres requirements on the HBA setup and DNS resolution (both forward and reverse lookups), IP addresses are often used for the hostname. .sp The \fB\-\-name\fP option allows using a user\-friendly name for your Postgres nodes. .TP .B \-\-hostname Hostname or IP address (both v4 and v6 are supported) to use from any other node to connect to this node. .sp When not provided, a default value is computed by running the following algorithm. .INDENT 7.0 .INDENT 3.5 .INDENT 0.0 .IP 1. 3 We get this machine\(aqs \(dqpublic IP\(dq by opening a connection to the given monitor hostname or IP address. Then we get TCP/IP client address that has been used to make that connection. .IP 2. 3 We then do a reverse DNS lookup on the IP address found in the previous step to fetch a hostname for our local machine. .IP 3. 3 If the reverse DNS lookup is successful , then \fBpg_autoctl\fP does a forward DNS lookup of that hostname. .UNINDENT .UNINDENT .UNINDENT .sp When the forward DNS lookup response in step 3. is an IP address found in one of our local network interfaces, then \fBpg_autoctl\fP uses the hostname found in step 2. as the default \fB\-\-hostname\fP\&. Otherwise it uses the IP address found in step 1. .sp You may use the \fB\-\-hostname\fP command line option to bypass the whole DNS lookup based process and force the local node name to a fixed value. .TP .B \-\-formation Formation to register the node into on the monitor. Defaults to the \fBdefault\fP formation, that is automatically created in the monitor in the \fI\%pg_autoctl create monitor\fP command. .TP .B \-\-monitor Postgres URI used to connect to the monitor. Must use the \fBautoctl_node\fP username and target the \fBpg_auto_failover\fP database name. It is possible to show the Postgres URI from the monitor node using the command \fI\%pg_autoctl show uri\fP\&. .TP .B \-\-auth Authentication method used by \fBpg_autoctl\fP when editing the Postgres HBA file to open connections to other nodes. No default value, must be provided by the user. The value \fB\-\-trust\fP is only a good choice for testing and evaluation of pg_auto_failover, see \fI\%Security settings for pg_auto_failover\fP for more information. .TP .B \-\-skip\-pg\-hba When this option is used then \fBpg_autoctl\fP refrains from any editing of the Postgres HBA file. Please note that editing the HBA file is still needed so that other nodes can connect using either read privileges or replication streaming privileges. .sp When \fB\-\-skip\-pg\-hba\fP is used, \fBpg_autoctl\fP still outputs the HBA entries it needs in the logs, it only skips editing the HBA file. .TP .B \-\-pg\-hba\-lan When this option is used \fBpg_autoctl\fP determines the local IP address used to connect to the monitor, and retrieves its netmask, and uses that to compute your local area network CIDR. This CIDR is then opened for connections in the Postgres HBA rules. .sp For instance, when the monitor resolves to \fB192.168.0.1\fP and your local Postgres node uses an interface with IP address \fB192.168.0.2/255.255.255.0\fP to connect to the monitor, then the LAN CIDR is computed to be \fB192.168.0.0/24\fP\&. .TP .B \-\-candidate\-priority Sets this node replication setting for candidate priority to the given value (between 0 and 100) at node registration on the monitor. Defaults to 50. .TP .B \-\-replication\-quorum Sets this node replication setting for replication quorum to the given value (either \fBtrue\fP or \fBfalse\fP) at node registration on the monitor. Defaults to \fBtrue\fP, which enables synchronous replication. .TP .B \-\-maximum\-backup\-rate Sets the maximum transfer rate of data transferred from the server during initial sync. This is used by \fBpg_basebackup\fP\&. Defaults to \fB100M\fP\&. .TP .B \-\-run Immediately run the \fBpg_autoctl\fP service after having created this node. .TP .B \-\-ssl\-self\-signed Generate SSL self\-signed certificates to provide network encryption. This does not protect against man\-in\-the\-middle kinds of attacks. See \fI\%Security settings for pg_auto_failover\fP for more about our SSL settings. .TP .B \-\-ssl\-mode SSL Mode used by \fBpg_autoctl\fP when connecting to other nodes, including when connecting for streaming replication. .TP .B \-\-ssl\-ca\-file Set the Postgres \fBssl_ca_file\fP to that file path. .TP .B \-\-ssl\-crl\-file Set the Postgres \fBssl_crl_file\fP to that file path. .TP .B \-\-no\-ssl Don\(aqt enable network encryption. This is not recommended, prefer \fB\-\-ssl\-self\-signed\fP\&. .TP .B \-\-server\-key Set the Postgres \fBssl_key_file\fP to that file path. .TP .B \-\-server\-cert Set the Postgres \fBssl_cert_file\fP to that file path. .UNINDENT .SH ENVIRONMENT .sp PGDATA .INDENT 0.0 .INDENT 3.5 Postgres directory location. Can be used instead of the \fB\-\-pgdata\fP option. .UNINDENT .UNINDENT .sp PG_AUTOCTL_MONITOR .INDENT 0.0 .INDENT 3.5 Postgres URI to connect to the monitor node, can be used instead of the \fB\-\-monitor\fP option. .UNINDENT .UNINDENT .sp PG_AUTOCTL_NODE_NAME .INDENT 0.0 .INDENT 3.5 Node name to register to the monitor, can be used instead of the \fB\-\-name\fP option. .UNINDENT .UNINDENT .sp PG_AUTOCTL_REPLICATION_QUORUM .INDENT 0.0 .INDENT 3.5 Can be used instead of the \fB\-\-replication\-quorum\fP option. .UNINDENT .UNINDENT .sp PG_AUTOCTL_CANDIDATE_PRIORITY .INDENT 0.0 .INDENT 3.5 Can be used instead of the \fB\-\-candidate\-priority\fP option. .UNINDENT .UNINDENT .sp PG_CONFIG .INDENT 0.0 .INDENT 3.5 Can be set to the absolute path to the \fI\%pg_config\fP Postgres tool. This is mostly used in the context of building extensions, though it can be a useful way to select a Postgres version when several are installed on the same system. .UNINDENT .UNINDENT .sp PATH .INDENT 0.0 .INDENT 3.5 Used the usual way mostly. Some entries that are searched in the PATH by the \fBpg_autoctl\fP command are expected to be found only once, to avoid mistakes with Postgres major versions. .UNINDENT .UNINDENT .sp PGHOST, PGPORT, PGDATABASE, PGUSER, PGCONNECT_TIMEOUT, ... .INDENT 0.0 .INDENT 3.5 See the \fI\%Postgres docs about Environment Variables\fP for details. .UNINDENT .UNINDENT .sp TMPDIR .INDENT 0.0 .INDENT 3.5 The pgcopydb command creates all its work files and directories in \fB${TMPDIR}/pgcopydb\fP, and defaults to \fB/tmp/pgcopydb\fP\&. .UNINDENT .UNINDENT .sp XDG_CONFIG_HOME .INDENT 0.0 .INDENT 3.5 The pg_autoctl command stores its configuration files in the standard place XDG_CONFIG_HOME. See the \fI\%XDG Base Directory Specification\fP\&. .UNINDENT .UNINDENT .sp XDG_DATA_HOME .INDENT 0.0 .INDENT 3.5 The pg_autoctl command stores its internal states files in the standard place XDG_DATA_HOME, which defaults to \fB~/.local/share\fP\&. See the \fI\%XDG Base Directory Specification\fP\&. .UNINDENT .UNINDENT .SH AUTHOR Microsoft .SH COPYRIGHT Copyright (c) Microsoft Corporation. All rights reserved. .\" Generated by docutils manpage writer. .