pg_hba_file_rules 是一个 系统目录 视图,提供 pg_hba.conf 内容的摘要。
pg_hba_file_rules 在 PostgreSQL 10 中被添加。
用法
pg_hba_file_rules 提供对 pg_hba.conf 当前内容的解释,而不是已应用的设置(截至 PostgreSQL 14,已应用的设置不可用)。它也不会指示规则将如何被应用,仅仅表明它们是否可以被解析。
按 PostgreSQL 版本定义
pg_hba_file_rules (PostgreSQL 19)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
rule_number | integer | | |
file_name | text | | |
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 18)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
rule_number | integer | | |
file_name | text | | |
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 17)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
rule_number | integer | | |
file_name | text | | |
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 16)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
rule_number | integer | | |
file_name | text | | |
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 15)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 14)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 13)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 12)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 11)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
pg_hba_file_rules (PostgreSQL 10)
View "pg_catalog.pg_hba_file_rules"
Column | Type | Collation | Nullable | Default
-------------+---------+-----------+----------+---------
line_number | integer | | |
type | text | | |
database | text[] | | |
user_name | text[] | | |
address | text | | |
netmask | text | | |
auth_method | text | | |
options | text[] | | |
error | text | | |
变更历史
- PostgreSQL 10
- 添加(提交 de16ab72)
示例
给定一个简单的 pg_hba.conf 文件,例如(为简洁起见省略了 IPv6 行)
# TYPE DATABASE USER ADDRESS METHOD local all postgres trust host all postgres 127.0.0.1/32 trust host all postgres 192.168.0.0/16 trust # TYPE DATABASE USER ADDRESS METHOD local replication repuser trust host replication repuser 127.0.0.1/32 trust host replication repuser 192.168.0.0/16 trust
pg_hba_file_rules 将内容渲染如下:
postgres=# SELECT * FROM pg_hba_file_rules ;
line_number | type | database | user_name | address | netmask | auth_method | options | error
-------------+-------+---------------+------------+-------------+-----------------+-------------+---------+-------
2 | local | {all} | {postgres} | | | trust | |
3 | host | {all} | {postgres} | 127.0.0.1 | 255.255.255.255 | trust | |
4 | host | {all} | {postgres} | 192.168.0.0 | 255.255.0.0 | trust | |
7 | local | {replication} | {repuser} | | | trust | |
8 | host | {replication} | {repuser} | 127.0.0.1 | 255.255.255.255 | trust | |
9 | host | {replication} | {repuser} | 192.168.0.0 | 255.255.0.0 | trust | |
(6 rows)
添加一条无意义的行,例如:
# TYPE DATABASE USER ADDRESS METHOD foo !!! --- ()()()
将导致该行被报告为包含错误。
postgres=# SELECT * FROM pg_hba_file_rules WHERE error IS NOT NULL;
line_number | type | database | user_name | address | netmask | auth_method | options | error
-------------+------+----------+-----------+---------+---------+-------------+---------+-------------------------------
2 | | | | | | | | invalid connection type "foo"
参考资料
- PostgreSQL 文档: pg_hba_file_rules
