alter table drop unused columns checkpoint

guocun09發表於2021-11-13

結論

1,alter table drop unused columns checkpoint適用於減少不必要的undo空間消耗

2,checkpoint選項可取值有:
    不取值,預設在512條記錄後發生檢查點動作
    大於表記錄個數,表明在處理完所有表記錄後發生檢查點
    小於表記錄個數,表明在指定表記錄後發生檢查點

3,如果checkpoint選項後產生的檢查點動作被中斷,僅truncate table,drop table,alter table drop unused columns continue語句可以執行

4,alter table drop unused columns continue即恢復繼續執行被中斷的alter table drop unused columns checkpoint繼續下去    


測試

1,資料庫版本
SQL> select * from v$version where rownum=1;


BANNER
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production


2,開啟檢查點資訊到告警日誌
SQL> show parameter checkpoint


NAME                                 TYPE                   VALUE
------------------------------------ ---------------------- ------------------------------
log_checkpoint_interval              integer                0
log_checkpoint_timeout               integer                1800
log_checkpoints_to_alert             boolean                FALSE


SQL> alter system set log_checkpoints_to_alert=true;


System altered.


[oracle@seconary trace]$ tail -f alert_guowang.log 
  Current log# 2 seq# 356 mem# 0: /oracle/oradata/guowang/redo02.log
Fri Oct 16 08:18:16 2015
Thread 1 advanced to log sequence 357 (LGWR switch)
  Current log# 3 seq# 357 mem# 0: /oracle/oradata/guowang/redo03.log
Fri Oct 16 08:27:17 2015
ALTER SYSTEM SET log_checkpoints_to_alert=TRUE SCOPE=BOTH;
Fri Oct 16 08:28:44 2015
Beginning log switch checkpoint up to RBA [0x166.2.10], SCN: 11696352
Thread 1 advanced to log sequence 358 (LGWR switch)
  Current log# 1 seq# 358 mem# 0: /oracle/oradata/guowang/redo01.log


SQL> alter system checkpoint;


System altered.


Fri Oct 16 08:29:15 2015
Beginning global checkpoint up to RBA [0x166.1044.10], SCN: 11698731
Completed checkpoint up to RBA [0x166.1044.10], SCN: 11698731
Completed checkpoint up to RBA [0x166.2.10], SCN: 11696352


3,建立測試表並插入資料
SQL> conn scott/system
Connected.
SQL> create table t_checkpoint(a int,b int);


Table created.


SQL> insert into t_checkpoint select level,level from dual connect by level<=100000;


100000 rows created.


SQL> commit;


Commit complete.


4,指定測試表B列為不可用
SQL> alter table t_checkpoint set unused column b;


Table altered.


5,可見指定checkpoint選項後會發生一個檢查點動作


SQL> alter table t_checkpoint drop unused columns checkpoint 500;


Table altered.


Fri Oct 16 08:34:11 2015
Beginning log switch checkpoint up to RBA [0x167.2.10], SCN: 11720087
Thread 1 advanced to log sequence 359 (LGWR switch)
  Current log# 2 seq# 359 mem# 0: /oracle/oradata/guowang/redo02.log




6,如果正在進行檢查點動作,被中斷,會如何呢?
SQL> drop table t_checkpoint purge;


Table dropped.


SQL> create table t_checkpoint(a int,b int);


Table created.


SQL> insert into t_checkpoint select level,level from dual connect by level<=100000;


100000 rows created.


SQL> commit;


Commit complete.  


SQL> alter table t_checkpoint drop unused columns checkpoint;


alter table t_checkpoint drop unused columns checkpoint
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01013: user requested cancel of current operation






SQL> SQL> 


SQL> select table_name,status from user_tables where table_name='T_CHECKPOINT';


TABLE_NAME                                                   STATUS
------------------------------------------------------------ ----------------
T_CHECKPOINT                                                 VALID


可見如果檢查點程式被中斷,不能進行alter table add操作,必須先要讓檢查點執行完成,即執行
  alter table drop columns continue
SQL> alter table t_checkpoint add c int;
alter table t_checkpoint add c int
            *
ERROR at line 1:
ORA-12986: columns in partially dropped state. Submit ALTER TABLE DROP COLUMNS
CONTINUE




SQL> 


SQL> host oerr ora 12986
12986, 00000, "columns in partially dropped state. Submit ALTER TABLE DROP COLUMNS CONTINUE"
// *Cause:  An attempt was made to access a table with columns in partially 
//          dropped state (i.e., drop column operation was interrupted).
// *Action: Submit ALTER TABLE DROP COLUMNS CONTINUE to complete the drop
//          column operation before accessing the table.


select查詢也不成
SQL> select count(*) from t_checkpoint;
select count(*) from t_checkpoint
                     *
ERROR at line 1:
ORA-12986: columns in partially dropped state. Submit ALTER TABLE DROP COLUMNS
CONTINUE


truncate操作是可以成功的
SQL> truncate table t_checkpoint;


Table truncated.




alter table drop columns continue用於繼續執行被中斷的檢查點選項的刪除列操作
SQL> alter table t_checkpoint drop columns continue;


Table altered.


SQL> alter table t_checkpoint add c int;


Table altered.


出自:

oracle 11g之alter table drop unused columns checkpoint刪除表不可用列系列二_ITPUB部落格

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25583515/viewspace-2842045/,如需轉載,請註明出處,否則將追究法律責任。

相關文章