Partition on existing Tables

Hello

I want to archive a database due to too much data into DB everymonth, so I have to delete the records from the previous month, which is about 4 million.

Can someone give me idea to delete records as soon as possible. My opinion is to create the partition on the table and drop the partition once he becomes older.
But if I want to introduce the partition then I have to create a partition in an existing table. So please give me the best way to introduce the partition of the existing table.

It would really help that may suggest meanings.

Thank you

Spengler

Here is an example

CREATE TABLE my_table (
  id           NUMBER,
  description  VARCHAR2(50),
  create_date date
)PARTITION BY RANGE (create_date)
(PARTITION id_id0 VALUES LESS THAN (TO_DATE('26/08/2009', 'DD/MM/YYYY')) TABLESPACE users,
 PARTITION id_id1 VALUES LESS THAN (TO_DATE('27/08/2009', 'DD/MM/YYYY')) TABLESPACE users,
 PARTITION id_id2 VALUES LESS THAN (TO_DATE('28/08/2009', 'DD/MM/YYYY')) TABLESPACE users,
 PARTITION id_id3 VALUES LESS THAN (TO_DATE('29/08/2009', 'DD/MM/YYYY')) TABLESPACE users,
PARTITION id_id4 VALUES LESS THAN (TO_DATE('30/08/2009', 'DD/MM/YYYY')) TABLESPACE users,
PARTITION id_max  VALUES LESS THAN  (MAXVALUE) TABLESPACE users);

-Insert the sample data

 INSERT INTO my_table  VALUES (0, 'ZERO',sysdate);
INSERT INTO my_table  VALUES (1, 'One',sysdate+1);
INSERT INTO my_table  VALUES (2, 'Two',sysdate+2);
INSERT INTO my_table  VALUES (3, 'Three',sysdate+3);
INSERT INTO my_table  VALUES (4, 'Four',sysdate+4);
COMMIT;

-You can run these queries to check the output.

select * from my_table;
select * from my_table partition(id_id0);
select * from my_table partition(id_id1);
select * from my_table partition(id_id2);
select * from my_table partition(id_id3);
select * from my_table partition(id_id4);
select * from my_table partition(id_max);

-Split partition

ALTER TABLE my_table SPLIT PARTITION id_max AT (TO_DATE('01/09/2009', 'DD/MM/YYYY'))
INTO (PARTITION id_id5 TABLESPACE users,PARTITION id_max TABLESPACE users);

-Insert data into the new partition

INSERT INTO my_table  VALUES (5, 'FIVE',sysdate+5);
commit;

-check

select * from my_table partition(id_id5);

Tags: Database

Similar Questions

  • How to partition an existing table?

    Hi all

    Is there some way I can change a no compartmentalized partitioned table.
    We have a table with almost 4 million documents and we want that it partition by date (per day).

    Is this a good idea? or someone has another suggestion on this solution.

    Really appreciate any help on this.

    Thank you
    APS

    I have a similar question in my application that records the transaction in the transactions of several years table... Since keep us data for so many years it is difficult to maintain and affecting performance.

    We thought to use Oracle partitioning to partition the data in the table by month, then we will make transactions online on the score for the last few months.
    But Oracle partitioning comes with enterprise edition, and we need to purchase this license. Since its very expensive, the proposal was rejected by management.
    Then we got to know that we have only 13 months of data online.

    Creating archiving scripts to purge historical data and keep the backup of the entire database before the purge... so in case it is necessary to refer to older data for 13 months, we can restore the backup on any other DB and get that.

    You can think of the archiving of data.

  • Creating a partitioned table to an existing table interval.

    Hello

    Is there a way I can create a partitioned table interval of an existing table using DEC? I know how to create a partitioned table in range.

    create the table range_partitioned_table

    partition by range (date_column)

    (

    partition p1 lower ((to_date (' 08/01/2012 ',' mm/dd/yyyy'))),

    lower partition p2 values (to_date (' 09/01/2012 ',' mm/dd/yyyy')),

    PN VALUES LESS THAN (MAXVALUE) PARTITION

    )

    AS SELECT * from existing_table;

    Is there a similar way to the Interval partition an existing table?

    create the table interval_partitioned_table

    partition by range (date_column)

    interval (provide the interval)

    (

    partition p1 lower ((to_date (' 08/01/2012 ',' mm/dd/yyyy'))),

    partition p2 values less (to_date (' 09/01/2012 ',' mm/dd/yyyy')),

    -PN SCORE VALUES LESS THAN (MAXVALUE)

    )

    AS SELECT * from existing_table;

    For example:

    SQL > create table interval_partitioned_table
    2 partition by range (hiredate)
    interval of 3 (numtoyminterval(1,'YEAR'))
    (4)
    5 score below p1 ((to_date (' 08/01/2012 ',' mm/dd/yyyy'))),
    6 partition p2 values less (to_date (' 09/01/2012 ',' mm/dd/yyyy')),
    7 - PARTITION pN VALUES LESS THAN (MAXVALUE)
    8)
    9 AS SELECT * FROM emp;

    Table created.

    SQL >

    SY.

  • How add us partition on an existing table?

    Hi gurus,

    What would be the best way to add a partition to an existing table?

    Is there a simple documentation for example?

    Thank you

    What would be the best way to add a partition to an existing table?

    Is there a simple documentation for example?

    Was it something you were ask in an interview?

    You cannot add a partition to a table unless this table is a partitioned table.

    The table is already partitioned? If so, after the DDL.

    The Oracle documentation has examples of adding partitions to a table that is already partitioned

    Partition management

    Adding Partitions

    This section explains how to manually add partitions of a partitioned table and explains why partitions can be added specifically for partitioned more indexes.

    Adding a Partition to a partitioned Table range

    Use of the ALTER TABLE ... ADD PARTITION statement to add a new partition at the end 'high' (the point after the last existing partition). To add a partition at the beginning or in the middle of a table, use the SPLIT PARTITION clause.

  • Cannot add the partition to an existing table.

    Hello

    I don't add the partition to an existing table that is not partitioned, get the error as a type of data not valid, then I'm not find syntax errors.

    ALTER TABLE MESSAGEX_XCHANGE

    ADD THE PARTITION OF RANGE (LAST_MODIFY_TIMESTAMP)

    (

    PARTITION old_data VALUES LESS THAN (To_TIMESTAMP('27/02/2014','DD/MM/YYYY')),

    You see for VALUES LESS THAN (To_TIMESTAMP('28/02/2014','DD/MM/YYYY')) of the PARTITION

    );

    Error report:

    SQL error: ORA-00902: invalid data type

    1. 00000 - "invalid data type".

    * Cause:

    * Action:

    Thank you

    Manon...

    You get this error because your edit statement has an invalid syntax. In addition, you cannot partition a table that is not already configured for partitioning!

    You have to physically re-create the partitioned table in order to add new partitions to it.

  • modify an existing table to selectively the partition interval range

    I'm using Oracle 11.2.0.3.

    I have an existing table that has parition interval range.

    example:
     
    create table Log( ts date, level  varchar2(20), scr varchar2(2000))PARTITION BY RANGE (TS)
    INTERVAL( NUMTODSINTERVAL(1,'DAY'))
    Currently, we have the log of the table that is the partition of the range by day and we drop old parition to a week. However, we want to change this to persist the records in the table of WHICH = LEVEL "IMPORTANT."

    What is the best way to achieve this?

    >
    Is it possible to modify the existing interval partition table to add partition in the list?
    >
    Only using the DBMS_REDEFINITION to do online. And that always involves the creation of a "provisional" table

    If you have a window of failure just to create a new partitioned table the way you want to and INSERT the data into it. You should be able to use a DEC to do if you want. You may not use swap partition since all data must be physically moved.
    >
    Can we do list-interval partition table i.e. (with partition interval as partition sup)?
    >
    No - subpartitioning of interval is not currently supported.

    Here is the code example of a partitioned table by using the RANGE-interval LIST. It uses a VIRTUAL column, but you can ignore it for your use case

    DROP TABLE mytable;
    
    CREATE TABLE mytable
    (
    CREATION_DATE TIMESTAMP(6),
    LAST_MODIFIED_DATE TIMESTAMP(6),
    CREATION_DAY NUMBER(2) GENERATED ALWAYS AS (TO_NUMBER(TO_CHAR(CREATION_DATE, 'DD'))) VIRTUAL
    )
    PARTITION BY RANGE (LAST_MODIFIED_DATE) INTERVAL(NUMTOYMINTERVAL(1, 'MONTH'))
    SUBPARTITION BY LIST (CREATION_DAY)
       SUBPARTITION TEMPLATE
       ( SUBPARTITION days_1_5 VALUES (1,2,3,4,5)
       , SUBPARTITION days_6_10 VALUES (6,7,8,9,10)
       , SUBPARTITION days_11_15 VALUES (11,12,13,14,15)
       , SUBPARTITION days_16_20 VALUES (16,17,18,19,20)
       , SUBPARTITION days_21_25 VALUES (21,22,23,24,25)
       , SUBPARTITION days_26_31 VALUES (26,27,28,29,30,31)
       )
    (
       PARTITION prior_to_2013 VALUES LESS THAN (TO_DATE('2013-01-01', 'YYYY-MM-DD'))
    )
    
  • Type logic Partition of an existing table

    Dear all,

    My database is 10gr 2 and Linux is the operating system.

    One of my table in the production database is huge and contains lots of data. Table is growing daily. There are many queries that users run on this table and the selection criteria is normally the date of entry of the registration, it's an Entrty_Date field with the date data type.

    I want a partition logical on this table in such a way, the table name remains the same, and data are logically partitioned.

    As if the Entry_Date is from 2005, a partition is made on criteria:


    2005-2006
    2006-2007
    .
    .
    2011
    . at the request of the user for records having entry date > 2011... the query is made only this piece of the table, which makes the fast query.

    I hope that I am able to make you understand my problem. If its possible in Oracle please let me know the name of the method and I'll RND on this one. And I have to do it on an existing table that contains a lot of data.

    Thank you
    Imran

    Hello

    You can do this
    http://www.Oracle-base.com/articles/Misc/PartitioningAnExistingTable.php
    I suggest go fill through the myths of have from before backward Oracle documentation and to understand and then to proceed
    http://download.Oracle.com/docs/CD/B10501_01/AppDev.920/a96612/d_redefi.htm

    -Pavan Kumar N

  • Partitioning of an existing Table using the EXCHANGE PARTITION

    Hi all

    I have one unpartitioned table I partitioned by Exchange, this table has several indexes and constraints (primary and foreign).

    ALTER TABLE notpart_table ADD (
        CONSTRAINT PK_KCESPITI PRIMARY KEY (K_CESP, TIPORD)
            USING INDEX TABLESPACE TBLS_CONTA,
        CONSTRAINT FK_KCONTO_CE FOREIGN KEY (K_CONTO) REFERENCES xxxx (K_CONTO));
    
    CREATE INDEX IX_NFATTURA_CE ON notpart_tab (ANNO_FATTURA, K_REGISTRO, K_REGFA, TIPORD)
        TABLESPACE TBLS_CONTA;
    
    
    
    
    

    after Create a partitioned Table Destination

    notpart_table2, I created the same constraints and indexes defined in notpart_table


    When I run


    ALTER TABLE notpart_table2
      EXCHANGE PARTITION PART_notpart_table2
      WITH TABLE notpart_table
      WITHOUT VALIDATION
      UPDATE GLOBAL INDEXES;
    
    
    
    

    I get: ora-02266

    Why?

    Thanks in advance for any help


    Post edited by: vigilant Rosario

    It is not exactly what you have. Very probably not partitioned table, you are partitioning is the parent to another table table:

    SQL > create table tbl1 (id number)
    2.

    Table created.

    SQL > alter table tbl1
    2 Add the constraint tbl1_pk
    3 primary key
    4.

    Modified table.

    SQL > create table tbl2 (id number)
    2.

    Table created.

    SQL > alter table tbl2
    2 Add the constraint tbl1_fk1
    3 foreign key
    4 references tbl1
    5.

    Modified table.

    SQL > insert into tbl1 values (1)
    2.

    1 line of creation.

    SQL > insert into tbl2 values (1)
    2.

    1 line of creation.

    SQL > create table tbl1_part (id number)
    2 partition by range (id)
    3 (partition p1 values less than (1000000))
    4.

    Table created.

    SQL >
    SQL > alter table tbl1_part
    Exchange 2 partition p1
    3 with table tbl1
    4 without validation
    5 update global indexes
    6.
    with table tbl1
    *
    ERROR at line 3:
    ORA-02266: permit to unique/primary keys in table referenced by foreign keys

    SQL >

    If so, of the foreign key and recreate it pointing to the partitioned table as parent after finished partitioning the table.

    SY.

  • Limit the number of partitions of a table can have

    Hello

    It has been a while I think about a simple method and the best solution to a performance problem in my application. Benefiting from the table partitioning seems a simpler approach. It involves tiny my application code changes and more, it keeps the logic of global application 100% intact. However, sometimes the number of required partitions can grow to more than 500 thousand. I know another application implementation of partitions that 50 thousand for one of his paintings. I wonder if Oracle recommends or puts a limit to a number of partitions of the table can have. How does that limit, if it exists, varies so each of my partition table contains only a small amount of data. say, no more than 2 thousand records each of size 1 KB. What are the important considerations to keep in mind while creating the huge number of partitions of a table?

    All entries on this would be a great help.


    Thank you
    EXISTING


    PS: versions of Oracle 10 g from to consider.

    Published by: Olivia on December 30, 2009 09:46

    Published by: Olivia on December 30, 2009 09:50

    Hello

    Please visit the following link.

    Maximum number of partitions?

    Concerning

  • Create procedure upsert (name of the existing table, incoming table name)

    Is it possible to create a procedure that makes a merge (upsert) with only two parameters:

    1. Existing Table name - name of table that will have data merged into it.
    2. Incoming Table name - name of the table that has developed data day/news.

    The method would be:

    1. Use primary keys on the "existing" table as the condition links
    2. Fact and update if exists and insert new
    3. no record
    4. no clues
    5. no removal clause

    Oracle 11g

    MERGE < tip > < table_name >

    USING < table_view_or_query >

    (< CONDITION >)

    WHEN MATCHED THEN < update_clause >

    DELETE < where_clause >

    WHEN NOT MATCHED THEN < insert_clause >

    [ERRORLOG < log_errors_clause > < reject limit < integer | unlimited >];

    < table_name > - from input parameter

    < table_view_or_query > -socket input parameter

    < condition > - primary key links (how search a single/multiple primary keys and return the list?)

    < update_clause > - update all columns (other than KP, how to get and use a dynamic list of columns)

    < where_clause > - not used

    < insert_clause > - insert new records for all columns (including the PK (s))

    declare

    p_source varchar2 (30): = "EMP_X";

    p_target varchar2 (30): = "EMP_Y";

    query varchar2 (32000);

    function get_cols (p_table in varchar2) return varchar2 is

    VARCHAR2 (32000) retval;

    Start

    Select the Group (order of column_id) listagg (column_name, ',')

    in retval

    of user_tab_cols

    where table_name = p_table

    Table_name group;

    Return retval;

    end;

    function get_keys (p_table in varchar2) return varchar2 is

    VARCHAR2 (4000) retval;

    Start

    Select listagg (cc.column_name, ',') in the Group (order by cc.position)

    in retval

    from user_constraints c,.

    user_cons_columns cc

    where cc.table_name = p_table

    and c.constraint_type = 'P '.

    and cc.table_name = c.table_name

    and cc.constraint_name = c.constraint_name

    C.table_name group;

    Return retval;

    end;

    function merge (p_merge1 varchar2, p_merge2 varchar2, p_link varchar2) return varchar2 is

    Merge1 varchar2 (32000): = p_merge1 | «, » ;

    merge2 varchar2 (32000): = p_merge2 | «, » ;

    VARCHAR2 (32000) retval;

    Start

    then merge1 is not null

    loop

    retval: = retval | » t.'|| substr (Merge1, 1, InStr (Merge1, ',') - 1) |'s =.' | substr (merge2, 1, InStr (merge2, ',') - 1);

    Merge1: = substr (merge1, instr(merge1,',') + 1);

    merge2: = substr (merge2, instr (merge2, ',') + 1);

    If merge1 is not null then

    retval: = retval | p_link;

    end if;

    end loop;

    Return retval;

    end;

    Chopper (p_cols p_keys varchar2, varchar2) return varchar2 is

    passes varchar2 (32000): = ', '. p_cols | «, » ;

    keys varchar2 (32000): = ', '. p_keys | «, » ;

    VARCHAR2 (32000) retval;

    Start

    While the keys! = «, »

    loop

    If instr (passes, substr (keys, 1, instr(keys,',',1,2))) = 1 then

    cols: = substr (collars, instr(cols,',',1,2));

    on the other

    cols: = substr (passes, 1, instr (passes, substr (keys, 1, instr(keys,',',1,2))) | substr (collars, InStr (collars, ',', InStr (passes, substr (Keys, 1, InStr(Keys,',',1,2))), 2) + 1);)

    end if;

    keys: = substr (keys, instr(keys,',',1,2));

    end loop;

    return trim (both ',' collar);

    end;

    Start

    query: = 'merge'. p_target |' t ' |' using (select ' | get_cols (p_source): ' from ' | p_source |') s '.

    ' on ('|) Merger (get_keys (p_target), get_keys (p_source), 'and') |') ' ||

    "When matched then update set ' | '. Merger (Chopper (get_cols (p_target), get_keys (p_target)), Chopper (get_cols (p_source), get_keys (p_source)), ',').

    «When not matched then insert ('|)» get_cols (p_target) |') values (s.'|) Replace (get_cols (p_source),', ', ', s') |') ';

    dbms_output.put_line (Query);

    end;


    Fusion in EMP_Y t using (select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO EMP_X) s on (t.EMPNO = s.EMPNO and t.ENAME = s.ENAME) when matched then update set t.JOB = s.JOB, t.MGR = s.MGR, t.HIREDATE = s.HIREDATE, t.SAL = s.SAL, t.COMM = s.COMM, t.DEPTNO = s.DEPTNO when not matched then insert (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (s.EMPNO, s.ENAME, s.JOB, s.MGR, s.HIREDATE, s.SAL, s.COMM, s.DEPTNO)

    Concerning

    Etbin

  • ADOBE Acrobat Pro DC - add lines to an existing table

    Hello. I have an existing table, I need to add lines.  Is this possible? Thanks in advance.

    It is very difficult to do something like this in a PDF file (unless it was created using LiveCycle Designer).

    You will be better off by changing the original file, and then creating a new PDF from it.

  • How to add the new column in existing table to our desired location?

    How to add the new column in existing table to our desired location?

    For example, I have to add the new column 'course' before the salary column in the emp table.

    I think the best way is to add the column at the end of the table and create a new view with the order of the columns...

    Another option...

    places the data into a temporary table and recreate the table with the correct order of the columns, and then insert data to the table from the temporary table

    Refer

    Add column (from table) in the desired position

    Example:

    CREATE TABLE temp_my_user LIKE)

    SELECT * FROM password);

    DROP TABLE password;

    (Password) CREATE TABLE

    userID NUMBER

    , first name VARCAHR2 (25)

    , middleInitial VARCHAR2 (1)

    (, name VARCHAR2 (25));

    INSERT INTO password (userID, firstName, lastName)

    (SELECT username

    first name

    lastName

    OF temp_my_user);

    DROP TABLE temp_user;

  • Add the cluster to an existing table in oracle

    Is it possible to add the cluster of an existing table? For example...

    I have a table:

    CREATE TABLE table_name)

    t_id number PRIMARY KEY,

    t_name varchar2 (50));

    Cluster:

    CLUSTER to CREATE my_cluster

    (c_id NUMBER) SIZE 100;

    Y at - it a command such as: ALTER TABLE t_name add CLUSTER my_cluster (t_id); or something like that?

    Because I want to table to look like this:

    CREATE TABLE table_name)

    t_id number PRIMARY KEY,

    t_name varchar2 (50))

    My_cluster (t_id) CLUSTER;

    And drop all the tables isn't really what I want to do.

    Thank you

    No,

    It is the reverse:

    A table can be stored as a segment of memory (the common way) or in a cluster.

    Will not be part of the table "in the cluster", but other parts outside.

    Please create a new table in the cluster and insert your data here.

    Sorry,

    Martin

  • Add the constraint not NULL in the existing table that has null values

    Hello

    I want to add a constraint not null to and an existing table, but the table already contains values null in this column.

    EMP

    Emp_id name

    1 axada

    2

    3 sdkdd

    Here is already the data IE 2 empid is Null as name. I must add a fool of constraint not null which new values will not be null, but I don't want to change the data of exisitng alreadt which is null.

    Hello

    "The opposite": NOVALIDATE does not validate the data that is ALREADY in the table, but do not allow the insertion of a NULL value.

    Have you tried my sample code?

    CREATE TABLE MaTable (x NUMBER PRIMARY KEY, y NUMBER);

    INSERT INTO myTable VALUES (1, 123);

    INSERT INTO myTable VALUES ( 2, NULL );

    INSERT INTO myTable VALUES (3, 456);

    ALTER TABLE mytable MODIFY (y NOT NULL NOVALIDATE );

    INSERT INTO myTable VALUES (4, 678);

    INSERT INTO myTable VALUES ( 5, NULL );

    SELECT * FROM MyTable;

    '2' line was inserted with null before the creation of the NOT NULL constraint, this line remains "as what" at the end of the trial.

    '5' line trying to insert a NULL value after creating the NOT NULL constraint, which is denied.

    Best regards

    Bruno.

  • How can I add data file to an existing table on Oracle RAC ASM with no OMF? Thank you!

    How can I add data file to an existing table on Oracle RAC ASM with no OMF? Thank you!

    Hello

    So I guess you have some files in ASM, see your first existing file structure

    Select file_name

    from dba_data_files;

    and to add to an existing table, the example below (even if you're better sticking with OMFs!)-is that what you are looking for?

    SQL > create tablespace TEST1

    2 datafile '+ DATA' size 1 M;

    Created tablespace.

    SQL > select file_name in dba_data_files;

    FILE_NAME

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

    +Data/orcl2/datafile/users.259.859820983

    +Data/orcl2/datafile/undotbs1.258.859820983

    +Data/orcl2/datafile/SYSAUX.257.859820983

    +Data/orcl2/datafile/system.256.859820981

    +Data/orcl2/datafile/example.269.859821049

    +Data/orcl2/datafile/Test1.271.859843053

    6 selected lines.

    SQL > alter tablespace TEST1

    2 Add datafile ' + DATA / mynewfile01.dbf ' size 2 m;

    Tablespace altered.

    SQL > select file_name in dba_data_files;

    FILE_NAME

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

    +Data/orcl2/datafile/users.259.859820983

    +Data/orcl2/datafile/undotbs1.258.859820983

    +Data/orcl2/datafile/SYSAUX.257.859820983

    +Data/orcl2/datafile/system.256.859820981

    +Data/orcl2/datafile/example.269.859821049

    +Data/orcl2/datafile/Test1.271.859843053

    + DATA / mynewfile01.dbf

    Thank you

Maybe you are looking for

  • email does not work in firefox

    I have three emails from domain, in which one of them stopped working with firefox. All three works with internet explorer or google chrome. There is one who does not work with firefox.

  • Error BIOS acpi with Windows XP SP2 home edition on model Sat Pro 4310

    Hello I get this message in my event logsIs there a way (update, etc.) to come around him Thanks in advance William

  • Cannot rename the old DAQmx tasks via NI MAX

    Hello I NI MAX 15.3 and DAQmx 15.1.1 installed. I am facing a strange problem. When I try to rename any task DAQmx via NI MAX, I get this error message: The thing is, the chosen name is NOT in use and does not contain illegal characters! (I tried sev

  • Dell Laptop XP account, don't have login information

    I was given an old dell laptop with windows xp service pack 2.  I don't have a connection or anything so I can do something with it. It won't let me even wipe it. Help, please. I tried administrator accounts and invited. I also tried password unlocke

  • E3200 unable to connect to the Internet

    I bought a new E3200 to replace my old Linksys router.  It finds my computers and set up a network, but unable to connect to the internet via my Comcast cable modem.  I read on this forum to the questions of the Mac address, but it has located the Ma