postgresql - 如何解决 Azure for PostgreSQL 中的内存不足错误
问题描述
我正在一个项目中工作,该项目从数据库中提取一百万条数据,并将这些数据转换为 csv 文件以供下载。我使用的数据库是 PostgreSQL,我将它部署到 AKS (Azure kubernetes)。该代码在我本地运行良好。我正在从 AKS 使用的本地连接相同的数据库。但是当我试图在 AKS 中执行代码时,我总是得到
java.lang.OutOfMemoryError: Java heap space] with root cause
java.lang.OutOfMemoryError: Java heap space
at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor.getExtractor(VarcharTypeDescriptor.java:59) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.custom.ScalarResultColumnProcessor.extract(ScalarResultColumnProcessor.java:54) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.custom.ResultRowProcessor.buildResultRow(ResultRowProcessor.java:83) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.custom.ResultRowProcessor.buildResultRow(ResultRowProcessor.java:60) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:412) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:775) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.getRowsFromResultSet(Loader.java:1044) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.processResultSet(Loader.java:995) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:964) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:350) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2887) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2869) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2701) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.Loader.list(Loader.java:2696) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338) ~[hibernate-core-5.4.21.Final.jar!/:5.4.21.Final]
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java
我正在发布执行的代码
Query query = entityManager.createNativeQuery(sqlQuery);
List<Object[]> objectList = query.getResultList();
objectList.forEach(glObject -> {
myEntity entity = myEntity.builder()
.supl_num(glObject[0])
.detail(glObject[1])
...............
.build();
myEntityList.add(entity);
});
AKS 部署配置
...........
ports:
-containerPort: 80
resources:
requests:
cpu : 75m
memory:256Mi
limits:
cpu:1
memory: 2Gi
我不明白为什么这会导致一次又一次
解决方案
在 JDBC URL 中使用defaultRowFetchSize
连接模式,以便驱动程序以块的形式获取数据,而不是一次全部获取。
推荐阅读
- r - 当多个电子邮件ID存储在一个Excel单元格中时如何发送邮件?
- php - Laravel 一对多更新失败问题
- c# - 带有附加参数的 C# 按钮单击
- c++ - POD 结构的 std::vector::emplace_back 与分配的性能
- node.js - 节点 - 以类形式编写子进程生成执行
- c# - ASP.NET Core 3.1 如何从引用的项目运行方法?
- javascript - 从Javascript中的嵌套数组对象制作扁平值数组
- .net-core - 限制 AddJwtBearer 在 .net core 3.1 中验证 ID 令牌
- python - 不带表达式的 while 语句
- php - 在 WooCommerce 中发送订单确认电子邮件通知谢谢