pg_hba_file_rules

一个系统目录视图,提供 pg_hba.conf 内容的摘要。

pg_hba_file_rules 是一个提供 pg_hba.conf 内容摘要的系统目录视图。

pg_hba_file_rulesPostgreSQL 10 中添加。

用法

pg_hba_file_rules 提供了 pg_hba.conf 当前内容的解释,而不是应用的设置(截至 PostgreSQL 14 无法获得)。它也没有提供任何关于规则如何应用的指示,仅仅是它们是否可以被解析。

按 PostgreSQL 版本定义

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

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

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

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

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

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

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

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    |           |          |
    

文档: pg_hba_file_rules

更改历史

示例

给定一个简单的 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"

分类

身份验证配置用户和角色

参见

pg_hba.confpg_file_settings

反馈

提交任何关于 "pg_hba_file_rules" 的评论、建议或更正 此处