本文参考官方PG12安装步骤,欢迎查阅并研究https://www.postgresql.org/docs/12/install-getsource.html (PG officials)
1.官方下载PG12介质
Download from https://www.postgresql.org/download/
2. 创建必须目录以及用户
mkdir /opt/postgres /pgdata groupadd postgres useradd -g postgres postgres chown-R postgres:postgres /opt/postgres /pgdata
3. 系统参数优化
# 主要是hugepagesize设置以及kernel配置 /etc/sysctl.conf# 暂时略
4. 安装PG12
cd postgresql-12.4/ ./configure --prefix=/opt/postgres --enable-thread-safety--with-wal-blocksize=16--with-blocksize=16--enable-dtrace--enable-debugchown-R postgres:postgres /opt/postgres /pgdata gmake world gmake install-world
5. 初始化数据库
su- postgres cat >> /home/postgres/.bash_profile <<EOF exportPGPORT=5432exportPGDATA=/pgdata exportLANG=en_US.utf8 exportPGHOME=/posthome exportLD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH/lib:/usr/local/lib/usr64/local/lib exportPGDATABASE=postgres EOF initdb -D$PGDATA-E UTF8 --locale=C -U postgres -W
6. 启动数据库
pg_ctl -D$PAGDATAstart
7. 配置开机自启
#参考官方文档 https://www.postgresql.org/docs/12/server-start.html如果使用linux 6,则参考postgresql-12.4/contrib/start-scripts/linux 编辑对应的行即可 如果使用Linux 7 or onwards 则按如下操作 #注意根据环境,修改ExecStart为对应postgres以及data路径cat >>/etc/systemd/system/postgresql.service<<EOF [Unit] Description=PostgreSQL database server Documentation=man:postgres(1) [Service] Type=notify User=postgres ExecStart=/posthome/bin/postgres -D /pgdata ExecReload=/bin/kill -HUP \$MAINPID KillMode=mixed KillSignal=SIGINT TimeoutSec=0[Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable postgresql systemctl start postgresql systemctl status postgresql
7. 安装第三方插件
# 如果PG安装过程使用的是gmake && gmake install则需要手动按照如下操作安装扩展插件cd postgresql-12.4/contrib gmake && gmake install # 若有必要安装第三方插件,将对应插件解压之后按如下操作即可# Or for some special extension, you can install with following wayscd postgresql-12.4/contrib/expected_extension_name gmake && gmake install