迁移数据库

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

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

从 Neo4j 5 开始,数据库的存储格式使用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>] [--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>

包含其他配置的配置文件。

--expand-commands

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

--force-btree-indexes-to-range

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

Neo4j 5 不支持 BTREE 索引,并且 neo4j-admin database migrate 命令将删除所有 BTREE 索引和基于 BTREE 索引的约束。建议在迁移数据库之前创建有效的替换。有关更多信息,请参阅 [升级和迁移指南 → 准备索引

-h, --help

显示此帮助消息并退出。

--pagecache=<size>

迁移过程中使用的页面缓存的大小。一般规则是,高达数据库大小的值会成比例地提高性能。

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

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

--verbose

启用详细输出。

块格式在 Neo4j 5.14 中引入,从 Neo4j 5.22 开始,是企业版中所有新创建数据库的默认格式,只要它们没有指定 db.format 设置。有关块格式的更多信息,请参阅 存储格式

示例

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

bin/neo4j-admin database migrate --to-format=high_limit movies
示例输出
2022-11-10 12:55:35.542+0000 INFO  [o.n.c.d.MigrateStoreCommand] Starting migration for database 'movies'
2022-11-10 12:55:36.061+0000 INFO  [o.n.k.i.s.StoreMigrator] 'record-aligned-1.1' has been identified as the current version of the store
2022-11-10 12:55:36.061+0000 INFO  [o.n.k.i.s.StoreMigrator] 'record-high_limit-1.1' has been identified as the target version of the store migration
2022-11-10 12:55:36.065+0000 INFO  [o.n.k.i.s.StoreMigrator] Starting migration of database
2022-11-10 12:55:36.154+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating Store files (1/7):
2022-11-10 12:55:36.828+0000 INFO  [o.n.k.i.s.f.RecordFormatSelector] Selected RecordFormat:HighLimitV5_0[high_limit-1.1] record format from store $NEO4J_HOME/data/databases/movies/migrate
2022-11-10 12:55:36.828+0000 INFO  [o.n.k.i.s.f.RecordFormatSelector] Selected format from the store files: RecordFormat:HighLimitV5_0[high_limit-1.1]
2022-11-10 12:55:37.020+0000 INFO  [o.n.i.b.ImportLogic] Import starting
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   10% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   20% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   30% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   40% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   50% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   60% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   70% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   80% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   90% completed
2022-11-10 12:55:37.924+0000 INFO  [o.n.k.i.s.StoreMigrator]   100% completed
2022-11-10 12:55:37.925+0000 INFO  [o.n.i.b.ImportLogic] Import completed successfully, took 903ms. Imported:
  171 nodes
  253 relationships
  564 properties
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating text-1.0 (2/7):
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   10% completed
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   20% completed
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   30% completed
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   40% completed
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   50% completed
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   60% completed
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   70% completed
2022-11-10 12:55:38.515+0000 INFO  [o.n.k.i.s.StoreMigrator]   80% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   90% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   100% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating range-1.0 indexes (3/7):
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   10% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   20% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   30% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   40% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   50% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   60% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   70% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   80% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   90% completed
2022-11-10 12:55:38.516+0000 INFO  [o.n.k.i.s.StoreMigrator]   100% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating Fulltext indexes (4/7):
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   10% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   20% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   30% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   40% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   50% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   60% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   70% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   80% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   90% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   100% completed
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating point-1.0 indexes (5/7):
2022-11-10 12:55:38.517+0000 INFO  [o.n.k.i.s.StoreMigrator]   10% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   20% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   30% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   40% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   50% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   60% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   70% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   80% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   90% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   100% completed
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating Token indexes (6/7):
2022-11-10 12:55:38.518+0000 INFO  [o.n.k.i.s.StoreMigrator]   10% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   20% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   30% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   40% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   50% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   60% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   70% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   80% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   90% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   100% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator] Migrating text-2.0 (7/7):
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   10% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   20% completed
2022-11-10 12:55:38.519+0000 INFO  [o.n.k.i.s.StoreMigrator]   30% completed
2022-11-10 12:55:38.520+0000 INFO  [o.n.k.i.s.StoreMigrator]   40% completed
2022-11-10 12:55:38.520+0000 INFO  [o.n.k.i.s.StoreMigrator]   50% completed
2022-11-10 12:55:38.520+0000 INFO  [o.n.k.i.s.StoreMigrator]   60% completed
2022-11-10 12:55:38.520+0000 INFO  [o.n.k.i.s.StoreMigrator]   70% completed
2022-11-10 12:55:38.520+0000 INFO  [o.n.k.i.s.StoreMigrator]   80% completed
2022-11-10 12:55:38.520+0000 INFO  [o.n.k.i.s.StoreMigrator]   90% completed
2022-11-10 12:55:38.520+0000 INFO  [o.n.k.i.s.StoreMigrator]   100% completed
2022-11-10 12:55:38.628+0000 INFO  [o.n.k.i.s.StoreMigrator] Starting transaction logs migration.
2022-11-10 12:55:38.660+0000 INFO  [o.n.k.i.s.StoreMigrator] Transaction logs migration completed.
2022-11-10 12:55:38.696+0000 INFO  [o.n.k.i.s.StoreMigrator] Successfully finished migration of database, took 2s 631ms
2022-11-10 12:55:38.698+0000 INFO  [o.n.c.d.MigrateStoreCommand] Database migration completed successfully