简体   繁体   English

在一笔交易中插入大量数据

[英]Insert one large amount of data in one transaction

I have struggled with architectural problem. 我一直在努力解决建筑问题。

I have table in DB2 v.9.7 database in which I need to insert ~250000 rows, with 13 columns each, in a single transaction. 我在DB2 v.9.7数据库中有表,在其中我需要在单个事务中插入〜250000行,每行13列。 I especially need that this data would inserted as one unit of work. 我特别需要将此数据作为一个工作单元插入。

Simple insert into and executeBatch give me: 简单insert intoexecuteBatch给我:

The transaction log for the database is full. 数据库的事务日志已满。 SQL Code: -964, SQL State: 57011 SQL代码:-964,SQL状态:57011

I don't have rights to change the size of transaction log. 我无权更改事务日志的大小。 So I need to resolve this problem on the developer's side. 因此,我需要在开发人员方面解决此问题。

My second thought was to use savepoint before all inserts then I found out that works only with current transaction so it doesn't help me. 我的第二个想法是在所有插入之前使用savepoint,然后发现它仅适用于当前事务,因此对我没有帮助。

Any ideas? 有任何想法吗?

You want to perform a large insert as a single transaction, but don't have enough log space for such transaction and no permissions to increase it. 您希望将大插入作为单个事务执行,但是没有足够的日志空间用于此类事务,并且没有权限来增加它。

This means you need to break up your insert into multiple database transactions and manage higher level commit or rollback on the application side. 这意味着您需要将插入拆分为多个数据库事务,并在应用程序端管理更高级别的提交或回滚。 There is not anything in the driver, either JDBC or CLI, to help with that, so you will have to write custom code to record all committed rows and manually delete them if you need to roll back. 驱动程序(JDBC或CLI)中没有任何东西可以帮助您解决问题,因此您将必须编写自定义代码来记录所有已提交的行,并在需要回滚时手动将其删除。

Another alternative might be to use the LOAD command by means of the ADMIN_CMD() system stored procedure. 另一种选择是通过ADMIN_CMD()系统存储过程使用LOAD命令。 LOAD requires less log space. LOAD需要较少的日志空间。 However, for this to work you will need to write rows that you want to insert into a file on the database server or to a shared filesystem or drive accessible from the server. 但是,为此,您将需要将要插入到数据库服务器上的文件中或要从服务器访问的共享文件系统或驱动器中写入行。

Hi you can use export/load commands to export/import large tables, this should be very fast.The LOAD command should not be using the transaction log.You may have problem if your user have no privilege to write file on server filesystem. 嗨,您可以使用export / load命令导出/导入大表,这应该非常快。LOAD命令不应使用事务日志。如果您的用户没有权限在服务器文件系统上写文件,则可能会遇到问题。

call SYSPROC.ADMIN_CMD('EXPORT TO /export/location/file.txt OF DEL MODIFIED BY   COLDEL0x09 DECPT, select  * from some_table ' )


call SYSPROC.ADMIN_CMD('LOAD FROM /export/location/file.txt OF DEL MODIFIED BY COLDEL0x09 DECPT, KEEPBLANKS INSERT INTO other_table COPY NO');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM