File: install.rst

package info (click to toggle)
pg-auto-failover 2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,368 kB
  • sloc: ansic: 58,369; python: 5,515; sql: 3,177; makefile: 629; sh: 35
file content (138 lines) | stat: -rw-r--r-- 4,833 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
.. _install:

Installing pg_auto_failover
===========================

We provide native system packages for pg_auto_failover on most popular Linux
distributions.

Use the steps below to install pg_auto_failover on PostgreSQL 17. At the
current time pg_auto_failover is compatible with PostgreSQL 13 to 17.

Ubuntu or Debian
----------------

Postgres apt repository
~~~~~~~~~~~~~~~~~~~~~~~

Binary packages for debian and derivatives (ubuntu) are available from
`apt.postgresql.org`__ repository, install by following the linked
documentation and then::

  $ sudo apt-get install pg-auto-failover-cli
  $ sudo apt-get install postgresql-17-auto-failover

__ https://wiki.postgresql.org/wiki/Apt

The Postgres extension named "pgautofailover" is only necessary on the
monitor node. To install that extension, you can install the
``postgresql-17-auto-failover`` package when using Postgres 17. It's
available for other Postgres versions too.

Avoiding the default Postgres service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When installing the debian Postgres package, the installation script will
initialize a Postgres data directory automatically, and register it to the
systemd services. When using pg_auto_failover, it is best to avoid that step.

To avoid automated creation of a Postgres data directory when installing the
debian package, follow those steps:

::

  $ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
  $ echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list

  # bypass initdb of a "main" cluster
  $ echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf
  $ apt-get update
  $ apt-get install -y --no-install-recommends postgresql-17

That way when it's time to :ref:`pg_autoctl_create_monitor` or
:ref:`pg_autoctl_create_postgres` there is no confusion about how to handle
the default Postgres service created by debian: it has not been created at
all.

Fedora, CentOS, or Red Hat
--------------------------

The Postgres community packaging team for RPM based system has worked on
supporting pg_auto_failover. Binary packages are available by following the
documentation at `PostgreSQL Yum Repository`__.

__ https://yum.postgresql.org

A single package named ``pg_auto_failover`` is available on the RPM based
systems, containing both the monitor Postgres extension and the pg_autoctl
command line.

Installing a pgautofailover Systemd unit
----------------------------------------

The command ``pg_autoctl show systemd`` outputs a systemd unit file that you
can use to setup a boot-time registered service for pg_auto_failover on your
machine.

Here's a sample output from the command:

.. code-block:: bash

   $ export PGDATA=/var/lib/postgresql/monitor
   $ pg_autoctl show systemd
   13:44:34 INFO  HINT: to complete a systemd integration, run the following commands:
   13:44:34 INFO  pg_autoctl -q show systemd --pgdata "/var/lib/postgresql/monitor" | sudo tee /etc/systemd/system/pgautofailover.service
   13:44:34 INFO  sudo systemctl daemon-reload
   13:44:34 INFO  sudo systemctl start pgautofailover
   [Unit]
   Description = pg_auto_failover

   [Service]
   WorkingDirectory = /var/lib/postgresql
   Environment = 'PGDATA=/var/lib/postgresql/monitor'
   User = postgres
   ExecStart = /usr/lib/postgresql/17/bin/pg_autoctl run
   Restart = always
   StartLimitBurst = 0

   [Install]
   WantedBy = multi-user.target

Copy/pasting the commands given in the hint output from the command will
enable the pgautofailer service on your system, when using systemd.

It is important that PostgreSQL is started by ``pg_autoctl`` rather than by
systemd itself, as it might be that a failover has been done during a
reboot, for instance, and that once the reboot complete we want the local
Postgres to re-join as a secondary node where it used to be a primary node.


Building pg_auto_failover from sources
--------------------------------------

To build the project, make sure you have installed the build-dependencies,
then just type `make`. You can install the resulting binary using `make
install`.

For this to work please consider adding both the binary and the source
repositories to your debian distribution by using the following apt sources,
as an example targetting the debian bullseye distribution:

::

   deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main
   deb-src http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main

Then we can install the build dependencies for Postgres, knowing that
pg_auto_failover uses the same build dependencies:

::

   $ sudo apt-get build-dep -y --no-install-recommends postgresql-17

Then build pg_auto_failover from sources with the following instructions:

::

   $ make -s clean && make -s -j12 all
   $ sudo make -s install