ubuntu 22.04安装postgresql


安装
sudo apt install postgresql

修改
/etc/postgresql/14/main/postgresql.conf
把 listen_addresses = '127.0.0.1'
修改为 listen_addresses = '*'


/etc/postgresql/14/main/pg_hba.conf
添加
host all all 0.0.0.0/0 md5
放到最上面

重启postgresql
sudo systemctl restart postgresql


创建用户
从root 用户切换到 postgres
su postgres
然后
psql
然后创建用户
create user postgres2 with NOSUPERUSER CREATEDB CREATEROLE LOGIN PASSWORD '123456';

这个时候就可以用ip+端口(5432)+用户(postgres2) + 密码(123456) 远程登录了。
如果不好使,可以关注一下防火墙是否允许

 

参考

https://www.postgresql.org/docs/14/sql-createuser.html

https://www.postgresql.org/docs/14/auth-pg-hba-conf.html

https://www.postgresql.org/docs/14/runtime-config-connection.html

 

posted on 2023-04-20 09:25  cococooder  阅读(141)  评论(0编辑  收藏  举报