2024年1月17日发(作者:)

oracle partition维护操作()

oracle event 10434 and drm

cache fusion and coordination of inter forum

execute immediate动态sql的使用总结

oracle data & temp files management

分区表维护的常用命令.

alter table

- drop partition

- add |

- rename |

- modifity |

- truncate |

- split |

- move |

- exchange |

分区索引的常用维护命令.

alter index

- drop partition

- rebuild |

- rename |

- modifity |

- split |

- parallel

- unusable

1、alter table drop partition

用于删除table中某个partition和其中的数据, 主要是用于历史数据的删除.如果还想保留数据, 就需要合并到另一个partition中.

删除该partition之后, 如果再insert该partition范围内的值,

要存放在更高的partition中.如果你删除了最大的partition, 就会出错.

删除table partition的同时, 删除相应的local index.即使该index是iu状态.

如果table上有global index, 且该partition不空, drop index

index partition会使所有的global 为iu状态.如果不想rebuil,

可以用sql语句手工删除数据, 然后再drop score.

例子.

altr dec96 atbel sales drop partition.

到底是drop partition或者是delete?

如果global index是最重要的, 就应该先delete 数据再drop

score.

在下面情况下, 手工删除数据的代价比drop partition要小

- 如果要删除的数据只占整个table的小部分

- 在table中有很多的global index.

在下面情况下, 手工删除数据的代价比drop partition要大

- 如果要删除的数据占整个table的绝大部分

- 在table中没有很多的global index.

如果在table是父table, 有被引用的约束, 且partition不空,

drop partition时出错.

如果要删除有数据的partition, 应该先删除引用约束.或者先delete, 然后再drop score.

如果table只有一个partiton, 不能drop 只能drop partition

table.

2、alter index. drop partition

overall 删除partiotn index上删除index和index entry, 一般用于平衡i.

index.不能显式的drop index必须是global local index partition,

不能删除最大的index.

删除之后, insert属于该partition的值时候, index建立在更高的partition.

如果包含数据的partition删除之后, 下一个partition是iu状态,

必须rebuild.可以删除iu状态的partition, 即使它包含数据.

3、alter rename partition table / index.

主要用于改变隐式建立的index name.

可以是iu状态 index.

rename 一般的index可以用alter index.

4、alter table. add partition.

只能加到最后一个partition之后.一般用于数据会单调增长的地方,

比如每周 / 月 / 年会增加新的历史数据等.

split可以在中间插入partition.

the than的第一个值是maxvalue 如果values, 就不能增加partition.必须split.

the local 该命令也可以给自动增加partition partition名字和table partition一致 index.新的local index.

新的本地分区索引使用前一个索引分区表分区表空间的缺省值,存放在同样的。

不影响全球指数。

即使表有指数或者索引分区是IU状态也可以增加分区。

5、更改表/索引修改分区

1)更改表修改分区

修改分区的物理属性,比如分配更多的延伸。

如果要移动到新的或者改变创建表空间,建立的属性,就需要ALTER

TABLE移动分区。

2)更改索引修改分区

修改指数的物理属性。

可以增减更多的程度

必须是全球/本地分区索引。

改变表/索引…修改分区…不可用。

如果要把变成可用不可用,

-重建索引分区

滴+重现包含这个分区的指数。

如果修改表…的物理属性,值放在数据字典,只有添加分区的时候才使用的属性不会改变现有的分区。

比如:表0销售PCTFREE PCTUSED 20。

改变指数直接修改分区和nonpartition的物理属性。

如果修改分区索引的物理属性,也是值放在数据字典,只有建立新的indexpartition的时候才使用的属性不会改变现有的分区。

如果指数是全球的,在修改索引拆分分区的时候用到。如果是本地索引,在隐式的增加索引分区的时候用到,比如修改表添加分区或者分割分区。这样就可以控制ALTER TABLE建立局部指标的属性了。

如果指数是nonpartition的,标记为指标无法使用,不允许改变命令的时候设置其属性只能在重现。

6、修改表分区不能使用本地索引

把表所有相关的局部指标设置为可用。用于要进行大规模的DML操作的时候。

不可用的方法-->:

-更改索引重建分区

-修改表分区,重建无法使用的本地索引

可以查询DBA /所有/ user_partitions看指数的状态。

7、修改表,修改分区,重建本地索引

重建该上所有不可用的本地索引表。

8、更改索引…不可用

-可以对分区/ nonpartition指数。

-可以使nonpartition指数为不可用状态。

-可以使所有的索引分区为不可用状态。

-处于IU状态的nopartition指数必须重建,或者滴+重现。

-一次只能重建一个分区索引。

-对处于不可用状态的全球指数,下跌+重现的效率要高于重建。

9、更改索引…重建分区…

用于重建索引的一个分区,如果不需要重现一个大的指数,用这个命令修复之。

也可以用于把一个索引分区移动到另外的表空间,或者改变创建时候的物理参数,或者作为分裂操作的最后一步。

并行重建:

-如果重建的时候指定并行,则使用之;

-否则使用指数缺省的并行属性;

-否则使用表缺省的并行属性;

-否则不使用并行。

10、改变会话设置skip_unusable_indexes

允许用户在有可用指数或者索引分区的表上进行DML操作。否则就会产生错误。用在进行大规模的修改和加载数据的时候,推迟指数的维护。

但是如果查询指定不可用的指数或者索引分区,依然会报错。

不能跳过对不可用的唯一索引的维护。

11、更改表拆分分区

建立两个新的分区,有自己新的段,新的物理属性,和初始程度。原来分区的段都丢弃。

用在如果分区太大,导致备份、恢复和维护操作时间很长,可以考虑使用分表。

也可以用在重新分布I/O负载。

在分割分区的时候,同样建立相应的本地索引。

如果在分裂的时候出现问题,新的段就删除,语句回滚。

指数即使是不可用的,索引分区也可以分裂。

例子:

ALTER TABLE部分分割分区depot4

在('40-001”)为

分区表空间(depot4 ts009 minextents 2,

分区表空间ts010 depot9

);

原来的索引分区缺省的物理属性用于新的局部索引分区表分区表空间,存放在的里除非已经定义了表空间。

新分离出来的包含数据的索引分区被设置为不可用,空的索引分区的指数是有效的。

12、更改索引分割分区

把全球指数的一个分区分为两个分区。注意必须是全球的,不能自己来分裂指数。

建立新的索引段,不再使用原来的空间。

如果是切分不可用的索引分区,则新的索引分区都是不可用的必须重建。

如果索引分区包含数据,则新的分区都是不可用的。

13、更改表移动分区

删除旧的数据段,建立新的段,即使没有指定新的表空间。

用于把数据移动到其他的分区,重新组织数据减少碎片,或者改变物理属性。

如果指定了分区名字,则移动分区之后,影响所有的为不可用包括指数。

-所有全局分区索引

-每个局部指标的相应分区表空间,但是它们的属性不变。

并行度:

如果在移动中指定,则使用之,

否则使用表缺省的并行设置,

否则就不使用并行了。

但是要注意的是移动命令中的并行不改变表本身的并行设置。

如果使用nologging,这个分区应该周期性的备份。

14、更改表交换分区

可以把非分区的表和分区的数据交换。

这个过程是双向的。

实际上不交换数据。

在数据字典进行更改。

这个表必须是存在的,不能是分区表或者是簇表。

用户必须对两个表有改变权限。

这两个表不能有任何约束。

不激活任何触发。

这两个PT和T必须有相同的结构:相同的柱,柱类型和大小相同的。

影响到它们的全球指数。

例子:

修改表的销售交流sales_feb97分区表feb97;

可以带的参数是

WITH VALIDATION: check the sales_feb97 table and return errors

if there is a problem.

WITHOUT VALIDATION: don't check TABLE sales_feb97, check by the

user himself.

IINCLUDING INDEXES: swap their index, where index must be of

the same type.

EXCLUING INDEXES: the associated INDEX is not available.

The related statistical information of TABLE and PARTITION is

also exchanged, including TABLE, CLUMON, INDEX statistics and

histogram. The overall information of PARTITION TABLE needs to

be re counted.

Their LOG properties are also exchanged.

15, modify the logical attributes of table

For example, adding new column, constraints, changing the type

of cloumn, or enable constraints. If partition table, these

attributes are for all partition.

Rules for changing logical attributes:

- cannot change the type and length of cloumn used as table

partition key.

- cannot change the type and length of cloumn used as index

partition key.

You can't add LONG, LONG RAW

You can't change columns to LONG, LONG RAW

For a TABLE with PARTITION on a read-only TABLESPACE, the new

column cannot have default values

For TABLE with PARTITION on read-only TABLESPACE, it cannot be

changed from VARCHAR, VARCHAR2 to CHAR

For TABLE with PARTITION on read-only TABLESPACE, the length

of CHAR cannot be increased.

If you want to add unique index /PK, ORACLE will do the

corresponding operation:

If there is already a unique index on these COLUMN, then use

it.

Error is returned if there is a non unique index

If there is a unique index, but is not available, the error is

returned

Otherwise, ORACLE builds GLOBAL NOPARTITION INDEX.

16, ALTER TABLE..TRUNCATE PARTITION

Delete all the data in PARTITION, faster than DELETE.

At the same time, the corresponding LOCAL INDEX data is deleted,

even if the INDEX is not available. At the same time, the

unavailable INDEX is set to VALID. The INDEX space is released

or waiting for reuse, depending on the TABLE PARTITION DROP

STORAGE or REUSE STORAGE.

If there is GLOBAL INDEX, and PARTITION contains data, it

becomes unusable. If you want to avoid this, you can first

DELETE data, and then TRUNCATE PARTITION.

If TABLE is referenced by other tables, and PARTITION is not

empty, the error is returned. You can either DISABLE first, or

DELETE first, then TRUNCATE.

Non stimulated TRIGGER.

17, PARALLEL

Changing the parallel attributes of INDEX.

The following operations require ALTER permissions and

permissions for DROP ANY TABLE

- ALTER TABLE DROP PARTITION

- ALTER TABLE TRUNCATE PARTITION

The following operations require ALTER permissions and spatial

allocation permissions on TABLESPACE

- ALTER INDEX MODIFY PARTITION

- ALTER INDEX REBUILD PARTITION

- ALTER INDEX SPLIT PARTITION

- ALTER TABLE ADD PARTITION

- ALTER TABLE SPLIT PARTITION

- ALTER TABLE MODIFY PARTITION

- ALTER TABLE MOVE PARTITION

19. Related data dictionary

USER/ALL/DBA_PART_TABLES

USER/ALL/DBA_PART_TINDEXES

USER/ALL/DBA_PART_KEY_COLUMNS

USER/ALL/DBA_TAB_PARTITIONS

USER/ALL/DBA_IND_PARTITIONS

USER/ALL/DBA_PART_COL_STATISTICS

USER/ALL/DBA_TAB_COL_STATISTICS

USER/ALL/DBA_PART_HISTOGRAMS

USER/ALL/DBA_TAB_HISTOGRAMS

USER/ALL/DBA_OBJECTS

USER/ALL/DBA_TABLES

USER/ALL/DBA_INDEXES

USER/ALL/DBA_TAB_COLUMNS

20, the new COLUMN in PLAN_TABLE

PARTITION_START

PARTITION_STOP

PARTITION_ID

A new step was added to the analysis procedure: PARTITION

In addition, there are steps to refer to PARTITION in the access

steps of TABLE/INDEX.

PARTITION_START and PARTITION_STOP

Determine the beginning / end of the PARTITION range

Values include:

NUMBER (n): the first N PARTITION identified by the SQL compiler

KEY: start time from the beginning of a PARTITION KEY value

ROW LOCATION: start / end time from a line

The PARTITION range accessed by INVALID: is empty.

PARTITION ID: PARTITION value pairs beginning at the end of

storage.

OPTION column:

You can have CONCATENATED/SINGLE/EMPTY on the PARTITION step

PARTITION result set for CONCATENATED: merge access

SINGLE: the instruction is a single PARTITION at run time

The PARTITION accessed by EMPTY: is empty

When TABLE access is determined according to the ROWID range,

you can have the following values:

BY USER ROWID

BY INDEX ROWID

BU GLOBAL INDEX ROWID

BY LOCAL INDEX ROWID

21, the conventional path of SQL*Loader

You can use a regular path SQL*Loader for a partition table,

no new syntax, use the insert statement, and update the

local/global index. Multiple load can be executed

simultaneously for one table.

You can load one partition data at a time, you must specify the

table and partition in the control file load. Not in the data

partition of the badfile.

22, the direct path of sql*loader

There is no new syntax added.

Index auto update.

Specify table and partition name, DIRECT=TRUE

If you're running the entire TABLE in LOAD, you can't run other

LOAD at the same time

If you don't have GLOBAL INDEX, you can run LOAD on different

PARTITION.

Parallel direct load can also be implemented on a partition:

- PARALLEL=TRUE must be specified

The relevant LOCAL INDEX PARTITION is set to be unavailable and

must be rebuilt itself.

There's no GLOBAL INDEX

Concurrent path LOAD for different PARTITION can be implemented

concurrently on a TABLE.

23, EXPORT

Still support FULL/USER/TABLE

PARTITION only supports TABLE mode

TABLE:PARTITION must be specified

24, IMPORT

You can take DUMP from the PARTITION/NONPARTITION TABLE file,

IMPORT to the partition or not partition files.

Support FULL/TABLE/USER

If the original TABLE is PARTITION, IMPORT builds PARTITION

TABLE.

All PARTITION TABLE above the current maximum KEY value will

be rejected.

TABLE:PARTITION must be specified.

You can set SKIP_UNUSABLE_INDEXES and skip the INDEX. that

can't be used

25, ALALYZE

The goal of the analysis can be a single PARTITION, the whole

TABLE or INDEX.

Analyze the statistical information of TABLE, INDEX, COLUMN,

and merge them together. But they don't merge their HISTOGRAM.

The ORACLE optimizer finds that the associated PARTITION is not

analyzed and uses the default TABLE/INDEX.