PostgreSQL pg_autoctl / pg_atuo_failover commands
configuration related commands:
-bash-4.2$ pg_autoctl config check
16:25:57 30701 INFO Postgres setup for PGDATA "/var/lib/pgsql/14/data" is ok, running with PID 5432 and port 3193
16:25:57 30701 INFO Connection to local Postgres ok, using "port=5432 dbname=pg_auto_failover host=/run/postgresql user=autoctl_node"
pgdata: /var/lib/pgsql/14/data
pg_ctl: /usr/pgsql-14/bin/pg_ctl
pg_version: "14.11" (1411)
pghost: /run/postgresql
pgport: 5432
proxyport: 0
pid: 3193
is in recovery: no
Control cluster state: in production
Control Version: 1300
Catalog Version: 202107181
System Identifier: 7349600518161216196
Latest checkpoint LSN: 0/3EBDB48
Postmaster status: ready
-bash-4.2$ pg_autoctl config get
[pg_autoctl]
role = monitor
hostname = admin01.localdomain
[postgresql]
pgdata = /var/lib/pgsql/14/data
pg_ctl = /usr/pgsql-14/bin/pg_ctl
username = autoctl_node
dbname = pg_auto_failover
host = /run/postgresql
port = 5432
listen_addresses = *
auth_method = trust
[ssl]
sslmode = require
active = 1
cert_file = /var/lib/pgsql/14/data/server.crt
key_file = /var/lib/pgsql/14/data/server.key
to set/modify the configuration, use set parameter.
-bash-4.2$ pg_autoctl config set
16:28:31 32762 ERROR Two arguments are expected, found 0
-bash-4.2$ pg_autoctl config set --help
pg_autoctl config set: Set the value of a given pg_autoctl configuration variable
usage: pg_autoctl config set [ --pgdata ] [ --json ] section.option [ value ]
--pgdata path to data directory
-bash-4.2$ pg_autoctl show settings
Context | Name | Setting | Value
----------+---------+---------------------------+-------------------------------------------------------------
formation | default | number_sync_standbys | 0
primary | node_1 | synchronous_standby_names | 'ANY 1 (pgautofailover_standby_3, pgautofailover_standby_2)'
node | node_1 | candidate priority | 50
node | node_2 | candidate priority | 50
node | node_3 | candidate priority | 70
node | node_1 | replication quorum | true
node | node_2 | replication quorum | true
node | node_3 | replication quorum | true
Replication verfication commands:
-bash-4.2$ pg_autoctl show uri
Type | Name | Connection String
-------------+---------+-------------------------------
monitor | monitor | postgres://autoctl_node@admin01.localdomain:5432/pg_auto_failover?sslmode=require
formation | default | postgres://rep01.localdomain:5432,rep02.localdomain:5432,master01.localdomain:5432/autodb?target_session_attrs=read-write&sslmode=require
-bash-4.2$ pg_autoctl show events
Event Time | Node | Current State | Assigned State | Comment
-------------------------------+--------+---------------------+---------------------+-----------
2024-03-25 16:12:25.804573+00 | 0/2 | secondary | catchingup | Node node 2 "node_2" (rep01.localdomain:5432) is marked as healthy by the monitor
2024-03-25 16:12:26.612818+00 | 0/2 | catchingup | catchingup | New state is reported by node 2 "node_2" (rep01.localdomain:5432): "catchingup"
2024-03-25 16:12:26.612818+00 | 0/2 | catchingup | secondary | Setting goal state of node 2 "node_2" (rep01.localdomain:5432) to secondary after it caught up.
2024-03-25 16:12:26.778657+00 | 0/2 | secondary | secondary | New state is reported by node 2 "node_2" (rep01.localdomain:5432): "secondary"
2024-03-25 16:12:26.847366+00 | 0/1 | wait_primary | primary | Setting goal state of node 1 "node_1" (master01.localdomain:5432) to primary now that we have 1 healthy secondary nodes in the quorum.
2024-03-25 16:12:27.014049+00 | 0/1 | primary | primary | New state is reported by node 1 "node_1" (master01.localdomain:5432): "primary"
2024-03-25 16:12:50.808192+00 | 0/3 | secondary | catchingup | Node node 3 "node_3" (rep02.localdomain:5432) is marked as healthy by the monitor
2024-03-25 16:12:51.572948+00 | 0/3 | catchingup | catchingup | New state is reported by node 3 "node_3" (rep02.localdomain:5432): "catchingup"
2024-03-25 16:12:51.572948+00 | 0/3 | catchingup | secondary | Setting goal state of node 3 "node_3" (rep02.localdomain:5432) to secondary after it caught up.
2024-03-25 16:12:51.716066+00 | 0/3 | secondary | secondary | New state is reported by node 3 "node_3" (rep02.localdomain:5432): "secondary"
-bash-4.2$ pg_autoctl show state
Name | Node | Host:Port | TLI: LSN | Connection | Reported State | Assigned State
-------+-------+---------------------------+----------------+--------------+---------------------+--------------------
node_1 | 1 | master01.localdomain:5432 | 6: 0/9000520 | read-write | primary | primary
node_2 | 2 | rep01.localdomain:5432 | 6: 0/9000520 | read-only | secondary | secondary
node_3 | 3 | rep02.localdomain:5432 | 6: 0/9000000 | read-only | secondary | secondary
-bash-4.2$ pg_autoctl show standby-names
'ANY 1 (pgautofailover_standby_3, pgautofailover_standby_2)'
-bash-4.2$ pg_autoctl show file
File | Path
--------+----------------
Config | /var/lib/pgsql/.config/pg_autoctl/var/lib/pgsql/14/data/pg_autoctl.cfg
Pid | /tmp/pg_autoctl/var/lib/pgsql/14/data/pg_autoctl.pid
Switchover commands:
-bash-4.2$ pg_autoctl perform switchover
16:35:04 6225 INFO Waiting 60 secs for a notification with state "primary" in formation "default" and group 0
16:35:04 6225 INFO Listening monitor notifications about state changes in formation "default" and group 0
16:35:04 6225 INFO Following table displays times when notifications are received
Time | Name | Node | Host:Port | Current State | Assigned State
---------+--------+-------+---------------------------+---------------------+--------------------
16:35:04 | node_1 | 1 | master01.localdomain:5432 | primary | draining
16:35:04 | node_1 | 1 | master01.localdomain:5432 | draining | draining
16:35:04 | node_1 | 1 | master01.localdomain:5432 | draining | report_lsn
16:35:04 | node_2 | 2 | rep01.localdomain:5432 | secondary | report_lsn
16:35:04 | node_3 | 3 | rep02.localdomain:5432 | secondary | report_lsn
16:35:05 | node_2 | 2 | rep01.localdomain:5432 | report_lsn | report_lsn
16:35:05 | node_3 | 3 | rep02.localdomain:5432 | report_lsn | report_lsn
16:35:05 | node_1 | 1 | master01.localdomain:5432 | report_lsn | report_lsn
16:35:05 | node_3 | 3 | rep02.localdomain:5432 | report_lsn | prepare_promotion
16:35:05 | node_3 | 3 | rep02.localdomain:5432 | prepare_promotion | prepare_promotion
16:35:05 | node_3 | 3 | rep02.localdomain:5432 | prepare_promotion | wait_primary
16:35:06 | node_2 | 2 | rep01.localdomain:5432 | report_lsn | join_secondary
16:35:06 | node_1 | 1 | master01.localdomain:5432 | report_lsn | join_secondary
16:35:06 | node_2 | 2 | rep01.localdomain:5432 | join_secondary | join_secondary
16:35:06 | node_1 | 1 | master01.localdomain:5432 | join_secondary | join_secondary
16:35:07 | node_3 | 3 | rep02.localdomain:5432 | wait_primary | wait_primary
16:35:07 | node_1 | 1 | master01.localdomain:5432 | join_secondary | secondary
16:35:07 | node_2 | 2 | rep01.localdomain:5432 | join_secondary | secondary
16:35:07 | node_2 | 2 | rep01.localdomain:5432 | secondary | secondary
16:35:07 | node_3 | 3 | rep02.localdomain:5432 | wait_primary | primary
16:35:07 | node_3 | 3 | rep02.localdomain:5432 | primary | primary
To watch the live replication status:
bash-4.2$ pg_autoctl watch
Other operational commands:
-bash-4.2$ pg_autoctl watch
-bash-4.2$ pg_autoctl status
16:50:08 18772 INFO pg_autoctl is running with pid 3180
16:50:08 18772 INFO Postgres is serving PGDATA "/var/lib/pgsql/14/data" on port 5432 with pid 3193
-bash-4.2$ pg_autoctl reload
-bash-4.2$ pg_autoctl version
pg_autoctl version 1.6.3
pg_autoctl extension version 1.6
compiled with PostgreSQL 14.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
compatible with Postgres 10, 11, 12, 13, and 14
-bash-4.2$ pg_autoctl stop
-bash-4.2$ pg_autoctl status
16:50:56 19266 INFO pg_autoctl is not running at "/var/lib/pgsql/14/data"
-bash-4.2$ pg_autoctl show state
16:51:03 19274 ERROR Failed to open file "/var/lib/pgsql/14/data/postmaster.pid": No such file or directory
16:51:03 19274 INFO Is PostgreSQL at "/var/lib/pgsql/14/data" up and running?
16:51:03 19274 ERROR Failed to get Postgres pid, see above for details
16:51:03 19274 FATAL Failed to discover PostgreSQL setup, please fix previous errors.
16:51:03 19274 FATAL Failed to read configuration file "/var/lib/pgsql/.config/pg_autoctl/var/lib/pgsql/14/data/pg_autoctl.cfg"
-bash-4.2$ nohup pg_autoctl run &
[1] 19288
-bash-4.2$ nohup: ignoring input and appending output to ‘nohup.out’
-bash-4.2$ pg_autoctl show state
Name | Node | Host:Port | TLI: LSN | Connection | Reported State | Assigned State
-------+-------+---------------------------+----------------+--------------+---------------------+--------------------
node_1 | 1 | master01.localdomain:5432 | 7: 0/9000810 | read-only | secondary | secondary
node_2 | 2 | rep01.localdomain:5432 | 7: 0/9000810 | read-only | secondary | secondary
node_3 | 3 | rep02.localdomain:5432 | 7: 0/9000810 | read-write | primary | primary
Comments
Post a Comment