{"id":12891,"date":"2019-11-01T07:25:16","date_gmt":"2019-11-01T06:25:16","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/"},"modified":"2019-11-01T07:25:16","modified_gmt":"2019-11-01T06:25:16","slug":"pg_auto_failover-setup-and-installation","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/","title":{"rendered":"pg_auto_failover: Setup and installation"},"content":{"rendered":"<p>When I attended <a href=\"https:\/\/pgibz.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">PGIBZ 2019<\/a> earlier this year, I talked with <a href=\"https:\/\/www.linkedin.com\/in\/dimitrifontaine\/\" target=\"blank\" rel=\"noopener noreferrer\">Dimitri<\/a> about <a href=\"https:\/\/github.com\/citusdata\/pg_auto_failover\" target=\"_blank\" rel=\"noopener noreferrer\">pg_auto_failover<\/a> and I promised to have a look at it. Well, almost half a year later and after we&#8217;ve met again at <a href=\"https:\/\/2019.pgconf.eu\/\" target=\"_blank\" rel=\"noopener noreferrer\">pgconf.eu<\/a> it is time to actually do that. You probably already know that <a href=\"https:\/\/www.citusdata.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">citudata<\/a> was acquired by Microsoft earlier this year and that Microsoft seems to be committed to open source since a few years. pg_auto_failover is one of the projects they contribute back to the PostgreSQL community. This will be a multi-blog series and in this very first post it is all about getting it up and running. In a following post we will then look at failover and switchover scenarios.<\/p>\n<p><!--more--><\/p>\n<p>As usual, when you need auto failover you need at least three nodes and pg_auto_failover is no exception to that. The following graphic is stolen from the pg_auto_failover github page:<br \/>\n<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg\" alt=\"\" width=\"1416\" height=\"514\" class=\"aligncenter size-full wp-image-34903\" \/><\/a><\/p>\n<p>We have one PostgreSQL master, one PostgreSQL replica and in addition a monitoring host. In may case that maps to:<\/p>\n<table>\n<tr>\n<td>pg-af1.ti.dbi-services.com<\/td>\n<td>master<\/td>\n<td>192.168.22.70<\/td>\n<\/tr>\n<\/tr>\n<td>pg-af2.ti.dbi-services.com<\/td>\n<td>replica<\/td>\n<td>192.168.22.71<\/td>\n<\/tr>\n<\/tr>\n<td>pg-af3.ti.dbi-services.com<\/td>\n<td>monitor\/cluster management<\/td>\n<td>192.168.22.72<\/td>\n<\/tr>\n<\/table>\n<p>All of these nodes run <a href=\"https:\/\/www.centos.org\/CentOS 8\" target=\"_blank\" rel=\"noopener noreferrer\">CentOS 8<\/a> and I will be going from source code as that gives most flexibility. As pg_auto_failover depends on PostgreSQL (of course) the first step is to install PostgreSQL on all three nodes (PostgreSQL 12 in this setup). If you need further information on how to do that you can e.g. check <a href=\"https:\/\/www.dbi-services.com\/blog\/how-to-compile-postgresql-11-with-support-for-jit-compilation-on-rhelcentos-7\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. Basically these steps have been executed on all the three nodes (given that the postgres user already exists and sudo is configured):<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\n[postgres@pg-af1 ~]$ sudo dnf install -y gcc openldap-devel python36-devel readline-devel redhat-lsb bison flex perl-ExtUtils-Embed zlib-devel openssl-devel pam-devel libxml2-devel libxslt-devel openssh-clients bzip2 net-tools wget unzip sysstat xorg-x11-xauth systemd-devel bash-completion python36 policycoreutils-python-utils make git\n[postgres@pg-af1 ~]$ wget https:\/\/ftp.postgresql.org\/pub\/source\/v12.0\/postgresql-12.0.tar.bz2\n[postgres@pg-af1 ~]$ tar -axf postgresql-12.0.tar.bz2\n[postgres@pg-af1 ~]$ cd postgresql-12.0\n[postgres@pg-af1 postgresql-12.0]$ sudo mkdir -p \/u01 \/u02\n[postgres@pg-af1 postgresql-12.0]$ sudo chown postgres:postgres \/u01 \/u02\n[postgres@pg-af1 postgresql-12.0]$ PGHOME=\/u01\/app\/postgres\/product\/12\/db_0\/\n[postgres@pg-af1 postgresql-12.0]$ SEGSIZE=2\n[postgres@pg-af1 postgresql-12.0]$ BLOCKSIZE=8\n[postgres@pg-af1 postgresql-12.0]$ WALSEGSIZE=64\n[postgres@pg-af1 postgresql-12.0]$ .\/configure --prefix=${PGHOME} \\\n&gt; --exec-prefix=${PGHOME} \\\n&gt; --bindir=${PGHOME}\/bin \\\n&gt; --libdir=${PGHOME}\/lib \\\n&gt; --sysconfdir=${PGHOME}\/etc \\\n&gt; --includedir=${PGHOME}\/include \\\n&gt; --datarootdir=${PGHOME}\/share \\\n&gt; --datadir=${PGHOME}\/share \\\n&gt; --with-pgport=5432 \\\n&gt; --with-perl \\\n&gt; --with-python \\\n&gt; --with-openssl \\\n&gt; --with-pam \\\n&gt; --with-ldap \\\n&gt; --with-libxml \\\n&gt; --with-libxslt \\\n&gt; --with-segsize=${SEGSIZE} \\\n&gt; --with-blocksize=${BLOCKSIZE} \\\n&gt; --with-systemd \\\n&gt; --with-extra-version=\" dbi services build\"\n[postgres@pg-af1 postgresql-12.0]$ make all\n[postgres@pg-af1 postgresql-12.0]$ make install\n[postgres@pg-af1 postgresql-12.0]$ cd contrib\n[postgres@pg-af1 contrib]$ make install\n[postgres@pg-af1 contrib]$ cd ..\/..\n[postgres@pg-af1 ~]$ rm -rf postgresql*\n<\/pre>\n<p>We will go for an installation from source code of pg_auto_failover as well (again, on all three nodes):<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af1:\/home\/postgres\/ [pg120] git clone https:\/\/github.com\/citusdata\/pg_auto_failover.git\npostgres@pg-af1:\/home\/postgres\/ [pg120] cd pg_auto_failover\/\npostgres@pg-af1:\/home\/postgres\/pg_auto_failover\/ [pg120] make\npostgres@pg-af1:\/home\/postgres\/pg_auto_failover\/ [pg120] make install\npostgres@pg-af1:\/home\/postgres\/pg_auto_failover\/ [pg120] cd ..\npostgres@pg-af1:\/home\/postgres\/ [pg120] rm -rf pg_auto_failover\/\n<\/pre>\n<p>That&#8217;s it, quite easy. What I like especially is, that there are no dependencies on python or any other libraries except for PostgreSQL. What the installation gives us is basically pg_autoctl:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af1:\/home\/postgres\/ [pg120] pg_autoctl --help\npg_autoctl: pg_auto_failover control tools and service\nusage: pg_autoctl [ --verbose --quiet ]\n\n\nAvailable commands:\npg_autoctl\n+ create   Create a pg_auto_failover node, or formation\n+ drop     Drop a pg_auto_failover node, or formation\n+ config   Manages the pg_autoctl configuration\n+ show     Show pg_auto_failover information\n+ enable   Enable a feature on a formation\n+ disable  Disable a feature on a formation\nrun      Run the pg_autoctl service (monitor or keeper)\nstop     signal the pg_autoctl service for it to stop\nreload   signal the pg_autoctl for it to reload its configuration\nhelp     print help message\nversion  print pg_autoctl version\n<\/pre>\n<p>The first step in setting up the cluster is to initialize the monitoring node:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [1,10,11,12,13]\">\npostgres@pg-af3:\/home\/postgres\/ [pg120] pg_autoctl create --help\npg_autoctl create: Create a pg_auto_failover node, or formation\n\nAvailable commands:\npg_autoctl create\nmonitor    Initialize a pg_auto_failover monitor node\npostgres   Initialize a pg_auto_failover standalone postgres node\nformation  Create a new formation on the pg_auto_failover monitor\n\npostgres@pg-af3:\/home\/postgres\/ [pg120] sudo mkdir -p \/u02\/pgdata\npostgres@pg-af3:\/home\/postgres\/ [pg120] sudo chown postgres:postgres \/u02\/pgdata\npostgres@pg-af3:\/home\/postgres\/ [pg120] unset PGDATABASE\npostgres@pg-af3:\/home\/postgres\/ [] pg_autoctl create monitor --pgdata \/u02\/pgdata\/PG12\/af\nINFO  Initialising a PostgreSQL cluster at \"\/u02\/pgdata\/PG12\/af\"\nINFO   \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_ctl --pgdata \/u02\/pgdata\/PG12\/af --options \"-p 5432\" --options \"-h *\" --waitstart\nINFO  Granting connection privileges on 192.168.22.0\/24\nINFO  Your pg_auto_failover monitor instance is now ready on port 5432.\nINFO  pg_auto_failover monitor is ready at postgres:\/\/autoctl_node@pg-af3:5432\/pg_auto_failover\nINFO  Monitor has been succesfully initialized.\n<\/pre>\n<p>Once that succeeds you&#8217;ll a new PostgreSQL instance running and pg_auto_failover PostgreSQL background worker processes:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [9,10]\">\npostgres@pg-af3:\/home\/postgres\/ [af] ps -ef | grep \"postgres:\"\npostgres  5958  5955  0 14:15 ?        00:00:00 postgres: checkpointer\npostgres  5959  5955  0 14:15 ?        00:00:00 postgres: background writer\npostgres  5960  5955  0 14:15 ?        00:00:00 postgres: walwriter\npostgres  5961  5955  0 14:15 ?        00:00:00 postgres: autovacuum launcher\npostgres  5962  5955  0 14:15 ?        00:00:00 postgres: stats collector\npostgres  5963  5955  0 14:15 ?        00:00:00 postgres: pg_auto_failover monitor\npostgres  5964  5955  0 14:15 ?        00:00:00 postgres: logical replication launcher\npostgres  5965  5955  0 14:15 ?        00:00:00 postgres: pg_auto_failover monitor worker\npostgres  5966  5955  0 14:15 ?        00:00:00 postgres: pg_auto_failover monitor worker\n<\/pre>\n<p>The initialization of the monitor node also created a new database and two roles:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [9,20,21]\">\npostgres@pg-af3:\/home\/postgres\/ [af] psql postgres\npsql (12.0 dbi services build)\nType \"help\" for help.\n\npostgres=# \\l\nList of databases\nName       |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges\n------------------+----------+----------+-------------+-------------+-----------------------\npg_auto_failover | autoctl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |\npostgres         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |\ntemplate0        | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n                 |          |          |             |             | postgres=CTc\/postgres\ntemplate1        | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n                 |          |          |             |             | postgres=CTc\/postgres\n\npostgres=# \\du\nList of roles\nRole name   |                         Attributes                         | Member of\n--------------+------------------------------------------------------------+-----------\nautoctl      |                                                            | {}\nautoctl_node |                                                            | {}\npostgres     | Superuser, Create role, Create DB, Replication, Bypass RLS | {}\n<\/pre>\n<p>What we got in the new database is the pgautofailover extension:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npg_auto_failover=# \\dx\nList of installed extensions\nName      | Version |   Schema   |         Description\n----------------+---------+------------+------------------------------\npgautofailover | 1.0     | public     | pg_auto_failover\nplpgsql        | 1.0     | pg_catalog | PL\/pgSQL procedural language\n(2 rows)\n<\/pre>\n<p>For our management kit to work properly a few PostgreSQL parameters will be set:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npg_auto_failover=# alter system set log_truncate_on_rotation = 'on';\nALTER SYSTEM\npg_auto_failover=# alter system set log_filename = 'postgresql-%a.log';\nALTER SYSTEM\npg_auto_failover=# alter system set log_rotation_age = '1440';\nALTER SYSTEM\npg_auto_failover=# alter system set log_line_prefix = '%m - %l - %p - %h - %u@%d - %x';\nALTER SYSTEM\npg_auto_failover=# alter system set log_directory = 'pg_log';\nALTER SYSTEM\npg_auto_failover=# alter system set log_min_messages = 'WARNING';\nALTER SYSTEM\npg_auto_failover=# alter system set log_autovacuum_min_duration = '60s';\nALTER SYSTEM\npg_auto_failover=# alter system set log_min_error_statement = 'NOTICE';\nALTER SYSTEM\npg_auto_failover=# alter system set log_min_duration_statement = '30s';\nALTER SYSTEM\npg_auto_failover=# alter system set log_checkpoints = 'on';\nALTER SYSTEM\npg_auto_failover=# alter system set log_statement = 'ddl';\nALTER SYSTEM\npg_auto_failover=# alter system set log_lock_waits = 'on';\nALTER SYSTEM\npg_auto_failover=# alter system set log_temp_files = '0';\nALTER SYSTEM\npg_auto_failover=# alter system set log_timezone = 'Europe\/Zurich';\nALTER SYSTEM\npg_auto_failover=# alter system set log_connections=on;\nALTER SYSTEM\npg_auto_failover=# alter system set log_disconnections=on;\nALTER SYSTEM\npg_auto_failover=# alter system set log_duration=on;\nALTER SYSTEM\npg_auto_failover=# select pg_reload_conf();\npg_reload_conf\n----------------\nt\n(1 row)\n<\/pre>\n<p>What we need for the other nodes is the connection string to the monitoring node:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af3:\/home\/postgres\/ [af] pg_autoctl show uri\npostgres:\/\/autoctl_node@pg-af3:5432\/pg_auto_failover\n<\/pre>\n<p>Once we have that we can proceed with creating the master instance on the first host:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: [1,2,3,4]\">\npostgres@pg-af1:\/home\/postgres\/ [pg120] unset PGDATABASE\npostgres@pg-af1:\/home\/postgres\/ [] sudo mkdir \/u02\/pgdata\npostgres@pg-af1:\/home\/postgres\/ [] sudo chown postgres:postgres \/u02\/pgdata\npostgres@pg-af1:\/home\/postgres\/ [] pg_autoctl create postgres --pgdata \/u02\/pgdata\/12\/PG1 --nodename pg-af1.it.dbi-services.com --monitor postgres:\/\/autoctl_node@pg-af3:5432\/pg_auto_failover\nINFO  Found pg_ctl for PostgreSQL 12.0 at \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_ctl\nINFO  Registered node pg-af1.it.dbi-services.com:5432 with id 1 in formation \"default\", group 0.\nINFO  Writing keeper init state file at \"\/home\/postgres\/.local\/share\/pg_autoctl\/u02\/pgdata\/12\/PG1\/pg_autoctl.init\"\nINFO  Successfully registered as \"single\" to the monitor.\nINFO  Initialising a PostgreSQL cluster at \"\/u02\/pgdata\/12\/PG1\"\nINFO  Postgres is not running, starting postgres\nINFO   \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_ctl --pgdata \/u02\/pgdata\/12\/PG1 --options \"-p 5432\" --options \"-h *\" --wait start\nINFO  The user \"postgres\" already exists, skipping.\nINFO  CREATE DATABASE postgres;\nINFO  The database \"postgres\" already exists, skipping.\nINFO  FSM transition from \"init\" to \"single\": Start as a single node\nINFO  Initialising postgres as a primary\nINFO  Transition complete: current state is now \"single\"\nINFO  Keeper has been succesfully initialized.\n<\/pre>\n<p>Once the master if up bring up the replica on the second node:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af2:\/home\/postgres\/ [pg120] pg_autoctl create postgres --pgdata \/u02\/pgdata\/12\/PG1 --nodename pg-af2.it.dbi-services.com --monitor postgres:\/\/autoctl_node@pg-af3:5432\/pg_auto_failover\n17:11:42 INFO  Registered node pg-af2.it.dbi-services.com:5432 with id 2 in formation \"default\", group 0.\n17:11:42 INFO  Writing keeper init state file at \"\/home\/postgres\/.local\/share\/pg_autoctl\/u02\/pgdata\/12\/PG1\/pg_autoctl.init\"\n17:11:42 INFO  Successfully registered as \"wait_standby\" to the monitor.\n17:11:42 INFO  FSM transition from \"init\" to \"wait_standby\": Start following a primary\n17:11:42 INFO  Transition complete: current state is now \"wait_standby\"\n17:11:47 INFO  FSM transition from \"wait_standby\" to \"catchingup\": The primary is now ready to accept a standby\n17:11:47 INFO  The primary node returned by the monitor is pg-af1.it.dbi-services.com:5432\n17:11:47 INFO  Initialising PostgreSQL as a hot standby\n17:11:47 INFO  Running \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_basebackup -w -h pg-af1.it.dbi-services.com -p 5432 --pgdata \/u02\/pgdata\/12\/backup -U pgautofailover_replicator --write-recovery-conf --max-rate 100M --wal-method=stream --slot pgautofailover_standby ...\n17:11:49 INFO  pg_basebackup: initiating base backup, waiting for checkpoint to complete\npg_basebackup: checkpoint completed\npg_basebackup: write-ahead log start point: 0\/2000028 on timeline 1\npg_basebackup: starting background WAL receiver\n0\/23699 kB (0%), 0\/1 tablespace (\/u02\/pgdata\/12\/backup\/backup_label )\n136\/23699 kB (0%), 0\/1 tablespace (\/u02\/pgdata\/12\/backup\/global\/4184  )\n23708\/23708 kB (100%), 0\/1 tablespace (...data\/12\/backup\/global\/pg_control)\n23708\/23708 kB (100%), 1\/1 tablespace\npg_basebackup: write-ahead log end point: 0\/2000100\npg_basebackup: waiting for background process to finish streaming ...\npg_basebackup: syncing data to disk ...\npg_basebackup: base backup completed\n\n17:11:49 INFO  Postgres is not running, starting postgres\n17:11:49 INFO   \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_ctl --pgdata \/u02\/pgdata\/12\/PG1 --options \"-p 5432\" --options \"-h *\" --wait start\n17:11:50 INFO  PostgreSQL started on port 5432\n17:11:50 INFO  Transition complete: current state is now \"catchingup\"\n17:11:50 INFO  Keeper has been succesfully initialized.\n<\/pre>\n<p>The next step is to start the so called keeper process (this is the process which communicates with the montoring node about state changes):<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af1:\/home\/postgres\/ [] pg_autoctl run --pgdata \/u02\/pgdata\/12\/PG1\nINFO  Managing PostgreSQL installation at \"\/u02\/pgdata\/12\/PG1\"\nINFO  The version of extenstion \"pgautofailover\" is \"1.0\" on the monitor\nINFO  pg_autoctl service is starting\nINFO  Calling node_active for node default\/1\/0 with current state: single, PostgreSQL is running, sync_state is \"\", current lsn is \"0\/0\".\nINFO  Calling node_active for node default\/1\/0 with current state: single, PostgreSQL is running, sync_state is \"\", current lsn is \"0\/0\".\nINFO  Calling node_active for node default\/1\/0 with current state: single, PostgreSQL is running, sync_state is \"\", current lsn is \"0\/0\".\nINFO  Calling node_active for node default\/1\/0 with current state: single, PostgreSQL is running, sync_state is \"\", current lsn is \"0\/0\".\n<\/pre>\n<p>To integrate that into systemd:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af2:\/home\/postgres\/ [PG1] pg_autoctl show systemd\n20:28:43 INFO  HINT: to complete a systemd integration, run the following commands:\n20:28:43 INFO  pg_autoctl -q show systemd --pgdata \"\/u02\/pgdata\/12\/PG1\" | sudo tee \/etc\/systemd\/system\/pgautofailover.service\n20:28:43 INFO  sudo systemctl daemon-reload\n20:28:43 INFO  sudo systemctl start pgautofailover\n[Unit]\nDescription = pg_auto_failover\n\n[Service]\nWorkingDirectory = \/u02\/pgdata\/12\/PG1\nEnvironment = 'PGDATA=\/u02\/pgdata\/12\/PG1'\nUser = postgres\nExecStart = \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_autoctl run\nRestart = always\nStartLimitBurst = 0\n\n[Install]\nWantedBy = multi-user.target\n\npostgres@pg-af2:\/home\/postgres\/ [PG1] pg_autoctl -q show systemd --pgdata \"\/u02\/pgdata\/12\/PG1\" | sudo tee \/etc\/systemd\/system\/pgautofailover.service\n[Unit]\nDescription = pg_auto_failover\n\n[Service]\nWorkingDirectory = \/u02\/pgdata\/12\/PG1\nEnvironment = 'PGDATA=\/u02\/pgdata\/12\/PG1'\nUser = postgres\nExecStart = \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_autoctl run\nRestart = always\nStartLimitBurst = 0\n\n[Install]\nWantedBy = multi-user.target\n\npostgres@pg-af2:\/home\/postgres\/ [PG1] systemctl list-unit-files | grep pgauto\npgautofailover.service                      disabled\n20:30:57 postgres@pg-af2:\/home\/postgres\/ [PG1] sudo systemctl enable pgautofailover.service\nCreated symlink \/etc\/systemd\/system\/multi-user.target.wants\/pgautofailover.service \u2192 \/etc\/systemd\/system\/pgautofailover.service.\n<\/pre>\n<p>If you are on CentOS\/Red Hat 8 you will also need this as otherwise the service will not start:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af1:\/u01\/app\/postgres\/local\/dmk\/ [PG1] sudo semanage fcontext -a -t bin_t \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_autoctl\npostgres@pg-af1:\/u01\/app\/postgres\/local\/dmk\/ [PG1] restorecon -v \/u01\/app\/postgres\/product\/12\/db_0\/bin\/pg_autoctl\n<\/pre>\n<p>After rebooting all the nodes (to confirm that the systemd service is working as expected) the state of the cluster reports one primary and a secondary\/replica as expected:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af3:\/home\/postgres\/ [af] pg_autoctl show state\nName |   Port | Group |  Node |     Current State |    Assigned State\n---------------------------+--------+-------+-------+-------------------+------------------\npg-af1.it.dbi-services.com |   5432 |     0 |     1 |           primary |           primary\npg-af2.it.dbi-services.com |   5432 |     0 |     2 |         secondary |         secondary\n<\/pre>\n<p>The various states are documented <a href=\"https:\/\/pg-auto-failover.readthedocs.io\/en\/latest\/fsm.html#state-reference\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p>Remember: As this is based on PostgreSQL 12 there will be no recovery.conf on the replica. The replication parameters have been added to postgresql.auto.conf automatically:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@pg-af2:\/u02\/pgdata\/12\/PG1\/ [PG1] cat postgresql.auto.conf\n# Do not edit this file manually!\n# It will be overwritten by the ALTER SYSTEM command.\nprimary_conninfo = 'user=pgautofailover_replicator passfile=''\/home\/postgres\/.pgpass'' connect_timeout=5 host=''pg-af1.it.dbi-services.com'' port=5432 sslmode=prefer sslcompression=0 gssencmode=disable target_session_attrs=any'\nprimary_slot_name = 'pgautofailover_standby'\n<\/pre>\n<p>That&#8217;s it for the setup. Really easy and simple, I like it. In the next post we&#8217;ll have a look at controlled switch-overs and fail-over scenarios.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I attended PGIBZ 2019 earlier this year, I talked with Dimitri about pg_auto_failover and I promised to have a look at it. Well, almost half a year later and after we&#8217;ve met again at pgconf.eu it is time to actually do that. You probably already know that citudata was acquired by Microsoft earlier this [&hellip;]<\/p>\n","protected":false},"author":29,"featured_media":12892,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[1715,77],"type_dbi":[],"class_list":["post-12891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database-administration-monitoring","tag-pg_auto_failover","tag-postgresql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>pg_auto_failover: Setup and installation - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"pg_auto_failover: Setup and installation\" \/>\n<meta property=\"og:description\" content=\"When I attended PGIBZ 2019 earlier this year, I talked with Dimitri about pg_auto_failover and I promised to have a look at it. Well, almost half a year later and after we&#8217;ve met again at pgconf.eu it is time to actually do that. You probably already know that citudata was acquired by Microsoft earlier this [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-01T06:25:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1416\" \/>\n\t<meta property=\"og:image:height\" content=\"514\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Daniel Westermann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@westermanndanie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Westermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/\"},\"author\":{\"name\":\"Daniel Westermann\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"headline\":\"pg_auto_failover: Setup and installation\",\"datePublished\":\"2019-11-01T06:25:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/\"},\"wordCount\":586,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/Selection_236.jpg\",\"keywords\":[\"pg_auto_failover\",\"PostgreSQL\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/\",\"name\":\"pg_auto_failover: Setup and installation - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/Selection_236.jpg\",\"datePublished\":\"2019-11-01T06:25:16+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/Selection_236.jpg\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/04\\\/Selection_236.jpg\",\"width\":1416,\"height\":514},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/pg_auto_failover-setup-and-installation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"pg_auto_failover: Setup and installation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d08e9bd996a89bd75c0286cbabf3c66\",\"name\":\"Daniel Westermann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"caption\":\"Daniel Westermann\"},\"description\":\"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\\\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.\",\"sameAs\":[\"https:\\\/\\\/x.com\\\/westermanndanie\"],\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/daniel-westermann\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"pg_auto_failover: Setup and installation - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/","og_locale":"en_US","og_type":"article","og_title":"pg_auto_failover: Setup and installation","og_description":"When I attended PGIBZ 2019 earlier this year, I talked with Dimitri about pg_auto_failover and I promised to have a look at it. Well, almost half a year later and after we&#8217;ve met again at pgconf.eu it is time to actually do that. You probably already know that citudata was acquired by Microsoft earlier this [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/","og_site_name":"dbi Blog","article_published_time":"2019-11-01T06:25:16+00:00","og_image":[{"width":1416,"height":514,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg","type":"image\/jpeg"}],"author":"Daniel Westermann","twitter_card":"summary_large_image","twitter_creator":"@westermanndanie","twitter_misc":{"Written by":"Daniel Westermann","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/"},"author":{"name":"Daniel Westermann","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"headline":"pg_auto_failover: Setup and installation","datePublished":"2019-11-01T06:25:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/"},"wordCount":586,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg","keywords":["pg_auto_failover","PostgreSQL"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/","url":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/","name":"pg_auto_failover: Setup and installation - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg","datePublished":"2019-11-01T06:25:16+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Selection_236.jpg","width":1416,"height":514},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/pg_auto_failover-setup-and-installation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"pg_auto_failover: Setup and installation"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66","name":"Daniel Westermann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","caption":"Daniel Westermann"},"description":"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.","sameAs":["https:\/\/x.com\/westermanndanie"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/12891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=12891"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/12891\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/12892"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=12891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=12891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=12891"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=12891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}