How To Partition Existing Table Using DBMS_Redefinition [ID 472449.1]

How To Partition Existing Table Using DBMS_Redefinition [ID 472449.1]

Modified 28-SEP-2010Type HOWTOStatus MODERATED

In this Document
Goal
Solution

Platforms: 1-914CU;

This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.

Applies to:

Oracle Server - Standard Edition - Version: 9.2.0.4 and later[Release: 9.2 and later ]
Information in this document applies to any platform.
"Checked for relevance on 29-Sep-2010"

Goal

The purpose of this document is to provide step by step instructions on how to convert unpartitioned table to partitioned one using dbms_redefinition package.

Solution

1) Create unpartitioned table with the name unpar_table

SQL>CREATETABLEunpar_table(
idNUMBER(10),
create_dateDATE,
nameVARCHAR2(100)
);


2) Apply some constraints to the table:

SQL>ALTERTABLEunpar_tableADD(
CONSTRAINTunpar_table_pkPRIMARYKEY(id)
);

SQL>CREATEINDEXcreate_date_indONunpar_table(create_date);


3) Gather statistics on the table:

SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'unpar_table', cascade => TRUE);

4) Create a Partitioned Interim Table:

SQL>CREATETABLEpar_table(
idNUMBER(10),
create_dateDATE,
nameVARCHAR2(100)
)
PARTITIONBYRANGE(create_date)
(PARTITIONunpar_table_2005VALUESLESSTHAN(TO_DATE('01/01/2005','DD/MM/YYYY')),
PARTITIONunpar_table_2006VALUESLESSTHAN(TO_DATE('01/01/2006','DD/MM/YYYY')),
PARTITIONunpar_table_2007VALUESLESSTHAN(MAXVALUE));


5) Start the Redefinition Process:

a) Check the redefinition is possible using the following command:

SQL>EXECDbms_Redefinition.can_redef_table(USER,'unpar_table');

b)If no errors are reported, start the redefintion using the following command:

SQL>BEGIN
DBMS_REDEFINITION.start_redef_table(
uname=>USER,
orig_table=>'unpar_table',
int_table=>'par_table');
END;
/


Note: This operation can take quite some time to complete.

c) Optionally synchronize new table with interim name before index creation:

SQL>BEGIN
dbms_redefinition.sync_interim_table(
uname=>USER,
orig_table=>'unpar_table',
int_table=>'par_table');
END;
/

d) Create Constraints and Indexes:

SQL>ALTERTABLEpar_tableADD(
CONSTRAINTunpar_table_pk2PRIMARYKEY(id)
);

SQL>CREATEINDEXcreate_date_ind2ONpar_table(create_date);

e) Gather statistics on the new table:

SQL>EXECDBMS_STATS.gather_table_stats(USER,'par_table',cascade=>TRUE);

f) Complete the Redefintion Process:

SQL> BEGIN
dbms_redefinition.finish_redef_table(
uname => USER,
orig_table => 'unpar_table',
int_table => 'par_table');
END;
/

At this point the interim table has become the "real" table and their names have been switched in the name dictionary.

g) Remove original table which now has the name of the interim table:

SQL>DROPTABLEpar_table;

h)Rename all the constraints and indexes to match the original names.

ALTERTABLEunpar_tableRENAMECONSTRAINTunpar_table_pk2TOunpar_table_pk;
ALTERINDEXcreate_date_ind2RENAMETOcreate_date_ind;

i) Check whether partitioning is successful or not:

SQL> SELECT partitioned
FROM user_tables
WHERE table_name = 'unpar_table';

PAR
---
YES

1 row selected.

SQL> SELECT partition_name
FROM user_tab_partitions
WHERE table_name = 'unpar_table';

PARTITION_NAME
------------------------------
unpar_table_2005
unpar_table_2006
unpar_table_2007

3 rows selected.

Please not that the 9i redefinition procedures has some restrictions:

* There must be enough space to hold two copies of the table.
* Primary key columns cannot be modified.
* Tables must have primary keys.
* Redefinition must be done within the same schema.
* New columns added cannot be made NOT NULL until after the redefinition operation.
* Tables cannot contain LONGs, BFILEs or User Defined Types.
* Clustered tables cannot be redefined.
* Tables in the SYS or SYSTEM schema cannot be redefined.
* Tables with materialized view logs or materialized views defined on them cannot be redefined.
* Horizontal sub setting of data cannot be performed during the redefinition.

------------------------------------------------------------------------------

Blog http://blog.youkuaiyun.com/tianlesoftware

网上资源: http://tianlesoftware.download.youkuaiyun.com

相关视频:http://blog.youkuaiyun.com/tianlesoftware/archive/2009/11/27/4886500.aspx

DBA1 群:62697716(); DBA2 群:62697977()

DBA3 群:62697850 DBA 超级群:63306533;

聊天 群:40132017

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

#ifndef __PARTITION_TABLE_H_ #define __PARTITION_TABLE_H_ #define partition_table_loader "loader" #define partition_table_fdt "fdt" #define partition_table_fdt_restore "fdt_restore" #define partition_table_uboot "uboot" #define partition_table_factory_info "factory_info" #define partition_table_pt_table "pt_table" #define partition_table_pt_table_restore "pt_table_restore" #define partition_table_ubi1 "ubi1" #define partition_table_list {partition_table_loader,partition_table_fdt,partition_table_fdt_restore,partition_table_uboot,partition_table_factory_info,partition_table_pt_table,partition_table_pt_table_restore,partition_table_ubi1,NULL} #define partition_table_size {0x40000,0x100000,0x100000,0x100000,0x80000,0x180000,0x180000,0x3000000} #define partition_table_valid_size {0x0,0x0,0x0,0x0,0x10000,0x10000,0x10000,0x0} #define partition_table_version {1,0,1,1,1,0,0,0} #define partition_flash_loader "loader.bin" #define partition_flash_fdt "fdt.bin" #define partition_flash_fdt_restore "fdt.bin" #define partition_flash_uboot "uboot.bin" #define partition_flash_factory_info "factory_info.bin" #define partition_flash_pt_table "pt_table_flash.bin" #define partition_flash_pt_table_restore "pt_table_flash.bin" #define partition_flash_ubi1 "ubi1.bin" #define partition_flash_list {partition_flash_loader,partition_flash_fdt,partition_flash_fdt_restore,partition_flash_uboot,partition_flash_factory_info,partition_flash_pt_table,partition_flash_pt_table_restore,partition_flash_ubi1,NULL} #define partition_flash_name {"loader", "fdt", "fdt_restore", "uboot", "factory_info", "pt_table", "pt_table_restore", "ubi1",NULL} #define partition_upboot_fdt "fdt.bin" #define partition_upboot_pt_table "pt_table_upboot.bin" #define partition_upboot_ubi1_bootloader "ubi1_bootloader.bin" #define partition_upboot_ubi1_isp "isp_block.bin" #define partition_upboot_ubi1_kernel_linux "ubi1_kernel_linux.bin" #define partition_upboot_ubi1_rootfs_squashfs "ubi1_rootfs_squashfs.bin" #define partition_upboot_list {partition_upboot_fdt,partition_upboot_pt_table,partition_upboot_ubi1_bootloader,partition_upboot_ubi1_isp,partition_upboot_ubi1_kernel_linux,partition_upboot_ubi1_rootfs_squashfs,NULL} #define partition_upboot_name {"fdt", "pt_table", "ubi1_bootloader", "ubi1_isp", "ubi1_kernel_linux", "ubi1_rootfs_squashfs",NULL} #define partition_ubivol_list {"ubi1_bootloader", "ubi1_isp", "ubi1_kernel_linux", "ubi1_rootfs_squashfs", "ubi1_uc",NULL} #define partition_ubivol_file_list {"ubi1_bootloader.bin", "ubi1_isp.bin", "ubi1_kernel_linux.bin", "ubi1_rootfs_squashfs.bin", "ubi1_uc.bin",NULL} #define partition_ubivol_size {0x80000,0x100000,0xA00000,0x1000000,0x300000} #define partition_ubivol_valid_size {0x0,0x80000,0x0,0x0,0x0} #define partition_ubivol_version {0,0,0,0,1} #define partition_check_name {"fdt", "ubi1_bootloader", "ubi1_isp", "ubi1_kernel_linux", "ubi1_rootfs_squashfs",NULL} #define partition_map_fdt "fdt" #define partition_map_factory_info "factory_info" #define partition_expack_list {"ubi1_isp",NULL} #define partition_expack_type_list {CONTENT_TYPE_ISP_CONFIG_DMIC} #define partition_dynamic_fs_list {NULL} #define partition_forbid_list {"loader", "fdt_restore", "uboot", "factory_info", "ubi1_uc",NULL} #define partition_table_num 8 #define FLASH_PAGE_SIZE 2048 #define factory_info_max_size 1024 * 1024 #define FLASH_UPDATE_MEM_ADDR 33554432 #define FLASH_MAX_SIZE 0x8000000 #define FLASH_BLOCK_SIZE 0x20000 #endif
09-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值