# ubuntu22下配置postgresql远程访问

ubuntu22下配置postgresql远程访问

1、服务器监听地址, 默认只监听了127.0.0.1 ,要改成任意地址。

odoo@hxhome:~$ netstat -antl | grep 5432 | grep LISTEN
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN

cd  /etc/postgresql/14/main
vim postgresql.conf
找到下面这一行
#listen_addresses = 'localhost'          # what IP address(es) to listen on;
#去掉注释,将localhost改成*
listen_addresses = '*'          # what IP address(es) to listen on;

2、修改pg_hba.conf 文件

odoo@hxhome:/etc/postgresql/14/main$ vim pg_hba.conf

# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# 找到上面这一行, 在下面新增一行
host    all             all             192.168.0.0/16              scram-sha-256
# 这样配置就没问题了, 不过一开始测试的时候我改成0.0.0.0/32  这样不行,不知道是什么原因

3、重启服务

sudo systemctl restart postgresql

监听地址为任意地址了

odoo@hxhome:~/odoo16$ netstat -antpl | grep 5432 | grep LISTEN
(并非所有进程都能被检测到,所有非本用户的进程信息将不会显示,如果想看到所有信息,则必须切换到 root 用户)
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      -
tcp6       0      0 :::5432                 :::*                    LISTEN      -

用navicat连接测试成功。

你可能感兴趣的:(postgresql,postgresql,数据库)