2008年(32)
分类: Oracle
2008-08-08 20:51:16
alter tablespace users drop datafile '/tmp/users01.dbf' /
?
SQL> create table accounts_int 2 tablespace accdata 3 as 4 select * from accounts 5 where 1=2 6 /Note where the partitions are located now:
SQL> select partition_name, tablespace_name, num_rows 2 from user_tab_partitions 3 / PARTITION_NAME TABLESPACE_NAME NUM_ROWS ------------------------------ ------------------------------ ---------- P1 USERS 1014 P2 USERS 1042 P3 USERS 1002 P4 USERS 964 P5 USERS 990 P6 USERS 1042 P7 USERS 915 P8 USERS 983 P9 USERS 1047 P10 USERS 1001 PMAX USERS 0 11 rows selected.All partitions are in USERS tablespace. Now move the first partition P1 to the tablespace ACCDATA.
SQL> begin 2 dbms_redefinition.start_redef_table ( 3 uname => 'ARUP', 4 orig_table => 'ACCOUNTS', 5 int_table => 'ACCOUNTS_INT', 6 part_name => 'P1' 7 ); 8 end; 9 / PL/SQL procedure successfully completed.Note the line 6, where the part_name parameter specifies the partition to be reorganized. If this parameter is omitted, all the partitions will be redefined at the same time. Now, synchronize the interim table with the original table. (You need to do this only if there are updates going to the table ACCOUNTS.)
SQL> begin 2 dbms_redefinition.sync_interim_table ( 3 uname => 'ARUP', 4 orig_table => 'ACCOUNTS', 5 int_table => 'ACCOUNTS_INT', 6 part_name => 'P1' 7 ); 8 end; 9 / PL/SQL procedure successfully completed.Finally, finish the redefinition process.
SQL> begin 2 dbms_redefinition.finish_redef_table ( 3 uname => 'ARUP', 4 orig_table => 'ACCOUNTS', 5 int_table => 'ACCOUNTS_INT', 6 part_name => 'P1' 7 ); 8 end; 9 / PL/SQL procedure successfully completed.Confirm the partition P1 was indeed moved to the tablespace ACCDATA.
SQL> select partition_name, tablespace_name, num_rows 2 from user_tab_partitions 3 / PARTITION_NAME TABLESPACE_NAME NUM_ROWS ------------------------------ ------------------------------ ---------- P1 ACCDATA 1014 P2 USERS 1042 P3 USERS 1002 P4 USERS 964 P5 USERS 990 P6 USERS 1042 P7 USERS 915 P8 USERS 983 P9 USERS 1047 P10 USERS 1001 PMAX USERS 0 11 rows selected.That's it; repeat the same procedure for other partitions. In contrast, if you had reorganized the table entirely, you would have (a) required a space equal to the size of the entire table and (b) generated undos for the entire table, which would have to be present—else you would received an error. By doing the process for a single partition, however, you reduced the space requirement to that of a single partition and reduced the undo generation for that partition only. This powerful and useful feature enables you to reorganize very large objects—as most partitioned objects are—online. Furthermore, note how the statistics are copied to the redefined table as well, as shown in the values of NUM_RWS in the above query; you do not have to regenerate statistics for the newly created table or partitions.