【问题标题】:Netezza Batch Insert is very slow even in Batch execute mode即使在批处理执行模式下,Netezza 批处理插入也非常慢
【发布时间】:2017-07-20 16:25:53
【问题描述】:

我指的是这个文档。 http://www-01.ibm.com/support/docview.wss?uid=swg21981328。根据文章,如果我们使用 executeBatch 方法,那么插入会更快(Netezza JDBC 驱动程序可能会检测到批量插入,并且在幕后将其转换为外部表加载,外部表加载会更快)。我不得不执行数百万条插入语句,而每个连接的最大速度仅为每分钟 500 条记录。有没有更好的方法可以通过 jdbc 连接更快地将数据加载到 netezza?我正在使用 spark 和 jdbc 连接来插入记录。为什么即使我分批执行,通过加载的外部表也不会发生。下面给出的是我正在使用的火花代码,

Dataset<String> insertQueryDataSet.foreachPartition( partition -> {                 
    Connection conn = NetezzaConnector.getSingletonConnection(url, userName, pwd);
    conn.setAutoCommit(false);
    int commitBatchCount = 0;
    int insertBatchCount = 0;
    Statement statement = conn.createStatement();
    //PreparedStatement preparedStmt  = null;
    while(partition.hasNext()){
        insertBatchCount++;             
        //preparedStmt = conn.prepareStatement(partition.next());
        statement.addBatch(partition.next());
        //statement.addBatch(partition.next());
        commitBatchCount++;
        if(insertBatchCount % 10000 == 0){
            LOGGER.info("Before executeBatch.");                            
            int[] execCount = statement.executeBatch();
            LOGGER.info("After execCount." + execCount.length);                     
            LOGGER.info("Before commit.");
            conn.commit();                          
            LOGGER.info("After commit.");                                                   
        }                       
    }
    //execute remaining statements
    statement.executeBatch();
    int[] execCount = statement.executeBatch();
    LOGGER.info("After execCount." + execCount.length);
    conn.commit();          
    conn.close();

}); 

【问题讨论】:

    标签: jdbc netezza


    【解决方案1】:

    我尝试了这种方法(批量插入),但发现速度很慢, 所以我把所有数据都放在 CSV 中,并为每个 csv 做外部表加载。

    InsertReq="Insert into "+ tablename + " select * from external '"+ filepath + "' using (maxerrors 0, delimiter ',' unase 2000 encoding 'internal' remotesource 'jdbc' escapechar '\' )";
    Jdbctemplate.execute(InsertReq);
    

    由于我使用 java 所以 JDBC 作为源并注意 csv 文件路径是单引号。 希望这可以帮助。 如果您发现比这种方法更好,请不要忘记发布。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-17
      • 2021-06-08
      • 2012-07-03
      • 2021-08-31
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 2020-02-12
      相关资源
      最近更新 更多