org.postgresql.util.PSQLException:错误:索引行需要的内存多于默认值(8191)

时间:2016-04-19 04:49:40

标签: postgresql postgresql-9.4

我正在尝试在现有项目中使用PostgreSQL来提高性能并使其与JSON友好。我已经对PostgreSQL做了一些研究,并试图将它集成到我们的应用程序中。但是当我尝试将大型json文档插入表中时,我遇到了一些问题。它正在处理一小组json文档,但是失败了大数据。以下是插入数据时控制台中显示的错误。

org.postgresql.util.PSQLException: ERROR: index row requires 11936 bytes, maximum size is 8191
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:321)
    at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:297)
    at com.practice.PracticeClass.main(PracticeClass.java:28)
org.postgresql.util.PSQLException: ERROR: index row requires 11936 bytes, maximum size is 8191

PracticeClass.java

package com.practice;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PracticeClass {

    public static void main(String[] args) throws SQLException {
        Connection c = null;
        Statement st = null;
        try {
            Class.forName("org.postgresql.Driver");
            c = DriverManager
                    .getConnection("jdbc:postgresql://localhost:5432/jsonbdb", "postgres", "admin");
            System.out.println("Opened database successfully");
            st = c.createStatement();
            String query = "create table IpauDeviceInfo(id serial, deviceinfo jsonb UNIQUE)";
            st.executeUpdate(query);
            System.out.println("Table created successfully");

            StringBuilder strBuilder = new StringBuilder();
            strBuilder.append(**large_json_document**);

            String insertQuery = "insert into IpauDeviceInfo(\"deviceinfo\") values(" + strBuilder.toString() + ")";
            st.executeUpdate(insertQuery);
            System.out.println("inserted successfully");
            /*String upadteQuery = "update jsonbtab_unique set \"deviceinfo\" = jsonb_set(\"deviceinfo\", '{deviceId}', '\"SHARP-MX-Dev_10002\"', true) where \"deviceinfo\"-> 'deviceId' = '\"Brother_Dev_001\"'";
            st.executeUpdate(upadteQuery);*/
            ResultSet rs  = st.executeQuery("select (\"deviceinfo\") from IpauDeviceInfo");
            while(rs.next()) {
                System.out.println("count: " + rs.getFetchSize());
                System.out.println("rows: " + rs.getString("deviceinfo"));
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e.getClass().getName()+": "+e.getMessage());
            System.exit(0);
        } finally {
            c.close();
            st.close();
        }
    }
}

在上面的错误中,它表示内存不足以创建索引。我是Postgres的新手。插入json文档时我没有创建任何索引。我认为它是在内部为列创建索引。

创建表:

Create table sample(id serial, info jsonb);

可以告诉我如何解决此错误或如何配置增加内存以插入大数据。

0 个答案:

没有答案