【neo4j】跨版本升级数据库
由于使用neo4j版本较低,需要从neo4j-community-3.5.8升级到neo4j-community-5.26.0,但是直接通过dump保存文件,load加载到新版中,报错
所以使用逐步升级的方式。
3.5 -> 4.4 -> 5.26
一、 旧版本操作
- 导出文件
cd /opt/neo4j-community-3.5.8
bin/neo4j stop
./bin/neo4j-admin dump --database=graph.db --to=graph.db.dump
- 传输文件到中间版本所在的机器。
二、中间版本操作
- 解压4.4版本
tar zxvf neo4j-community-4.4.44-unix.tar.gz
- 解压并配置环境变量
tar zxvf jdk-11.0.27_linux-x64_bin.tar.gz -C /root/neo4j-community-4.4.44/
# 编辑并保存
vi /etc/profile
export JAVA_HOME=/root/neo4j-community-4.4.44/jdk-11.0.27
export JRE_HOME=/root/neo4j-community-4.4.44/jdk-11.0.27
# source生效
source /etc/profile
- 启动并关闭neo4j
cd /root/neo4j-community-4.4.44
bin/neo4j start
bin/neo4j stop
- 导入load
4.4版本的导入已经和3.x的不同,需要注意命令。
bin/neo4j-admin load --from=/root/graph.db.dump --database=graph.db --force
执行结束以后,会有一个WARN的提示,需要把dbms.allow_upgrade配置改为true,执行升级操作。
- 修改配置并启动
# 配置后保存
vi conf/neo4j.conf
# 修改库名为自己的数据库
initial.dbms.default_database=graph.db
dbms.allow_upgrade=true
# 启动
bin/neo4j start
等待库表自动升级后,服务启动。
6. 观察
7. 导出
4.4版本的导出命令已经和3.x的不同,需要注意命令。
# 停止neo4j服务
bin/neo4j stop
bin/neo4j-admin dump --database=graph.db --to=/root/out/
- 传输文件到中间版本所在的机器。
三、新版本操作
新版本已安装,安装步骤和操作库一样,不过jdk要求21.
- 停止服务
cd /opt/neo4j-community-5.26.0/
bin/neo4j stop - 导入
# 执行导入命令
bin/neo4j-admin database load --from-path=/root/out/ --overwrite-destination=true graph.db
# 根据提示执行migrate 操作
bin/neo4j-admin database migrate graph.db
报错:
2025-07-31 09:47:24.119+0000 ERROR [o.n.c.d. MigrateStoreCommand] Failed to migrate database ‘graph.db’: Migration will remove all BTREE indexes and constraints backed by BTREE indexes. To guard against unintentionally removing indexes or constraints, it is recommended for all BTREE indexes or constraints backed by BTREE indexes to have a valid replacement. Indexes can be replaced by RANGE, TEXT or POINT index and constraints can be replaced by constraints backed by RANGE index. Please drop your indexes and constraints or create replacements and retry the migration. The indexes and constraints without replacement are: [Index( id=1, name=‘index_7530a0f9’, type=‘BTREE’, schema=(:CI实例 {oneLevelId}), indexProvider=‘native-btree-1.0’ ), Index( id=3, name=‘index_5565c06f’, type=‘BTREE’, schema=(:CI目录 {type}), indexProvider=‘native-btree-1.0’ )] and []. Alternatively, you can use the option --force-btree-indexes-to-range to force all BTREE indexes or constraints backed by BTREE indexes to be replaced by RANGE equivalents. Be aware that RANGE indexes are not always the optimal replacement of BTREEs and performance may be affected while the new indexes are populated. See the Neo4j v5 migration guide online for more information.
根据提示新增–force-btree-indexes-to-range参数
bin/neo4j-admin database migrate graph.db --force-btree-indexes-to-range
- 修改配置并启动
# 配置后保存
vi conf/neo4j.conf
# 修改库名为自己的数据库
initial.dbms.default_database=graph.db
# 启动
bin/neo4j start
- 观察
旧版本:
新版本:
参考:
https://neo4j.ac.cn/docs/upgrade-migration-guide/current/version-4/migration/migrate-to-4.0/standalone/