从PostgreSQL读取单列时出现OutOfMemoryError

时间:2018-03-11 16:07:49

标签: java postgresql jdbc out-of-memory pg-jdbc

我正在尝试从本地安装的PostgreSQL 10.3

中的一个表中读取一列
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/vk", "postgres", "qwerty");
Statement statement = conn.createStatement();
statement.setFetchSize(10);
ResultSet rs = statement.executeQuery("select POST_CONTENT from VK_GROUP_POST");
System.out.println("rs is ready " + rs);

我使用-verbose:gc -Xmx512M VM选项运行程序。 项目只有依赖项:org.postgresql:postgresql:42.2.1

我总是得到OOM错误:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
...
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2134)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270)
at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:224)
at my.SaveRepostedToFile.main(SaveRepostedToFile.java:10)

有没有办法避免OOM?

0 个答案:

没有答案