迁移数据库

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

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

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

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

语法

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 命令只能在停止的数据库上运行。

参数

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

<database>

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

选项

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

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

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

包含附加配置的配置文件。

--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 中引入

neo4j-admin 可以用于各种数据结构和缓存以提高性能的最大内存。值可以是纯数字,例如 10000000,或 20G 表示 20 GB。它也可以指定为可用内存的百分比,例如 70%。

90%

--pagecache=<size> Neo4j 2025.04 中已弃用

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

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

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

--verbose

启用详细输出。

1. 详见Neo4j Admin 和 Neo4j CLI → 配置

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

示例

以下示例将 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
© . All rights reserved.