PostgreSQL开启远程访问

TrumanWong
7/1/2024
TrumanWong

首先查看配置文件位置:

[postgres@localhost ~]$ psql
psql (16.3)
Type "help" for help.

postgres=# show config_file;
              config_file               
----------------------------------------
 /var/lib/pgsql/16/data/postgresql.conf
(1 row)

然后修改/var/lib/pgsql/16/data/postgresql.conf,修改listen_addresses配置:

listen_addresses = '*'					# what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)

接下来修改/var/lib/pgsql/16/data/pg_hba.conf,加入以下配置:

host    all             all             0.0.0.0/0               scram-sha-256

然后重启postgresql

$ sudo systemctl restart postgresql-16.service