迁移数据库

您可以使用 neo4j-admin database migrate 命令将 Neo4j 数据库从一种存储格式迁移到另一种格式,或者迁移到相同格式的更高 MAJOR 版本。

存储格式定义了数据库数据在文件系统上的存储方式。

数据库的存储格式使用 MAJOR.MINOR 方案进行版本控制,独立于 Neo4j 日历版本控制。升级到最新的 MINOR 格式版本是在数据库启动时执行的自动操作。迁移到更高的 MAJOR 格式版本或另一种格式是使用 migrate 命令执行的手动操作。

可以使用 db.format 配置设置来设置新数据库的存储格式。

下表显示了不同 Neo4j 存储格式之间支持的迁移路径。但是,standardhigh_limit 存储格式从 Neo4j 5.23 开始被弃用,这意味着从该版本开始不建议迁移到这些格式。

表 1. Neo4j 存储格式之间的迁移路径

存储格式

迁移路径

block

aligned

high_limit

standard

block [1]

不建议

不建议

aligned [2]

不建议

high_limit [3]

standard [4]

不建议

1. 自 Neo4j 5.22 起,block 格式是企业版的默认格式。
2. aligned 格式是社区版的默认格式。在 Neo4j 5.22 之前,它是企业版的默认格式。
3. 企业版 high_limit 格式在 5.23 版本中被弃用。
4. 社区版 standard 格式在 5.23 版本中被弃用。

在从 block 格式迁移到 aligned 格式之前,您必须确保您的图数据适合 aligned 格式,因为 block 格式具有更高的限制。有关详细信息,请参阅 数据库内部原理与事务行为 → 存储格式

语法

neo4j-admin database migrate 的语法如下

neo4j-admin database migrate [-h] [--expand-commands]
                             [--force-btree-indexes-to-range]
                             [--verbose] [--additional-config=<file>]
                             [--max-off-heap-memory=<size>] [--pagecache=<size>]
                             [--to-format=standard|high_limit|aligned|block] <database>

neo4j-admin database migrate 命令只能在数据库停止运行时执行。

参数

表 2. neo4j-admin database migrate 参数
参数 描述

<database>

要迁移的数据库名称。可以使用 * 和 ? 进行通配。请注意,* 和 ? 在某些 shell 中有特殊含义,可能需要进行转义或使用引号括起来。

选项

neo4j-admin database migrate 命令具有以下选项

表 3. neo4j-admin database migrate 选项
选项 描述 默认

--additional-config=<file>[5]

包含额外配置的配置文件。

--expand-commands

允许在配置值评估中进行命令扩展。

--force-btree-indexes-to-range

这是一个特殊选项,用于自动将所有 BTREE 索引/约束转换为 RANGE 类型。请注意,RANGE 索引并不总是 BTREE 的最佳替代方案,并且在新索引填充期间性能可能会受到影响。有关更多信息,请参阅在线的 Neo4j v5 迁移指南。新创建的索引将在迁移后的首次数据库启动时在后台填充,用户应监控该过程是否成功完成。

此选项仅在从 Neo4j 4.4 迁移时相关。

-h, --help

显示此帮助消息并退出。

--max-off-heap-memory=<size> 引入于 Neo4j 2025.04

该命令可用于页面缓存和各种缓存数据结构以提高性能的最大内存。值可以是普通数字(例如 10000000)、单位大小(例如 20G 表示 20GB),或百分比(例如 70%,表示当前机器空闲内存的 70%)。

90%

--pagecache=<size> 弃用于 Neo4j 2025.04

用于迁移过程的页面缓存大小。通常的规则是,值最高达到数据库大小时,性能会成比例提升。

--to-format=standard|high_limit|aligned|block

要将存储迁移到的格式名称。如果指定了格式,目标数据库将迁移到该指定格式的最新已知 MAJORMINOR 版本组合。如果未指定,工具会将目标数据库迁移到当前格式的最新已知 MAJORMINOR 版本组合。

--verbose

启用详细输出。

5. 有关详细信息,请参阅 Neo4j Admin 和 Neo4j CLI → 配置

只要没有指定 db.format 设置,block 格式就是企业版中所有数据库的默认格式。有关 block 格式的更多信息,请参阅 存储格式

示例

以下示例将 movies 数据库迁移到 block 格式的最新已知 MAJORMINOR 版本组合

bin/neo4j-admin database migrate --to-format=block movies
输出示例
2025-01-22 18:03:21.842+0000 INFO  [c.n.c.d.EnterpriseMigrateStoreCommand] Starting migration for database 'movies'
2025-01-22 18:03:22.504+0000 INFO  [o.n.k.i.s.StoreMigrator] 'record-aligned-1.1' has been identified as the current version of the store
2025-01-22 18:03:22.504+0000 INFO  [o.n.k.i.s.StoreMigrator] 'block-block-1.1' has been identified as the target version of the store migration
2025-01-22 18:03:22.506+0000 INFO  [o.n.k.i.s.StoreMigrator] Starting migration of database
2025-01-22 18:03:22.586+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating Store files (1/1):
2025-01-22 18:03:22.588+0000 INFO  [o.n.k.i.s.StoreMigrator] Store files
2025-01-22 18:03:23.270+0000 INFO  [c.n.i.b.i.BlockBatchImporter] Import completed successfully, took 654ms.
2025-01-22 18:03:23.708+0000 INFO  [o.n.k.i.s.StoreMigrator]  10% completed
2025-01-22 18:03:23.708+0000 INFO  [o.n.k.i.s.StoreMigrator]  20% completed
2025-01-22 18:03:23.708+0000 INFO  [o.n.k.i.s.StoreMigrator]  30% completed
2025-01-22 18:03:23.708+0000 INFO  [o.n.k.i.s.StoreMigrator]  40% completed
2025-01-22 18:03:23.709+0000 INFO  [o.n.k.i.s.StoreMigrator]  50% completed
2025-01-22 18:03:23.709+0000 INFO  [o.n.k.i.s.StoreMigrator]  60% completed
2025-01-22 18:03:23.709+0000 INFO  [o.n.k.i.s.StoreMigrator]  70% completed
2025-01-22 18:03:23.709+0000 INFO  [o.n.k.i.s.StoreMigrator]  80% completed
2025-01-22 18:03:23.709+0000 INFO  [o.n.k.i.s.StoreMigrator]  90% completed
2025-01-22 18:03:23.709+0000 INFO  [o.n.k.i.s.StoreMigrator] 100% completed
2025-01-22 18:03:23.761+0000 INFO  [o.n.k.i.s.StoreMigrator] Starting transaction logs migration.
2025-01-22 18:03:23.800+0000 INFO  [o.n.k.i.s.StoreMigrator] Transaction logs migration completed.
2025-01-22 18:03:23.802+0000 INFO  [o.n.k.i.s.StoreMigrator] Successfully finished migration of database, took 1s 296ms
2025-01-22 18:03:23.804+0000 INFO  [c.n.c.d.EnterpriseMigrateStoreCommand] Database migration completed successfully