Ubuntu 安装postgresql

一、安装

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
# 如果需要指定版本可以使用postgresql-12
$ sudo apt-get -y install postgresql

二、配置默认用的密码

$ sudo su - postgres # 切换到postgres用户
$ psql -U postgres # 使用postgres登录数据库
# 修改用户密码
> ALTER USER postgres WITH PASSWORD '123456';

pg_hba.conf

将peer修改为md5,同时添加一行配置可以远程连接数据库

host    all             all             0.0.0.0/0               md5
# Database administrative login by Unix domain socket
local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             0.0.0.0/0               md5
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     md5
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

三、重启postgres

$ sudo systemctl restart postgresql
posted @ 2022-11-19 15:53  我爱这世间美貌女子  阅读(239)  评论(0编辑  收藏  举报