$ git clone https://github.com/lesovsky/postgresql-monitoring-book.git
$ cd postgresql-monitoring-book/playground
$ make help
Makefile available targets:
* help Display this help screen
* up Start playground environment
* ps Show current status of playground services
* down Stop playground environment (without cleanup)
* destroy Stop playground environment and clean up related resources
* %/logs Show service logs; % - service name, e.g. primary or standby
* %/logs/tail Tail service logs; % - service name, e.g. primary or standby
* %/shell Start shell session; % - service name, e.g. primary or standby
* %/psql Start psql session; % - service name, e.g. primary or standby
* %/pgcenter Start pgcenter session; % - service name, e.g. primary or standby
make 目标提供了启动和停止测试环境、连接容器中服务的简便方式,后续操作会用到这些目标。执行目标时,第一行会输出实际执行的命令,因此无需使用 Makefile,也可以直接执行该命令。
所有容器的 STATUS 字段都应为 running。两个数据库服务都应显示已准备好接受客户端连接,两个节点之间的复制也应正常工作。可以这样检查主节点的服务器日志:
$ make primary/logs
...
primary_1 | 2022-03-03 08:57:44 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
primary_1 | 2022-03-03 08:57:44 UTC [1] LOG: listening on IPv6 address "::", port 5432
primary_1 | 2022-03-03 08:57:44 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
primary_1 | 2022-03-03 08:57:44 UTC [63] LOG: database system was shut down at 2022-03-03 08:57:44 UTC
primary_1 | 2022-03-03 08:57:44 UTC [1] LOG: database system is ready to accept connections
备用节点也可以用类似的方法检查:
$ make standby/logs
...
standby_1 | 2022-03-03 08:57:50 UTC [24] LOG: consistent recovery state reached at 0/11000100
standby_1 | 2022-03-03 08:57:50 UTC [1] LOG: database system is ready to accept read-only connections
standby_1 | 2022-03-03 08:57:50 UTC [28] LOG: started streaming WAL from primary at 0/12000000 on timeline 1
现在启动连接到集群主节点的会话,作为可用性检查:
$ make primary/psql
psql (15.0)
Type "help" for help.
postgres=#
在打开的会话中,可以向服务器发送 SQL 查询:
postgres=# SELECT * FROM pg_stat_activity;
...
postgres=# SELECT * FROM pg_stat_replication;
...