centos7 安装 postgresql12-server

# 添加仓库。官方仓库,国内速度还可以。
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y

# 从仓库安装:server,以及它的依赖:libs、client(psql) 等,并自动新建了一个linux用户:postgres。
yum install postgresql12-server -y

# 初始化仓库。/var/lib/pgsql/12/data 这个空目录被填满(包含配置文件 pg_hba.conf、postgresql.conf 等)。默认数据库:postgres(和用户名一样的字符串)。默认库没有设置密码(远程登陆需要设置密码)。
/usr/pgsql-12/bin/postgresql-12-setup initdb

# 编辑配置文件 pg_hba.conf。在最后面新增一行
host all all 0.0.0.0/0 md5
# 最后一列的可选项为以下释义
# reject 拒绝登陆
# trust 不要密码登陆
# ident 系统与库的映射用户不要密码登陆
# md5 库用户密码加密登陆
# password 库用户密码明文登陆

# 编辑配置文件 postgresql.conf 。搜索 listen_addresses,修改为:
listen_addresses = '*'

# 启动服务
systemctl start postgresql-12

# 切换用户(安装时自动建立的)。
cd / && su postgres

# 进入客户端。
psql

# 设置密码。(默认库名、用户名、密码都是同一个字符串)
alter user postgres with password 'postgres';

# 退出客户端。
\q

# 用三方客户端,例如:Navicat 等,登陆成功。

你可能感兴趣的:(centos7 安装 postgresql12-server)