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-2010     Type HOWTO     Status 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> CREATE TABLE unpar_table (
id NUMBER(10),
create_date DATE,
name VARCHAR2(100)
);


2) Apply some constraints to the table:

SQL> ALTER TABLE unpar_table ADD (
CONSTRAINT unpar_table_pk PRIMARY KEY (id)
);

SQL> CREATE INDEX create_date_ind ON unpar_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> CREATE TABLE par_table (
id NUMBER(10),
create_date DATE,
name VARCHAR2(100)
)
PARTITION BY RANGE (create_date)
(PARTITION unpar_table_2005 VALUES LESS THAN (TO_DATE('01/01/2005', 'DD/MM/YYYY')),
PARTITION unpar_table_2006 VALUES LESS THAN (TO_DATE('01/01/2006', 'DD/MM/YYYY')),
PARTITION unpar_table_2007 VALUES LESS THAN (MAXVALUE));


5) Start the Redefinition Process:

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

SQL> EXEC Dbms_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> ALTER TABLE par_table ADD (
CONSTRAINT unpar_table_pk2 PRIMARY KEY (id)
);

SQL> CREATE INDEX create_date_ind2 ON par_table(create_date);

e) Gather statistics on the new table:

SQL> EXEC DBMS_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> DROP TABLE par_table; 

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

ALTER TABLE unpar_table RENAME CONSTRAINT unpar_table_pk2 TO unpar_table_pk;
ALTER INDEX create_date_ind2 RENAME TO create_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.csdn.net/tianlesoftware

网上资源: http://tianlesoftware.download.csdn.net

相关视频:http://blog.csdn.net/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
<think>好的,我现在需要分析用户提供的C头文件`partition_table.h`,并给出详细解释。用户之前讨论了固件镜像的构建过程,包括Makefile中的分区配置和UBI卷定义,现在他们想知道这个头文件的作用以及相关问题。 首先,我需要理解这个头文件的结构和内容。头文件通常用于定义常量、宏、数据结构等,供其他C代码使用。用户提供的头文件中包含大量的宏定义,涉及分区名称、文件名、大小、版本等信息。这些宏看起来与之前讨论的Makefile中的分区配置相关联,比如loader、fdt、uboot等分区。 接下来,我需要将这些宏分门别类,解释它们的用途。例如,`partition_table_list`可能用于在代码中引用所有分区的名称,而`partition_table_size`可能存储每个分区的大小。同时,注意到有些宏如`partition_flash_list`和`partition_upboot_list`可能分别对应固件镜像中的文件和升级时使用的文件。 还要注意版本控制、有效大小、访问控制列表(如`partition_forbid_list`)以及一些硬件相关的定义,如FLASH_PAGE_SIZE等。这些定义可能在固件运行时用于内存管理、升级验证等。 用户可能想知道这个头文件如何与之前的Makefile配置关联,以及它在固件构建和运行中的作用。此外,可能需要解释如何通过修改这个头文件来调整分区配置,或者如何验证这些配置是否正确应用。 需要确保回答覆盖头文件的各个部分,解释每个宏组的作用,并指出它们在系统中的实际应用场景。同时,根据用户的历史问题,可能需要关联到固件镜像的生成过程,比如这些宏是否影响最终生成的.bin或.ubi文件。 最后,生成相关问题时,要围绕头文件内容,可能涉及配置验证、修改影响、版本控制、硬件参数调整等方面,帮助用户深入理解分区管理的细节。</think>### **代码解析:`partition_table.h` 分区配置头文件** 该头文件定义了 **固件分区布局的静态信息**,包括分区名称、大小、关联文件、访问控制规则及硬件参数。其核心作用是 **为固件运行时提供分区元数据**,确保固件构建、升级、运行时的分区操作与配置一致。 --- ### **1. 分区名称与列表** ```c #define partition_table_loader "loader" #define partition_table_list {partition_table_loader, ..., NULL} ``` - **功能**:定义所有物理分区的名称字符串,并生成一个以 `NULL` 结尾的字符串数组。 - **用途**: - 在代码中通过字符串名称操作分区(如查找、校验)。 - 遍历分区时使用(如升级、校验流程)。 --- ### **2. 分区大小与属性** ```c #define partition_table_size {0x40000, 0x100000, ...} #define partition_table_valid_size {0x0, 0x0, 0x10000, ...} #define partition_table_version {1, 0, 1, 1, ...} ``` - **`partition_table_size`**: - 每个分区的总大小(十六进制),与 Makefile 中的 `ADD_TO_TABLE` 配置一致。 - **`partition_table_valid_size`**: - 分区中有效数据的最小大小(部分分区可能预留空间但实际数据较小)。 - 例如:`factory_info` 的有效大小为 `0x10000`,表示其实际数据不超过该值。 - **`partition_table_version`**: - 分区的版本标志,用于升级时校验兼容性(版本不匹配时可能阻止升级)。 --- ### **3. 固件文件映射** ```c #define partition_flash_loader "loader.bin" #define partition_flash_list {partition_flash_loader, ..., NULL} ``` - **功能**:定义每个分区对应的固件文件名(如 `loader.bin`, `ubi1.bin`)。 - **用途**: - 构建时将分区数据打包为独立文件。 - 升级时从文件加载数据到对应分区。 --- ### **4. 升级相关配置** ```c #define partition_upboot_list {partition_upboot_fdt, ..., NULL} #define partition_upboot_name {"fdt", "pt_table", ...} ``` - **功能**:定义升级过程中涉及的文件名和分区名称。 - **用途**: - 升级工具根据此列表识别需更新的分区(如 `ubi1_bootloader`)。 - 指定升级时使用的文件路径(如 `pt_table_upboot.bin`)。 --- ### **5. UBI 卷配置** ```c #define partition_ubivol_list {"ubi1_bootloader", ...} #define partition_ubivol_size {0x80000, 0x100000, ...} ``` - **功能**:定义 UBI 设备(如 `ubi1`)中的逻辑卷名称、大小及有效大小。 - **用途**: - UBI 子系统初始化时根据此配置创建逻辑卷。 - 升级工具验证 UBI 卷的大小和版本是否匹配。 --- ### **6. 访问控制与校验** ```c #define partition_check_name {"fdt", "ubi1_bootloader", ...} #define partition_forbid_list {"loader", "ubi1_uc", ...} ``` - **`partition_check_name`**: - 需校验完整性的分区列表(如 `fdt` 设备树)。 - 校验失败时可能阻止启动或升级。 - **`partition_forbid_list`**: - 禁止直接修改的分区列表(如 `loader` 引导程序)。 - 尝试写入时会触发访问拒绝错误。 --- ### **7. 硬件参数定义** ```c #define FLASH_PAGE_SIZE 2048 #define FLASH_BLOCK_SIZE 0x20000 #define FLASH_MAX_SIZE 0x8000000 ``` - **功能**:定义 Flash 存储的物理特性。 - **用途**: - 分区对齐:确保分区大小为 `FLASH_BLOCK_SIZE` 的整数倍。 - 内存管理:计算擦写次数、垃圾回收策略等。 --- ### **8. 特殊用途配置** ```c #define partition_expack_list {"ubi1_isp", NULL} #define partition_expack_type_list {CONTENT_TYPE_ISP_CONFIG_DMIC} ``` - **功能**:定义需特殊处理的分区及其内容类型(如 `CONTENT_TYPE_ISP_CONFIG_DMIC`)。 - **用途**: - 在升级或导出时,附加额外处理逻辑(如加密、校验)。 --- ### **9. 配置验证与调试** - **验证分区与文件一致性**: - 检查 `partition_flash_list` 中的文件是否存在于固件构建输出目录。 - 使用 `file` 命令确认文件大小与 `partition_table_size` 匹配。 - **调试分区访问控制**: - 尝试写入 `partition_forbid_list` 中的分区,验证是否触发错误。 - 检查 `partition_check_name` 中的分区校验逻辑是否生效。 --- ### **相关问题** 1. 如何通过修改 `partition_table.h` 调整某个分区的大小?需要同步更新哪些 Makefile 配置? 2. `partition_table_valid_size` 与 `partition_table_size` 的差异如何影响固件升级? 3. 若新增一个 UBI 卷(如 `ubi1_logs`),需要在哪些头文件或 Makefile 中添加配置? 4. `FLASH_PAGE_SIZE` 和 `FLASH_BLOCK_SIZE` 的设置如何影响分区对齐和性能? 5. 如何验证 `partition_check_name` 中的分区校验逻辑是否正确执行?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值