首页 > 解决方案 > h2数据库java堆问题

问题描述

我们的应用程序使用 java spring boot 将数据从 avro 文件加载到内存 h2 数据库中。我有 145000000 行要插入,我收到 java 堆错误。它适用于 200 万行。我该如何解决这个问题?

错误粘贴在下面引起:org.h2.jdbc.JdbcSQLNonTransientConnectionException:内存不足。;SQL 语句:在 org.h2.message.DbException.getJdbcSQLException(DbException.java:617) ~[h2-1.4.199.jar:1.4.199] 在 org.h2.message.DbException.getJdbcSQLException(DbException.java:427) ) ~[h2-1.4.199.jar:1.4.199] at org.h2.message.DbException.get(DbException.java:194) ~[h2-1.4.199.jar:1.4.199] at org.h2 .message.DbException.convert(DbException.java:341) ~[h2-1.4.199.jar:1.4.199] at org.h2.command.Command.executeUpdate(Command.java:278) ~[h2-1.4. 199.jar:1.4.199] 在 org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:233) ~[h2-1.4.199.jar:1.4.199] 在 org.h2.jdbc.JdbcStatement.execute( JdbcStatement.java:205) ~[h2-1.4.199.jar:1.4.199] 在 com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:

标签: javaspring-bootheap-memoryh2

解决方案


您正在尝试将 145M 行加载到内存中。所以你显然需要给 JVM 更多的内存来处理这么多的存储量。

查看添加/更改您的-XmxJVM 参数以分配更多内存。请参阅此处了解更多信息:

启动JVM时-Xms和-Xmx参数是什么?


推荐阅读