pg_isready 簡介
此功能類似 Oracle 的 tnsping
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | node1-@[postgres]:/home/postgres>pg_isready --helppg_isready issues a connection check to a PostgreSQL database.Usage:  pg_isready [OPTION]...Options:  -d, --dbname=DBNAME      database name  -q, --quiet              run quietly  -V, --version            output version information, thenexit  -?, --help               show this help, thenexitConnection options:  -h, --host=HOSTNAME      database server host or socket directory  -p, --port=PORT          database server port  -t, --timeout=SECS       seconds to wait when attempting connection, 0 disables (default: 3)  -U, --username=USERNAME  user name to connect as | 
示例
pg_hba.conf
| 1 | host    all        all        0.0.0.0/0trust | 
postgresql.conf
| 1 | listen_addresses = '*' | 
重啟 PG
| 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 | [root@node1 pg_data]# systemctl stop postgresql-12[root@node1 pg_data]# systemctl start postgresql-12[root@node1 pg_data]# systemctl status postgresql-12● postgresql-12.service - PostgreSQL database server   Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; enabled; vendor preset: disabled)   Active: active (running) since Sat 2020-08-15 02:06:19 EDT; 5s ago  Process: 2044 ExecStop=/opt/pgsql/bin/pg_ctlstop -D ${PGDATA} -s -m fast (code=exited, status=0/SUCCESS)  Process: 2052 ExecStart=/opt/pgsql/bin/pg_ctlstart -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS) Main PID: 2054 (postgres)   CGroup: /system.slice/postgresql-12.service           ├─2054 /opt/pgsql/bin/postgres-D /data/pg_data-p 5432           ├─2055 postgres: logger              ├─2057 postgres: checkpointer              ├─2058 postgres: background writer              ├─2059 postgres: walwriter              ├─2060 postgres: autovacuum launcher              ├─2061 postgres: stats collector              └─2062 postgres: logical replication launcher   Aug 15 02:06:18 node1 systemd[1]: Starting PostgreSQL database server...Aug 15 02:06:18 node1 pg_ctl[2052]: 2020-08-15 02:06:18.980 EDT [2054] LOG:  starting PostgreSQL 12.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4...9), 64-bitAug 15 02:06:18 node1 pg_ctl[2052]: 2020-08-15 02:06:18.981 EDT [2054] LOG:  listening on IPv4 address "0.0.0.0", port 5432Aug 15 02:06:18 node1 pg_ctl[2052]: 2020-08-15 02:06:18.981 EDT [2054] LOG:  listening on IPv6 address "::", port 5432Aug 15 02:06:18 node1 pg_ctl[2052]: 2020-08-15 02:06:18.983 EDT [2054] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"Aug 15 02:06:18 node1 pg_ctl[2052]: 2020-08-15 02:06:18.992 EDT [2054] LOG:  redirecting log output to logging collector processAug 15 02:06:18 node1 pg_ctl[2052]: 2020-08-15 02:06:18.992 EDT [2054] HINT:  Future log output will appear indirectory "log".Aug 15 02:06:19 node1 systemd[1]: Started PostgreSQL database server.Hint: Some lines were ellipsized, use -l to show infull.[root@node1 pg_data]# | 
pg_isready 測試
| 1 2 3 | node1-@[postgres]:/data/pg_data>pg_isready -h 192.168.66.63 -p 5432192.168.66.63:5432 - accepting connectionsnode1-@[postgres]:/data/pg_data> | 
來自 “ ITPUB博客 ” ,鏈接://blog.itpub.net/31490526/viewspace-2711966/,如需轉載,請注明出處,否則將追究法律責任。