pg_upgrade

一个服务器实用程序,用于将 PostgreSQL 数据库集群进行二进制升级到新的主版本。

pg_upgrade 是一个 服务器实用程序,用于将 PostgreSQL 数据库集群进行二进制升级到新的主版本。

pg_upgradePostgreSQL 9.0 中被添加,最初是基于 pg_migrator 的一个 contrib 模块

源代码

pg_upgrade 的源代码位于 src/bin/pg_upgrade/

请参阅 src/bin/pg_upgrade/IMPLEMENTATION 获取其实现的技术描述。

变更历史

  • PostgreSQL 19
  • PostgreSQL 18
    • 添加了任务并行化框架(提交 40e2e5e9),为以下项目提供并行化:
    • 添加了对传输统计信息的支持(提交 1fd1bd87
    • 添加了 --swap 选项(提交 626d7236
  • PostgreSQL 17
    • 添加了选项 --sync-method(提交 8c16ad3b
    • 添加了对逻辑复制槽迁移的支持(提交 29d0a77f
    • 添加了 --copy-file-range 选项(提交 d93627bc
  • PostgreSQL 16
    • 添加了 --copy 选项(提交 746915c6
    • 区域设置和编码信息现在被复制到新集群(提交 9637badd
  • PostgreSQL 15
    • 添加了 -N/--no-sync 选项(提交 3d5ffccb
    • 保留了 filenodetablespace 的 OID(提交 9a974cbc)。
    • 保留了 postgrestemplate0 数据库的 OID(提交 aa010514)。
    • pg_upgrade 生成的文件现在将存储在升级集群的数据目录下的 pg_upgrade_output.d 中(提交 38bfae36a0084963)。
    • 所有无法连接的数据库现在都会被列出(提交 26ebb0e2)。
    • 如果输出不是 tty,则不会发出进度状态(提交 27b02e07)。
    • 删除了从 PostgreSQL 9.2 之前的版本升级的支持(提交 38bfae36a0084963)。
  • PostgreSQL 13
    • 默认的新 bindir 现在与正在执行的 pg_upgrade 二进制文件的位置相同,在大多数情况下无需显式指定 -B newbindir (提交 959f6d6a)。
  • PostgreSQL 12
    • 添加了 --clone 选项(提交 3a769d82)。
    • 添加了 --socketdir 选项(提交 2d34ad84)。
  • PostgreSQL 10
    • 旧 PostgreSQL 版本的哈希索引将被使失效,并生成一个用于重新创建它们的脚本(提交 a95410e2)。
  • PostgreSQL 9.5
  • PostgreSQL 9.4
    • -u/--user 选项重命名为 -U/--username,以与其他实用程序保持一致(提交 457d6cf0)。
    • 显著减少了内存消耗(提交 2a2e40aa)。
  • PostgreSQL 9.3
    • 添加了 --jobs 选项,以启用数据库的并行模式转储/恢复,以及数据文件的并行复制/链接(提交 6f1b9e4e 和提交 a89c46f9)。
    • 改进了状态显示(提交 6dd95845)。
    • 提高了具有大量表的数据库的性能(提交 29add0de)。
    • 正确检测非默认套接字目录的位置(提交 f763b771)。
    • 在升级日志中显示执行的命令(提交 4741e9af)。
    • 改进了复制/链接操作期间的状态显示(提交 6dd95845)。
  • PostgreSQL 9.2
    • 以 PG 开头的 pg_upgrade 特定的环境变量已被重命名;PGPORT 现在被忽略,并由 PGPORTOLD/PGPORTNEW 替换(提交 a88f4496)。
    • 默认使用端口 50432(提交 a88f4496)。
    • 一般的日志记录改进(提交 717f6d60)。
    • 旧集群仅在使用了链接模式时才会被锁定(提交 2127aac6)。
    • 添加了用于增量生成更准确统计信息的脚本(提交 faec2815)。
    • 删除了 -g/-G/-l 日志选项(提交 717f6d60)。
    • 添加了 -o/-O 选项(提交 0dc3f57b)。
    • 添加了 -r/--retain 选项(提交 717f6d60)。
    • 改进了 -v/--verbose 的行为(提交 717f6d60)。
    • 支持升级不包含 postgres 数据库的集群(提交 a50d860a)。
  • PostgreSQL 9.0

请注意,pg_upgrade 的早期版本最初是作为 contrib 模块PostgreSQL 7.2 中添加(提交 92a8bc96),并在 PostgreSQL 8.1 中删除(提交 d20763db)。

 

示例

pg_upgrade 操作的样本输出。

$ pg_upgrade \
  --old-bindir=/usr/local/pg12/bin \
  --old-datadir=/var/lib/pg12/data \
  --new-datadir=/var/lib/pg13/data \
  --old-port=5432 \
  --new-port=5433 \
  --jobs 4

Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for user-defined postfix operators                 ok
Creating dump of global objects                             ok
Creating dump of database schemas
                                                            ok
Checking for presence of required libraries                 ok
Checking database user is the install user                  ok
Checking for prepared transactions                          ok
Checking for new cluster tablespace directories             ok

If pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.

Performing Upgrade
------------------
Analyzing all rows in the new cluster                       ok
Freezing all rows in the new cluster                        ok
Deleting files from new pg_xact                             ok
Copying old pg_xact to new server                           ok
Setting next transaction ID and epoch for new cluster       ok
Deleting files from new pg_multixact/offsets                ok
Copying old pg_multixact/offsets to new server              ok
Deleting files from new pg_multixact/members                ok
Copying old pg_multixact/members to new server              ok
Setting next multixact ID and offset for new cluster        ok
Resetting WAL archives                                      ok
Setting frozenxid and minmxid counters in new cluster       ok
Restoring global objects in the new cluster                 ok
Restoring database schemas in the new cluster
                                                            ok
Copying user relation files
                                                            ok
Setting next OID for new cluster                            ok
Sync data directory to disk                                 ok
Creating script to delete old cluster                       ok

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
    /usr/local/pg13/bin/vacuumdb --all --analyze-in-stages

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh

分类

服务器实用程序, 升级

反馈

提交关于“pg_upgrade”的任何评论、建议或更正 请在此处