Oracle DB daily partitioning

后端 未结 3 948
你的背包
你的背包 2021-02-09 14:43

I have the following table

  CREATE TABLE \"METRIC_VALUE_RAW\" 
   (    
    \"SUBELEMENT_ID\" INTEGER NOT NULL , 
    \"METRIC_METADATA_ID\" INTEGER NOT NULL ,          


        
3条回答
  •  悲哀的现实
    2021-02-09 15:13

    here is an example how to do it on Oracle 11g and it works very well. I haven't tried it on Oracle 10g, you can try it.

    This is the way, how to create a table with daily partitions:

    CREATE TABLE XXX (
        partition_date   DATE,
      ...,
      ...,
    )
    PARTITION BY RANGE (partition_date)
    INTERVAL (NUMTODSINTERVAL(1, 'day'))
    (
       PARTITION part_01 values LESS THAN (TO_DATE('2000-01-01','YYYY-MM-DD'))
    )
    TABLESPACE  MY_TABLESPACE
    NOLOGGING;
    

    As you see above, Oracle will automaticaly create separate partitions for each distinct partition_day after 1st January 2000. The records, whose partition_date is older than this date, will be stored in partition called 'part_01'.

    You can monitore your table partitions using this statement:

    SELECT * FROM user_tab_partitions WHERE table_name = 'XXX';
    

    Afterwards, when you would like to delete some partitions, use following command:

    ALTER TABLE XXX DROP PARTITION AAAAAA UPDATE GLOBAL INDEXES
    

    where 'AAAAAA' is parition name.

    I hope it will help you!

提交回复
热议问题