# 将 SELinux 设置为宽容模式
sudo setenforce Permissive
sudo vi /etc/selinux/config
SELINUX=permissive
# 关闭系统防火墙服务
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
# 安装 PostgreSQL 16 服务
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql16-server
# 自定义 PostgreSQL 16 服务数据目录
sudo mkdir -p /opt/var/lib/pgsql/16/data/
sudo mkdir /opt/var/lib/pgsql/16/backups/
sudo chown -R postgres:postgres /opt/var/lib/pgsql/
sudo chmod -R g-rx,o-rx /opt/var/lib/pgsql/
# 阿巴阿巴
sudo mkdir /etc/systemd/system/postgresql-16.service.d/
sudo cp /usr/lib/systemd/system/postgresql-16.service /etc/systemd/system/postgresql-16.service.d/override.conf
# 该命令会调用 Vim 编辑 "/etc/systemd/system/postgresql-16.service.d/override.conf" 文件。
sudo systemctl edit postgresql-16.service
# 请将 "Environment=PGDATA=/var/lib/pgsql/16/data/" 修改为 "Environment=PGDATA=/opt/var/lib/pgsql/16/data/"
# 并在 "ExecStart=/usr/pgsql-16/bin/postmaster -D ${PGDATA}" 行的上面添加一行,内容为 "ExecStart="
# 初始化数据库
echo '********' > /tmp/pwfile
sudo -u postgres /usr/pgsql-16/bin/initdb -A scram-sha-256 -D /opt/var/lib/pgsql/16/data -E UTF8 --pwfile=/tmp/pwfile ; rm -f /tmp/pwfile
# 修改 PostgreSQL 16 服务配置文件的 "max_connections" 参数的值
sudo vi /opt/var/lib/pgsql/16/data/postgresql.conf
max_connections = 256
sudo systemctl enable postgresql-16.service
sudo systemctl start postgresql-16.service
psql -U postgres
# 创建名为 "vbird" 的角色,并为其设置一个安全的密码。
# 创建属于 "vbird" 角色的同名数据库。
CREATE ROLE vbird LOGIN PASSWORD '********';
CREATE DATABASE vbird OWNER vbird;
# 退出 psql
\q
标签:PostgreSQL,lib,service,16,AlmaLinux,sudo,pgsql,postgresql
From: https://www.cnblogs.com/f0rsaken/p/18237421