升级后任务(重新编译/分析)
Oracle
-- 1) Compile invalid objects in parallel:
@?/rdbms/admin/utlrp.sql
-- 2) Refresh dictionary/fixed object statistics:
EXEC DBMS_STATS.GATHER_DICTIONARY_STATS;
EXEC DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;
-- Check remaining invalid objects:
SELECT owner, object_name, object_type FROM dba_objects WHERE status='INVALID';utlrp.sql 会重新编译升级后变为 INVALID 的包/视图/触发器。之后收集数据字典和固定对象统计信息,可让优化器在新版本中生成合理的执行计划。
PostgreSQL
# 1) Regather statistics after pg_upgrade (mandatory):
$ vacuumdb --all --analyze-in-stages
-- 2) Bring extensions to the new version:
ALTER EXTENSION postgis UPDATE;
-- 3) If the collation changed, rebuild text indexes (can take long):
REINDEX DATABASE database_name;pg_upgrade(PG17 及更早版本)不会迁移规划器统计信息;analyze-in-stages 先收集粗略统计信息、再收集完整统计信息,使系统尽快可用。扩展必须通过 ALTER EXTENSION ... UPDATE 刷新;若排序规则(collation)发生变化,索引需执行 REINDEX。
MySQL
-- 8.0+ dictionary upgrade happens automatically at startup; additionally:
ANALYZE TABLE customer; -- refresh statistics of critical tables
-- Legacy 5.7 -> if needed on first startup:
-- $ mysql_upgrade -u root -p (before 8.0.16)在 MySQL 8.0.16 及更高版本中,mysql_upgrade 的功能已移入服务器,因此无需单独运行。升级后,对大型/关键表执行 ANALYZE TABLE 刷新统计信息可保持执行计划质量。
SQL Server
-- 1) Correct page/row usage counters:
DBCC UPDATEUSAGE(Sales);
-- 2) Refresh statistics (sp_updatestats uses sampling; FULLSCAN for critical tables):
EXEC sp_updatestats;
-- UPDATE STATISTICS dbo.CriticalTable WITH FULLSCAN;
-- 3) Raise the compatibility level to the new version (while monitoring):
ALTER DATABASE Sales SET COMPATIBILITY_LEVEL = 160;升级后,DBCC UPDATEUSAGE 可修正从旧版本带来的不准确的空间/行计数器,sp_updatestats 可刷新统计信息。提升兼容级别时,需监控新基数估算器(CE)可能导致的执行计划回归。
MongoDB
// 1) Verify the FCV upgrade:
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
// 2) Check indexes and compatibility warnings in the server logs:
db.customer.getIndexes()
// If an index is incompatible: dropIndex + createIndex (rolling); do NOT use reIndex大版本升级后,确认 FCV 已达到目标版本。重建索引不是常规的升级步骤;如果发行说明中点名了某个索引,或日志中出现相关警告,用 dropIndex + createIndex 重新创建。在 6.0+ 上,reIndex 仅在独立实例上可用,副本集成员上不允许。
Redis
# Usually no extra task is needed. Recommended: verify persistence and replication:
redis-cli INFO replication # is the master/replica link healthy
redis-cli INFO persistence # rdb_last_bgsave_status / aof_last_bgrewrite_status
redis-cli DBSIZE # is the key count as expectedRedis 升级后没有 schema 编译/分析任务;要做的是确认复制已重新建立、RDB/AOF 持久化正常且键数量未变。
Elasticsearch
# Verify cluster health:
GET _cluster/health
# Move indices created in an old major version that can no longer be read:
POST _reindex
{ "source": { "index": "old_index" }, "dest": { "index": "new_index" } }升级后,确认集群状态为 'green' 且所有分片均已分配。格式早于上一大版本的索引无法在新版本中读取,因此必须用 _reindex 迁移到当前格式。