Oracle database due to index expiration prompt ORA-14400: inserted partition key does not map to any partition problem description and solution

Problem description: At the beginning of the project, some data tables with a relatively large amount of data were partitioned. The partition field was partitioned according to the date. At that time, the partition was only created until March 1st, and it was finished when the date was switched to March 1st. The entire partitioned data table cannot be inserted into the data, oracle prompts ORA-14400: inserted partition key does not map to any partition error (the entire batch server exploded........ Brain fills the mood at the time) Fortunately, it was still in a quasi-production environment at that time, and the impact was not significant.

solution:

1. Manually re-create the partition (created until the end of the year), but this method will still have problems waiting until the end of the time.

The creation statement is as follows: alter table table name add partition partition name values ​​LESS THAN (partition field);

示例:alter table test add partition P5 values LESS THAN (TO_DATE('2020-04-01','YYYY-MM-DD'));

            alter table test1 add partition P5 values LESS THAN ('20200501');

You can also execute such a statement: alter table test add partition pmax values ​​less than (maxvalue);

But in this case, if the previous partition has expired, then all subsequent data will be placed in the pmax partition, which violates the concept of table partitioning and is not recommended

2. Automatically create table partitions (recommended, but it is said on the Internet that it will have a certain impact on the performance of the database).

The creation statement is as follows:

DROP TABLE  test;
-- 创建表及建立表分区
create table test
(
   ID NUMBER(20) not null,
   REMARK VARCHAR2(1000),
   create_time DATE
)PARTITION BY RANGE (CREATE_TIME) INTERVAL (numtoyminterval(1, 'year'))(partition P1 values less than(to_date('2018-11-01', 'yyyy-mm-dd')));

Note: The automatic partition creation is only applicable to the date type of the partition field, which can be created by year, month, week, and day. For details, please refer to this article https://www.cnblogs.com/yuxiaole/p/9809294.html
- Insert Test data
INSERT INTO test VALUES(23234,'asfafaf',to_date('2019-11-01','yyyy-mm-dd'));
- Test query
SELECT * FROM test;
SELECT * FROM test partition(P1) ;
- Query by partition
SELECT * FROM test partition(SYS_P7901);
- View table partition
select partition_name from user_tab_partitions where table_name='TEST;
select * from USER_PART_TABLES a where a.table_name=upper('TEST');

Note : After creating a new table partition, it is best to rebuild the index of the corresponding table again

Execution statement: alter index index name rebuild;

 

 

Guess you like

Origin blog.csdn.net/u013804636/article/details/104606658