淘先锋技术网

首页 1 2 3 4 5 6 7

postgresql 数据库小版本更新

记录一次pg小版本更新

前言

因为最近漏扫发现好多漏洞,需要升级pg数据库的版本用以解决漏洞问题,有些数据库不能升级大版本,只能升级小版本,网上全是讲的编译安装的,我在这里说说rpm安装如何升级。

一.下载最新的pg版本 pg11(11.18)

  1. 官网下载地址:
    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

官网直接下载

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

安装

sudo yum install -y postgresql11-server
  1. 自己下载安装包及依赖
    需要下载4个对应版本的rpm包。

下载地址:
https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/
在这里插入图片描述
已下载好的文件地址:pg11.18的资源
https://download.csdn.net/download/yang_z_1/87432521

把下载包放到一个目录下,上传到所需的Linux服务器
在文件目录下执行

yum localinstall *.rpm -y
[root@hrmw-template pg11.18]# yum localinstall *.rpm -y
Loaded plugins: fastestmirror
Examining postgresql11-11.18-1PGDG.rhel7.x86_64.rpm: postgresql11-11.18-1PGDG.rhel7.x86_64
Marking postgresql11-11.18-1PGDG.rhel7.x86_64.rpm as an update to postgresql11-11.5-1PGDG.rhel7.x86_64
Examining postgresql11-contrib-11.18-1PGDG.rhel7.x86_64.rpm: postgresql11-contrib-11.18-1PGDG.rhel7.x86_64
Marking postgresql11-contrib-11.18-1PGDG.rhel7.x86_64.rpm as an update to postgresql11-contrib-11.5-1PGDG.rhel7.x86_64
Examining postgresql11-libs-11.18-1PGDG.rhel7.x86_64.rpm: postgresql11-libs-11.18-1PGDG.rhel7.x86_64
Marking postgresql11-libs-11.18-1PGDG.rhel7.x86_64.rpm as an update to postgresql11-libs-11.5-1PGDG.rhel7.x86_64
Examining postgresql11-server-11.18-1PGDG.rhel7.x86_64.rpm: postgresql11-server-11.18-1PGDG.rhel7.x86_64
Marking postgresql11-server-11.18-1PGDG.rhel7.x86_64.rpm as an update to postgresql11-server-11.5-1PGDG.rhel7.x86_64
Resolving Dependencies
--> Running transaction check
---> Package postgresql11.x86_64 0:11.5-1PGDG.rhel7 will be updated
---> Package postgresql11.x86_64 0:11.18-1PGDG.rhel7 will be an update
---> Package postgresql11-contrib.x86_64 0:11.5-1PGDG.rhel7 will be updated
---> Package postgresql11-contrib.x86_64 0:11.18-1PGDG.rhel7 will be an update
---> Package postgresql11-libs.x86_64 0:11.5-1PGDG.rhel7 will be updated
---> Package postgresql11-libs.x86_64 0:11.18-1PGDG.rhel7 will be an update
---> Package postgresql11-server.x86_64 0:11.5-1PGDG.rhel7 will be updated
---> Package postgresql11-server.x86_64 0:11.18-1PGDG.rhel7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package               Arch    Version               Repository                                       Size
===========================================================================================================
Updating:
 postgresql11          x86_64  11.18-1PGDG.rhel7     /postgresql11-11.18-1PGDG.rhel7.x86_64          8.9 M
 postgresql11-contrib  x86_64  11.18-1PGDG.rhel7     /postgresql11-contrib-11.18-1PGDG.rhel7.x86_64  2.1 M
 postgresql11-libs     x86_64  11.18-1PGDG.rhel7     /postgresql11-libs-11.18-1PGDG.rhel7.x86_64     1.4 M
 postgresql11-server   x86_64  11.18-1PGDG.rhel7     /postgresql11-server-11.18-1PGDG.rhel7.x86_64    19 M

Transaction Summary
===========================================================================================================
Upgrade  4 Packages

Total size: 31 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : postgresql11-libs-11.18-1PGDG.rhel7.x86_64                                              1/8 
  Updating   : postgresql11-11.18-1PGDG.rhel7.x86_64                                                   2/8 
  Updating   : postgresql11-server-11.18-1PGDG.rhel7.x86_64                                            3/8 
  Updating   : postgresql11-contrib-11.18-1PGDG.rhel7.x86_64                                           4/8 
  Cleanup    : postgresql11-server-11.5-1PGDG.rhel7.x86_64                                             5/8 
  Cleanup    : postgresql11-contrib-11.5-1PGDG.rhel7.x86_64                                            6/8 
  Cleanup    : postgresql11-11.5-1PGDG.rhel7.x86_64                                                    7/8 
  Cleanup    : postgresql11-libs-11.5-1PGDG.rhel7.x86_64                                               8/8 
  Verifying  : postgresql11-libs-11.18-1PGDG.rhel7.x86_64                                              1/8 
  Verifying  : postgresql11-contrib-11.18-1PGDG.rhel7.x86_64                                           2/8 
  Verifying  : postgresql11-server-11.18-1PGDG.rhel7.x86_64                                            3/8 
  Verifying  : postgresql11-11.18-1PGDG.rhel7.x86_64                                                   4/8 
  Verifying  : postgresql11-server-11.5-1PGDG.rhel7.x86_64                                             5/8 
  Verifying  : postgresql11-contrib-11.5-1PGDG.rhel7.x86_64                                            6/8 
  Verifying  : postgresql11-11.5-1PGDG.rhel7.x86_64                                                    7/8 
  Verifying  : postgresql11-libs-11.5-1PGDG.rhel7.x86_64                                               8/8 

Updated:
  postgresql11.x86_64 0:11.18-1PGDG.rhel7            postgresql11-contrib.x86_64 0:11.18-1PGDG.rhel7      
  postgresql11-libs.x86_64 0:11.18-1PGDG.rhel7       postgresql11-server.x86_64 0:11.18-1PGDG.rhel7       

Complete!

二 pg11.5 升级 pg11.18过程

1. 查看当前数据库版本:

在这里插入图片描述

2. 关闭pg11.5数据库

3. 安装pg11.18

yum localinstall *.rpm -y

这步在上面已经做过了。

4.修改 配置文件

使用root用户修改 /usr/lib/systemd/system/postgresql-11.service 文件,将其中的PGDATA修改为新的数据目录

vim  /usr/lib/systemd/system/postgresql-11.service

把Environment=PGDATA=修改你pg11.5的安装目录;
修改前:
在这里插入图片描述
修改后:

在这里插入图片描述

5. 重新加载配置文件

systemctl daemon-reload

6. 启动数据库

7. 查看数据库版本

在这里插入图片描述

在这里插入图片描述

后记

如果本文章有何错误,请您评论中指出,或联系我,我会改正,如果您觉得这篇文章有用,请帮忙一键三连,让更多的人看见,谢谢
作者 yang_z_1 csdn博客地址:
https://blog.csdn.net/yang_z_1?type=blog