db2“不记录初始”不起作用

时间:2017-02-08 19:39:06

标签: sql db2 db2-luw

我的DB2版本是LUW v11.1。

我在大表上运行select查询并插入到新表中,因此我在创建新表时尝试使用“NOT LOGGED INITIALLY”以避免生成大量日志。但似乎NLI选项无效。

以下是我的sql代码:

create table diabetes_v3_2.comm_outpatient_prescription_drugs_t2dm
    as (select * from commercial.outpatient_prescription_drugs)
    with no data
    not logged initially;
insert into diabetes_v3_2.comm_outpatient_prescription_drugs_t2dm
    select * from commercial.outpatient_prescription_drugs
        where enrolid in (
            select enrolid from diabetes_v3_2.t2dm_cohort_filter_age_enrollment
        );


create table diabetes_v3_2.comm_outpatient_services_t2dm
    as (select * from commercial.outpatient_services)
    with no data
    not logged initially;
insert into diabetes_v3_2.comm_outpatient_services_t2dm
    select * from commercial.outpatient_services
        where enrolid in (
            select enrolid from diabetes_v3_2.t2dm_cohort_filter_age_enrollment
        );

我将脚本作为db2 -tvf script.sql运行。但我仍然得到“SQL0964C数据库的事务日志已满”错误:

/* Generate cohort data for the cohort after *  filtering according to age and continuous * enrollment criteria. */ /* facility header */ /* inpatient admissions */ /* inpatient services */ /* outpatient prescription drugs */ create table diabetes_v3_2.comm_outpatient_prescription_drugs_t2dm as (select * from commercial.outpatient_prescription_drugs) with no data not logged initially
DB20000I  The SQL command completed successfully.

insert into diabetes_v3_2.comm_outpatient_prescription_drugs_t2dm select * from commercial.outpatient_prescription_drugs where enrolid in ( select enrolid from diabetes_v3_2.t2dm_cohort_filter_age_enrollment )
  Number of rows affected : 275423901
DB20000I  The SQL command completed successfully.

/* outpatient services */ create table diabetes_v3_2.comm_outpatient_services_t2dm as (select * from commercial.outpatient_services) with no data not logged initially
DB20000I  The SQL command completed successfully.

insert into diabetes_v3_2.comm_outpatient_services_t2dm select * from commercial.outpatient_services where enrolid in ( select enrolid from diabetes_v3_2.t2dm_cohort_filter_age_enrollment )
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL0964C  The transaction log for the database is full.  SQLSTATE=57011

为什么会这样?

1 个答案:

答案 0 :(得分:2)

要正确使用NOT LOGGED INITIALLY,执行更改的应用程序不应启用AUTOCOMMIT。 AUTOCOMMIT OFF也有助于定义交易范围:

  • 对于CLP,您可以使用环境变量DB2OPTIONS关闭AUTOCOMMIT:

    export DB2OPTIONS=+c
    
  • 如果执行包含更新SQL语句的脚本(例如插入),并且未设置DB2OPTIONS,则可以使用以下命令执行脚本:

    db2 +c -tvf input_script.sql  -z output_script.out
    

确保在脚本中添加明确的COMMIT语句,以确保它们出现在合理的位置。