File: pg_autoctl_do_tmux.rst

package info (click to toggle)
pg-auto-failover 2.0-2
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 5,156 kB
  • sloc: ansic: 58,245; python: 5,501; sql: 3,171; makefile: 593; sh: 35
file content (133 lines) | stat: -rw-r--r-- 4,910 bytes parent folder | download
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
.. _pg_autoctl_do_tmux:

pg_autoctl do tmux
==================

pg_autoctl do tmux - Set of facilities to handle tmux interactive sessions

Synopsis
--------

pg_autoctl do tmux provides the following commands::

  pg_autoctl do tmux
  + compose  Set of facilities to handle docker-compose sessions
    script   Produce a tmux script for a demo or a test case (debug only)
    session  Run a tmux session for a demo or a test case
    stop     Stop pg_autoctl processes that belong to a tmux session
    wait     Wait until a given node has been registered on the monitor
    clean    Clean-up a tmux session processes and root dir

  pg_autoctl do tmux compose
    config   Produce a docker-compose configuration file for a demo
    script   Produce a tmux script for a demo or a test case (debug only)
    session  Run a tmux session for a demo or a test case


Description
-----------

An easy way to get started with pg_auto_failover in a localhost only
formation with three nodes is to run the following command::

  $ PG_AUTOCTL_DEBUG=1 pg_autoctl do tmux session \
       --root /tmp/pgaf    \
       --first-pgport 9000 \
       --nodes 4           \
       --layout tiled

This requires the command ``tmux`` to be available in your PATH. The
``pg_autoctl do tmux session`` commands prepares a self-contained root
directory where to create pg_auto_failover nodes and their configuration,
then prepares a tmux script, and then runs the script with a command such as::

  /usr/local/bin/tmux -v start-server ; source-file /tmp/pgaf/script-9000.tmux

The tmux session contains a single tmux window multiple panes:

 - one pane for the monitor
 - one pane per Postgres nodes, here 4 of them
 - one pane for running ``pg_autoctl watch``
 - one extra pane for an interactive shell.

Usually the first two commands to run in the interactive shell, once the
formation is stable (one node is primary, the other ones are all secondary),
are the following::

  $ pg_autoctl get formation settings
  $ pg_autoctl perform failover

Using docker-compose to run a distributed system
------------------------------------------------

The same idea can also be implemented with docker-compose to run the nodes,
and still using tmux to have three control panels this time:

 - one pane for the docker-compose cumulative logs of all the nodes
 - one pane for running ``pg_autoctl watch``
 - one extra pane for an interactive shell.

For this setup, you can use the following command::

  PG_AUTOCTL_DEBUG=1 pg_autoctl do tmux compose session \
         --root ./tmux/citus           \
         --first-pgport 5600           \
         --nodes 3                     \
         --async-nodes 0               \
         --node-priorities 50,50,0     \
         --sync-standbys -1            \
         --citus-workers 4             \
         --citus-secondaries 0         \
         --citus                       \
         --layout even-vertical

The ``pg_autoctl do tmux compose session`` command also takes care of
creating external docker volumes and referencing them for each node in the
docker-compose file.

.. _pg_autoctl_do_tmux_session:

pg_autoctl do tmux session
--------------------------

This command runs a tmux session for a demo or a test case.

::

   usage: pg_autoctl do tmux session [option ...]

     --root              path where to create a cluster
     --first-pgport      first Postgres port to use (5500)
     --nodes             number of Postgres nodes to create (2)
     --async-nodes       number of async nodes within nodes (0)
     --node-priorities   list of nodes priorities (50)
     --sync-standbys     number-sync-standbys to set (0 or 1)
     --skip-pg-hba       use --skip-pg-hba when creating nodes
     --citus             start a Citus formation
     --citus-workers     number of Citus workers to create (2)
     --citus-secondaries number of Citus secondaries to create (0)
     --layout            tmux layout to use (even-vertical)
     --binpath           path to the pg_autoctl binary (current binary path)


.. _pg_autoctl_do_tmux_compose_session:

pg_autoctl do tmux compose session
----------------------------------

This command runs a tmux session for a demo or a test case. It generates a
docker-compose file and then uses docker-compose to drive many nodes.

::

   usage: pg_autoctl do tmux compose session [option ...]

     --root            path where to create a cluster
     --first-pgport    first Postgres port to use (5500)
     --nodes           number of Postgres nodes to create (2)
     --async-nodes     number of async nodes within nodes (0)
     --node-priorities list of nodes priorities (50)
     --sync-standbys   number-sync-standbys to set (0 or 1)
     --skip-pg-hba     use --skip-pg-hba when creating nodes
     --layout          tmux layout to use (even-vertical)
     --binpath         path to the pg_autoctl binary (current binary path)