安装步骤
- 安装RPM
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 安装客户端
yum install postgresql12
- 安装服务端
yum install postgresql12-server
配置步骤
- 始化数据库并启用自动启动 (可选)
# 初始化数据库
/usr/pgsql-12/bin/postgresql-12-setup initdb
# 设置开机启动pg服务
systemctl enable postgresql-12
# 启动pg服务
systemctl start postgresql-12
- 修改PostgreSQL远程连接配置
vim /var/lib/pgsql/12/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
#host all all 127.0.0.1/32 ident
host all all 127.0.0.1/32 trust
host all all all md5
# IPv6 local connections:
#host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication all peer
host replication all 127.0.0.1/32 trust
host replication all all md5
- 放开远程连接ip限制
vim /var/lib/pgsql/12/data/postgresql.conf
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
修改账号密码
- 修改postgres账号密码
psql -h 127.0.0.1 -d postgres -U postgres
alter user postgres with password 'postgres';
网友评论