postgresql安装部署

官网:https://www.postgresql.org/

方法一、yum源安装

 

 

官网选择对应的版本信息,复制官网的安装脚本:https://www.postgresql.org/download/linux/redhat/

 

 

 

方法二、源码编译安装

官网下载地址:https://www.postgresql.org/ftp/source/

下载安装包:wget https://ftp.postgresql.org/pub/source/v14.0/postgresql-14.0.tar.gz

1、安装依赖:

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
2、解压源码包

tar zxf postgresql-14.0.tar.gz

3、编译安装

cd postgresql-14.1
./configure --prefix=/usr/local/pgsql/postgresql
make && make install

  

4、创建用户、创建数据库主目录

useradd postgres
cd /usr/local/pgsql/postgresql
mkdir data && chown postgres:postgres data

  

5、配置环境变量

cat <<EOF >>/etc/profile
export PGHOME=/usr/local/pgsql/postgresql
export PGDATA=$PGHOME/data
export LD_LIBRARY_PATH=$PGHOME/lib
export PATH=$PATH:$PGHOME/bin
EOF

source /etc/profile

  

 

6、初始化并启动数据库

su - postgres
initdb
pg_ctl -D /usr/local/pgsql/postgresql/data -l logfile start

 

7、配置开机自启

注:源码包中postgresql-14.1/contrib/start-scripts/有启动脚本,修改其中的安装目录和数据库根目录

cp postgresql-14.1/contrib/start-scripts/linux /etc/init.d/postgresql
vi postgresql
prefix=pgsql/postgresql
PGDATA="/usr/local/pgsql/postgresql"
PGUSER=postgres
chkconfig --add postgresql
chkconfig

  

 

posted @ 2021-12-21 15:38  zk01  阅读(297)  评论(0编辑  收藏  举报