应用补丁
Oracle
# 1) Shut down the database, apply the binary patch with OPatch:
$ $ORACLE_HOME/OPatch/opatch apply
# 2) Open the database and load the SQL layer changes:
$ $ORACLE_HOME/OPatch/datapatch -verboseopatch apply 更新 Oracle Home 中的二进制文件;随后 datapatch 在打开的数据库上应用数据字典/SQL 变更,并记录到 dba_registry_sqlpatch 中。在 RAC 上,支持滚动安装的补丁可逐节点应用。
PostgreSQL
# Minor version patch = replace binaries + restart (no dump needed):
$ sudo systemctl stop postgresql-16
$ sudo dnf update postgresql16-server # or apt upgrade
$ sudo systemctl start postgresql-16同一大版本系列内的小版本补丁(16.3 -> 16.4)不会改变数据格式:更新软件包并重启服务即可;无需 pg_upgrade 或 dump/restore。
MySQL
# Minor/patch update: update the package and restart the service
$ sudo systemctl stop mysqld
$ sudo dnf update mysql-community-server # or apt upgrade
$ sudo systemctl start mysqldMySQL 8.0+ 在启动时自动升级数据字典;无需单独的 mysql_upgrade 步骤。在复制环境中,先给副本打补丁,再给源库打补丁。
SQL Server
-- Run the Cumulative Update (CU) or GDR security update installer:
-- SQLServer2022-KB<no>-x64.exe /quiet /IAcceptSQLServerLicenseTerms
-- /Action=Patch /InstanceName=MSSQLSERVER
-- The instance then restarts; verify the version with SERVERPROPERTY.CU(Cumulative Update)和 GDR(General Distribution Release)更新通过 setup 安装程序应用,需要重启实例。在 Always On 组中,先给辅助副本打补丁,再进行故障转移,以尽量缩短停机时间。
MongoDB
// 'Rolling' patch on a replica set: one node at a time
// 1) Stop mongod, replace the binary with the new patch version, restart
// 2) Secondaries first, the primary last
// Step down the primary manually before patching it:
rs.stepDown()同一大版本内的补丁更新(7.0.x)以滚动方式进行,先从节点。主节点在通过 rs.stepDown() 移交后再打补丁,从而尽量缩短写入停机时间。
Redis
# Patch via rolling restart in a replicated deployment:
# 1) Stop one replica node, install the new version, start it, wait for sync
# 2) Repeat for the remaining replicas
# 3) Finally, fail over the master and patch it:
redis-cli -h <replica> REPLICAOF NO ONE # promote the upgraded replica补丁版本(7.2.x)通过滚动重启应用:先升级副本并重新同步,然后将一个副本提升为 master,再给旧 master 打补丁。Sentinel/Cluster 可自动完成故障转移。
Elasticsearch
# Rolling upgrade (patch within the same major version), per node:
PUT _cluster/settings
{ "persistent": { "cluster.routing.allocation.enable": "primaries" } }
# -> stop the node, update the package, start the node, then:
PUT _cluster/settings
{ "persistent": { "cluster.routing.allocation.enable": null } }补丁/小版本升级通过滚动升级完成:限制分片分配,逐个更新并重启节点,然后重新启用分配,等待集群恢复为 green。