PostgreSQL9.3Beta1:新增 pg_isready 测试工具

PostgreSQL9.3 将新增 pg_isready 客户端工具,用来测试 PostgreSQL 服务连接状态。运行 pg_isready 命令后,产生以下四种返回结果之一:

  • 0: 服务能正常响应连接;
  • 1: 服务拒绝连接(比如 PostgreSQL 启动过程中);
  • 2: 服务收不到连接响应;
  • 3: 没有尝试连接(例如 输入非法连接参数)

根据以上返回结果,简单测试下。

pg_isready 参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[pg93@server1 tf]$ pg_isready --help
pg_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, then exit
-?, --help show this help, then exit

Connection 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 database username

Report bugs to <pgsql-bugs@postgresql.org>.

连接正常

1
2
3
4
5
[pg93@server1 tf]$ pg_isready -h 127.0.0.1 -p 1925
127.0.0.1:1925 - accepting connections

[pg93@server1 tf]$ echo $?
0

连接无响应

1
2
3
4
5
[pg93@server1 tf]$ pg_isready -h 127.0.0.1 -p 1922
127.0.0.1:1922 - no response

[pg93@server1 tf]$ echo $?
2

连接参数不对

[pg93@server1 tf]$ pg_isready -h 127.0.0.1 -a
pg_isready: invalid option -- a
Try "pg_isready --help" for more information.

[pg93@server1 tf]$ echo $?
3

总结

显然用 pg_isready 探测 PostgreSQL 服务状态非常简单,容易,这比其它探测方式,例如 select 1 要好些。

参考

原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/237964.html

(0)
上一篇 2022年1月29日
下一篇 2022年1月29日

相关推荐

发表回复

登录后才能评论