环境:
系统:centos7.9
数据库:postgresql18beta1
#PostgreSQL 18 已转向 DocBook XML 构建体系(SGML 未来将被弃用)。需要安装 XML 工具链,如下:
yum install -y docbook5-style-xsl libxslt docbook-style-xsl xmlto fop
一、postgresql18beta1一键安装脚本如下,以root用户执行:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/bash
# 一键安装 PostgreSQL 18脚本
# 请先将 postgresql-18beta1.tar.gz 放在当前目录下,本脚本中上传至/root目录下
# 1. 创建 postgres 用户(如已存在则跳过)
if ! id postgres &>/dev/null; then
useradd postgres
echo "postgres" | passwd --stdin postgres 2>/dev/null || echo "postgres:postgres" | chpasswd
fi
# 2. 创建目录
mkdir -p /postgresql/{pg18,pgdata,arch,soft}
chown -R postgres. /postgresql/
chmod -R 700 /postgresql/
mv /root/postgresql-18beta1.tar.gz /postgresql/soft/
chown postgres. /postgresql/soft/postgresql-18beta1.tar.gz
# 3. 安装依赖
yum install -y docbook5-style-xsl libxslt docbook-style-xsl xmlto fop bison perl-ExtUtils-Embed readline-devel zlib-devel pam-devel tcl-devel libxml2-devel perl-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc gcc-c++ openssl-devel make cmake libicu libicu-devel flex wget
# 4. 解压并编译安装 PostgreSQL
su - postgres <<EOF
cd /postgresql/soft
tar zxvf postgresql-18beta1.tar.gz
cd postgresql-18beta1
./configure --prefix=/postgresql/pg18
make world && make install-world
EOF
# 5. 配置环境变量
su - postgres <<EOF
cat >> ~/.bash_profile <<'EOP'
export LANG=en_US.UTF-8
export PGHOME=/postgresql/pg18
export PGDATA=/postgresql/pgdata
export LD_LIBRARY_PATH=\$PGHOME/lib:\$LD_LIBRARY_PATH
export PATH=\$PGHOME/bin:\$PATH
EOP
source ~/.bash_profile
EOF
echo "PostgreSQL 18 安装完成。请以 postgres 用户登录并初始化数据库。"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
二、手动初始化数据库集簇
根据需要,修改postgresql.conf和pg_hba.conf,修改完成后,启动数据库。