postgresql小版本升级

2024-08-12  本文已影响0人  这货不是王马勺

本例为16.1升级至16.4
先下载对应Source code介质:

https://www.postgresql.org/download/

上传至服务器后解压:

tar -zxvf postgresql-14.6.tar.gz

升级前先做一个全备份(最好是pg_dump逻辑备份),之后检查版本等其他信息

su - postgres
psql
\q

然后停服务:

pg_ctl stop

查看postgresql用户环境变量:

[postgres@localhost ~]$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export PGHOME=/pgsql/postgresql

export PGDATA=/pgsql/postgresql/data

PATH=$PATH:$HOME/bin:$PGHOME/bin

补充安装一些依赖:

sudo yum install libicu-devel  readline-devel  perl-ExtUtils-Embed  python3 python3-dev  libxml2 libxml2-devel   libxslt libxslt-devel   -y

root用户下编译安装:

mkdir /usr/local/pgsql16.4
cd postgresql-16.4
./configure --prefix=/usr/local/pgsql16.4 --with-perl --with-python --with-libxml --with-libxslt --with-openssl
make && make install

更改属组:

chown -R postgres:postgres  /usr/local/pgsql16.4

拷贝原data目录到新版本数据库数据目录下:

su - postgresql
cd $PGHOME
cp -rf data  /usr/local/pgsql16.4/

改环境变量:

vim ~/.bash_profile

修改相关内容示例如下:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export PGHOME=/usr/local/pgsql16.4/

export PGDATA=$PGHOME/data

PATH=$PATH:$HOME/bin:$PGHOME/bin

生效:

source ~/.bash_profile

然后即可启动数据库并查看版本:

./pg_ctl start
./psql

检查版本已更新。

上一篇 下一篇

猜你喜欢

热点阅读