PostgreSQL Installation Guide

PostgreSQL 部署手册

安装

v13:CentOS 8

# Install the repository RPM:
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Disable the built-in PostgreSQL module:
dnf -qy module disable postgresql

# Install PostgreSQL:
dnf install -y postgresql13-server postgresql13-docs postgresql13-contrib

# 创建数据库实例/集群,否则 PostgreSQL 无法启动
/usr/pgsql-13/bin/postgresql-13-setup initdb

# 服务端配置文件中添加以下配置允许侦听远程连接
listen_addresses = '0.0.0.0'
# 或
listen_addresses = '*'

# 客户端认证配置文件中添加以下配置允许远程客户端密码连接
host    all             all             0.0.0.0/0               md5

# Enable automatic start:
systemctl enable postgresql-13 --now
# systemctl start postgresql-13

# 设置默认管理员 postgres 的密码,允许远程客户端可用密码访问
su - postgres
psql -c "alter user postgres with password 'postgres'"

相关文件及目录

PostgreSQL 使用 OID(Object Identifier)/ filenode 为文件名存储对象。

名称 目录
管理工具目录 /usr/pgsql-13/bin/
PGDATA 实例目录 /var/lib/pgsql/13/data/
服务端配置文件 PGDATA/postgresql.conf
权限配置文件 PGDATA/pg_hba.conf
表空间目录 PGDATA/pg_tblspc/
服务端日志目录 PGDATA/log/

v12:CentOS 8

sudo dnf module enable postgresql:12 -y
sudo dnf install postgresql-server -y

管理

PostgreSQL 通常以 postgres 用户启动,管理命令需用相同用户执行,切换到 postgres 用户后用以下语句指示在管理工具路径中匹配命令。

# 给 postgres 用户路由管理命令
echo "export PATH=/usr/pgsql-13/bin/:$PATH" >> ~/.bash_profile

pg_ctl

命令 作用
pg_ctl reload 重载配置文件
pg_ctl stop -m smart 无连接后关闭实例

安装包/源:macOSEL

客户端:PSequel

示例数据库:PagilaSakila

代码:Github

Author: njun
njun's picture
Updated: 2020/10/23