Exchange Partition

Hi,
What happens when :
1. A query is running on a partition table has millions of records.
2. Alter table exchange partition ... issued
Does it completes step (1) first and than it takes (2)step or how it handles? Or will it show wrong result in the query? Please help.

I have a case for the need to exchange partitions between two range partitioned tables. For example table SALES_HIST contains millions of sales records from the last 5 years range partitioned by fiscal year and month.
The need arises to add new columns to the table for the current year and going forward. The new columns are meaningless to prior years so the decision is made to move data older than the prior year to separate tables which should retain the fiscal year/month partitioning for performance.
If we had the ability to exchange partitions between partitioned tables, this would be a simple matter of a series of DDL statements to create the new table(s) and index(es) and then exchange partitions from the current table to the new table. Instead, we are forced to create the table, insert into NEW_TAB /*+ append */ select * from SALES_HIST, alter table sales_hist drop partition, create indexes on new_tab; repeat ad nauseum. And, since the volume of data is huge, we are forced to insert piecemeal else we blow out temp space and drag the system to a crawl.

Similar Messages

  • Materialized view on a Partitioned Table (Data through Exchange Partition)

    Hello,
    We have a scenario to create a MV on a Partitioned Table which get data through Exchange Partition strategy. Obviously, with exchange partition snap shot logs are not updated and FAST refreshes are not possible. Also, this partitioned table being a 450 million rows, COMPLETE refresh is not an option for us.
    I would like to know the alternatives for this approach,
    Any suggestions would be appreciated,
    thank you

    From your post it seems that you are trying to create a fast refresh view (as you are creating MV log). There are limitations on fast refresh which is documented in the oracle documentation.
    http://docs.oracle.com/cd/B28359_01/server.111/b28313/basicmv.htm#i1007028
    If you are not planning to do a fast refresh then as already mentioned by Solomon it is a valid approach used in multiple scenarios.
    Thanks,
    Jayadeep

  • Oracle Exchange partition feature not working as expected?

    I used the Exchange Partition feature to swap segments between 2 tables- one Partitioned, and one Non-Partitioned. The exchange went well. However, all the data in the partitioned table has gone to the partition which stores the maxbound values.
    Any ideas if this is the default behavior or have i missed out something?
    /** actual table names changed due to client confidentiality issues */
    -- Drop the 2 intermediate tables if they already exist
    drop table ordered_inv_bkp cascade constraints ;
    drop table ordered_inv_t cascade constraints ;
    1st create a Non-Partitioned Table from ORDERED_INV and then add the primary key and unique index(s):
    create table ordered_inv_bkp as select * from ordered_inv ;
    alter table ordered_inv_bkp add constraint ordinvb_pk primary key (ordinv_id) ;
    create unique index ordinv_scinv_uix on ordered_inv_bkp(
    SCP_ID ASC,
    INV_ID ASC,
    ANATLOC_ID ASC,
    SOI_ID ASC,
    CANCEL_TS ASC );
    -- Next, we have to create a partitioned table ORDERED_INV_T with a similar
    -- structure as ORDERED_INV.
    -- This is a bit tricky, and involves a pl/sql code
    declare
    l_dt_start DATE;
    l_ptn VARCHAR2(50);
    cnt PLS_INTEGER;
    l_cnt_initial PLS_INTEGER;
    ts_name VARCHAR2(50);
    l_sql VARCHAR2(10000);
    ts_indx VARCHAR2(100);
    l_num_errors NUMBER ;
    l_num_errors_ok NUMBER ;
    l_user_name VARCHAR2(50) ;
    l_sysdate VARCHAR2(50);
    l_cnt_script PLS_INTEGER ;
    BEGIN
    SELECT COUNT(*) INTO cnt FROM user_TABLES
    WHERE TABLE_NAME='ORDERED_INV_T';
    IF cnt=0 THEN
    l_sql:= 'CREATE TABLE ORDERED_INV_T
    PARTITION BY RANGE (ORDINV_TIME)
    ( PARTITION TP_ORDINV_MAX VALUES LESS THAN (MAXVALUE)
    TABLESPACE TEST_TPT_DATA
    ENABLE ROW MOVEMENT
    AS SELECT * FROM ORDERED_INV WHERE 1=0 ';
    EXECUTE IMMEDIATE l_sql;
    -- Add section to set default values for the intermediate table OL_ORDERED_INV_T
    FOR crec_cols IN (
    SELECT u.column_name ,u.nullable, u.data_default,u.table_name
    FROM USER_TAB_COLUMNS u WHERE
    u.table_name ='ORDERED_INV' AND
    u.data_default IS NOT NULL )
    LOOP
    l_sql:= 'ALTER TABLE ORDERED_INV_T MODIFY '||crec_cols.column_name||' DEFAULT '||crec_cols.data_default;
    -- dbms_output.put_line('chk data default => ' || l_sql) ;
    EXECUTE IMMEDIATE l_sql;
    END LOOP;
    END IF;
    -- Split partition to create more partitions
    select TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') into l_sysdate from dual;
    DBMS_OUTPUT.PUT_LINE ('Finding oldest value at ' || l_sysdate) ;
    EXECUTE IMMEDIATE 'SELECT NVL(TRUNC(MIN(OL_ORDINV_TIME),''MONTH''),TRUNC(SYSDATE,''MONTH''))
    FROM ORDERED_INV' INTO l_dt_start;
    select TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') into l_sysdate from dual;
    DBMS_OUTPUT.PUT_LINE ('Started creating partitions at ' || l_sysdate) ;
    LOOP
    EXIT WHEN l_dt_start > ADD_MONTHS(TRUNC(SYSDATE,'MONTH'),1);
    l_ptn:='tp_ordinv_'|| TO_CHAR(l_dt_start,'YYYYMM');
    l_sql:= 'ALTER TABLE ORDERED_INV_T
    split partition TP_ORDINV_MAX at (TO_DATE('''|| TO_CHAR(ADD_MONTHS(l_dt_start,12),'YYYYMM') ||''',''YYYYMM''))
    into ( partition '||l_ptn||' , partition TP_ORDINV_MAX)';
    execute immediate l_sql;
    l_dt_start:=add_months(l_dt_start,12);
    END LOOP;
    END;
    -- Also, add indexes to this table
    alter table ORDERED_INV_T add constraint ordinvt_pk primary key (ordinv_id) ;
    create unique index ordinvt_uix on ordered_inv_t(
    SCP_ID ASC,
    INV_ID ASC,
    ANATLOC_ID ASC,
    SOI_ID ASC,
    CANCEL_TS ASC );
    -- Next, use exchange partition for actual swipe
    -- Between ordered_inv_t and ordered_inv_bkp
    -- Analyze both tables : ordered_inv_t and ordered_inv_bkp
    BEGIN
    DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'HENRY220', TABNAME => 'ORDERED_INV_T');
    DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'HENRY220', TABNAME =>'ORDERED_INV_BKP');
    END;
    SET TIMING ON;
    ALTER TABLE ordered_inv_t
    EXCHANGE PARTITION TP_ORDINV_MAX
    WITH TABLE ordered_inv_bkp
    WITHOUT VALIDATION
    UPDATE GLOBAL INDEXES;
    -- Check query :
    select partition_name, num_rows, high_value from user_tab_partitions where table_name = 'ORDERED_INV_T' ;
    These are the results:
    TP_ORDINV_199801 0 TO_DATE(' 1999-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_199901 0 TO_DATE(' 2000-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200001 0 TO_DATE(' 2001-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200101 0 TO_DATE(' 2002-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200201 0 TO_DATE(' 2003-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200301 0 TO_DATE(' 2004-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200401 0 TO_DATE(' 2005-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200501 0 TO_DATE(' 2006-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200601 0 TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200701 0 TO_DATE(' 2008-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200801 0 TO_DATE(' 2009-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200901 0 TO_DATE(' 2010-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_201001 0 TO_DATE(' 2011-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_201101 0 TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_201201 0 TO_DATE(' 2013-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_MAX 24976 MAXVALUE
    Pay attention to the last record

    >
    used the Exchange Partition feature to swap segments between 2 tables- one Partitioned, and one Non-Partitioned. The exchange went well. However, all the data in the partitioned table has gone to the partition which stores the maxbound values.
    >
    That isn't possible. The data in the partition before the exchange could only have gone to the non-partitioned table.
    Please edit you post and add \ tags on the lines before and after your code to preserve formatting. See the FAQ for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to use Exchange partition

    Hi All,
    I have a requirement like .. i have to insert the data from partition table to unpartition table like temp table. by googling i came to know about Exchange partition. by using Exchange partition we can dump temp table to partition table but i don't know how to copy the data from partition table to temp table. following script am using.
    ALTER TABLE abc_partition
    EXCHANGE PARTITION P_2011_1115 WITH TABLE abc_tmp
    INCLUDING INDEXES
    WITHOUT VALIDATION;
    And again i have created a partition table and i ran below query
    ALTER TABLE abc_tmp
    EXCHANGE PARTITION P_2011_1115 WITH TABLE abc_partition
    INCLUDING INDEXES
    WITHOUT VALIDATION;
    but i was getting an error like partition ALTER TABLE EXCHANGE requires a non-partitioned, non-clustered table
    Thanks
    Sree
    Edited by: 874823 on Apr 30, 2012 2:01 AM

    In that case, you need to follow these basic steps.
    1. Use a CTAS (Create Table as Select) to create the staging table. This table's structure needs to match that of the partition table - be that a hash or index organised structure. The columns need to be in the same order, and of the same data type. Not null constraints need to be applied to the applicable columns. If you have manually set storage clauses (e.g. PCTFREE for example) for the partition table, the same needs to be applied to the staging table.
    A CTAS would look something as follows:
    create table staging_table(
      col1 not null,
      col2 null,
      col3 null
    ) nologging as
    select
      some_col,
      some_other_column,
      third_column
    from some_other_data2. The next step is to add the required indexes to the staging table - as that table needs to match the structure of the partitioned table. So the staging table needs to have the same index structures as local partition indexes of the partition table.
    3. The actual partition exchange can now happen. The data is not actually exchanged. Ownership of the data changes. The data blocks (for data and indexes) owned by the staging table, is now owned by that partition in the partition table. Likewise the staging table now owns the data and indexes of the partition.
    4. The last step is cleaning up - dropping and purging the staging table (assuming that you no longer have a need for it).
    The above steps can be fully automated (for any partition table) by developing a generic PL/SQL interface library that performs these steps. Additional features such as parallel processing and tablespaces to use for the staging table and indexes can also considered for such a PL/SQL interface.

  • Re: exchange partition on weekly partition

    We have divided month in 4 week partitions Week 1 start from date 2 to 8, Week2 start from 9 to 15, Week3 start from 16 to 22 and Week4 start from 23 to 1st of coming month.
    Tables has huge data (some tables size in TB). Can exchange partition will work on it or I have to change it to daily partition (with huge data)?
    Yes - exchange partition will work on it. As I said above:
    EXCHANGE PARTITION just exchanges two 'like' partitions so doesn't care what time period the partitions represent (daily, weekly, monthly, etc).
    That allows you to EXCHANGE one 'weekly' partition with a temp table.
    But you said you are loading data daily:
    We are loading data in our dataware house on daily basis from temp to stage and fact tables through insert command
    So you don't have a weeks worth of data to exchange; you have a 'days' worth of data. That can only be EXCHANGED with a partition that is intended to hold a days worth of data.
    If you are manually adding partitions to your current table then just begin manually add DAILY partitions instead of adding weekly ones. Then you can do a simple daily EXCHANGE to load the data.
    Or you could REDEFINE your existing table to use daily partitions by just defining partitions that correspond to your existing weekly ones to hold your current data and then daily partitions for your new data.
    CREATE TABLE SCOTT.PARTITION_DAILY_TEST
      ID       NUMBER(10),
      MY_DATE  DATE
    PARTITION BY RANGE (MY_DATE)
    INTERVAL( NUMTODSINTERVAL(1,'DAY'))
      PARTITION P_201204_WEEK1 VALUES LESS THAN (TO_DATE(' 2012-04-08 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201204_WEEK2 VALUES LESS THAN (TO_DATE(' 2012-04-16 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201204_WEEK3 VALUES LESS THAN (TO_DATE(' 2012-04-23 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201204_WEEK4 VALUES LESS THAN (TO_DATE(' 2012-05-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201205_WEEK1 VALUES LESS THAN (TO_DATE(' 2012-05-08 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    That table definition above defines specific partitions for existing data but tells Oracle to CREATE and USE daily partitions for new data.
    Then you can use EXCHANGE PARTITION (via a work tablel) to move data from your current table partitions to the new table partitions.

    If you are manually adding partitions to your current table then just begin manually add DAILY partitions instead of adding weekly ones. Then you can do a simple daily EXCHANGE to load the data.
    Or you could REDEFINE your existing table to use daily partitions by just defining partitions that correspond to your existing weekly ones to hold your current data and then daily partitions for your new data.
    rp0428,
    Just for confirmation can we add daily partition instead of weekly in our existing table for future data and current data will remain in weekly partition.

  • Exchange Partition Problem

    Hi,
    I am trying to create a partition table for a non parttition table.
    create table dept_test partition by list(deptno)
    (partition p10 values(10),
    partition p20 values(20),
    partition p30 values(30),
    partition p40 values(40))
    as select * from dept where 1=0;
    create table dept1
    as
    select * from dept;
    alter table DEPT_TEST
    exchange partition p10
    with table dept1
    WITHOUT VALIDATION;
    BEGIN
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P10',33);
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P20',33);
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P30',33);
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P40',33);
    END;
    select * from dba_tab_partitions where table_name='DEPT_TEST';
    SELECT * FROM DEPT_TEST WHERE DEPTNO=10;
    SELECT * FROM DEPT_TEST WHERE DEPTNO=20;
    In the dba_tab_partitions,row count for p10 is showing as 4. when i ran the query for the value 10 ,i got 4 row but for 20 no rows.
    Can you please tell me what is the problem?
    Thanks.

    Partition exchange moved all the data to partition p10. Partitions p20, p30 and p40 are empty. Evaluating condition WHERE DEPTNO = 10 optimizer relys on the partition definition VALUES(10). It's enough to do partition pruning only to satisfy the condition. The same partition pruning takes place for the condition DEPTNO = 20, but partition p20 is empty and the query returns no rows.
    SQL> set autotrace on explain
    SQL> SELECT * FROM DEPT_TEST WHERE DEPTNO=10;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    Execution Plan
    Plan hash value: 2891473902
    | Id  | Operation             | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT      |           |     1 |    20 |     3   (0)| 00:00:01 |       |       |
    |   1 |  PARTITION LIST SINGLE|           |     1 |    20 |     3   (0)| 00:00:01 |     1 | 1 |
    |   2 |   TABLE ACCESS FULL   | DEPT_TEST |     1 |    20 |     3   (0)| 00:00:01 |     1 | 1 |
    SQL> SELECT * FROM DEPT_TEST WHERE DEPTNO=20;
    no rows selected
    Execution Plan
    Plan hash value: 2891473902
    | Id  | Operation             | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT      |           |     1 |    30 |     2   (0)| 00:00:01 |       |       |
    |   1 |  PARTITION LIST SINGLE|           |     1 |    30 |     2   (0)| 00:00:01 |     2 | 2 |
    |   2 |   TABLE ACCESS FULL   | DEPT_TEST |     1 |    30 |     2   (0)| 00:00:01 |     2 | 2 |
    ---------------------------------------------------------------------------------------------------Regards,
    Dima
    Message was edited by:
    dimacit

  • ORA-02266: unique/primary keys - error while using Exchange Partition

    Hi All,
    While using EXCHANGE PARTITION statement as given below,
    ALTER TABLE SOURCE_TABLE EXCHANGE PARTITION PRT_EXCG_PRTN WITH TABLE TARGET_TABLE
    we are getting this error,
    ORA-02266: unique/primary keys in table referenced by enabled foreign keys
    However, there are no tables have foreign keys referring this TARGET_TABLE, we checked this by referring
    USER_CONSTRAINTS table, it has only primary key and NOT NULL constraints.
    SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME like 'TARGET_TABLE';
    We are using the following version,
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    PL/SQL Release 9.2.0.6.0 - Production
    CORE     9.2.0.6.0     Production
    TNS for IBM/AIX RISC System/6000: Version 9.2.0.6.0 - Production
    NLSRTL Version 9.2.0.6.0 - Production
    Is it due to any error in our end or it could be a bug in Oracle and should we go for any patch updation ?
    Please guide us to resolve this error as soon as possible, thank you.
    Regards,
    Deva

    *** Duplicate Post ***
    Please Ignore.

  • Exchange Partition Usage

    Hi,
    We store data from the main table by referring other lookup tables and store them temporarily in a Swap table and then
    in the end, we move data from here to the Main table using Exchange Partition.
    EXECUTE IMMEDIATE('ALTER TABLE TMP_SWAP EXCHANGE PARTITION PRT_TMP_SWAP WITH TABLE MAIN_TABLE');
    It is equivalent to Truncating data in the main table and insert data into it by reading from the swap table.
    Please tell me, how internally oracle handles "EXCHANGE PARTITION" implementation and how we get better performance
    instead of using TRUNCATE and INSERT, thank you.
    Regards,
    Deva

    Hi,
    It simply detaches extents/data blocks from the source table and attaches it to the destination table.
    This is the reason performance is better than INSERT statement.
    Regards
    Message was edited by:
    Citrus
    corrected a typo

  • High wait on Library Cache Lock while doing ALTER TABLE EXCHANGE PARTITION

    We are observing a very high wait time on "Library cache lock" while performing Exchange partition.
    Here we go
    ALTER TABLE PSALESREG EXCHANGE PARTITION P123
    WITH TABLE PBKPSALESREF WITHOUT VALIDATION
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.11 *6684.73* 2 9 2 0
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.11 6684.73 2 9 2 0
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    library cache lock 2274 3.12 *6681.32*
    Is it a bug? is anyone there who experienced the same issue?
    Rgds

    Maurice Muller wrote:
    Hi,
    As far as I remember a exchange partition can only be done when no other query is accessing the table.
    So you should check if any other queries are executed against the table PSALESREG while you do the exchange partition. Maurice,
    queries won't block the exchange operation but continue to read from the "original", exchanged segment; this "cross-DDL" read consistency is a feature that has been introduced a long time ago.
    But any kind of (long-running) DML should effectively prevent the exchange operation. Still I would assume that this shouldn't show up as "library cache lock", but you would get an "ORA-00054: resource busy" error.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Exchange Partition on large Partition tables in dataware house

    Hi all,
    oracle 10.2.0.4(64 bit) and OS 5.3 (64 bit).
    We have large tables in our DWH size in TB and data is for 13 Months.
    Now our management want to split these tables in two.
    current tables contain data for 3 months and current month and history tables contain data for history data of 9 months.
    We have no space on mount point for export/import.
    Can exchange partition will work on it? if yes, please need steps/demo/examples.
    Some partitions has size more then 300gb.

    user610482 wrote:
    Hi Oracle gurus,
    I need a dynamic script to add MAXVALUE partition to all 100 tables in schema,each tables are having different Partition Key with different tablespace
    AVB1_NOTIFICATIONSL have 2 columns in partition key
    For eg : alter table AVB1_NOTIFICATIONSL add partition DMAX VALUES LESS THAN (MAXVALUE,MAXVALUE) TABLESPACE LARGE_D
    is SQL above valid?
    does it do what you require?

  • Ora 14098 Index mismatch for tables  in Alter Exchange Partition

    Hi All,
    I want to exchange data from retek schema to CONV schema. Both the table have same partition, but there is no data in CONV table.
    So I'm populating the data from retek of one particular partition into one staging table and then I'm doing exchanging partition with staging table to CONV table.
    I have created the same index and constraints for staging as there are in CONV table.
    But When I'm doing exchange partition I'm getting error Index mismatch.
    v_parition_name:='mar 2012'
    v_stmt := 'create table staging_tab_st_hist as ( select * from retek.abc_st_hist partition(' ||
    v_parition_name || ') )';
    execute immediate v_stmt;
    v_stmt := ' alter table conv.abc_st_hist exchange partition ' ||
    v_parition_name ||
    ' with table staging_tab_st_hist
    including indexes without validation';
    execute immediate v_stmt;

    Welcome to the forum!
    Whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    Hi All,
    I want to exchange data from retek schema to CONV schema. Both the table have same partition, but there is no data in CONV table.
    So I'm populating the data from retek of one particular partition into one staging table and then I'm doing exchanging partition with staging table to CONV table.
    I have created the same index and constraints for staging as there are in CONV table.
    But When I'm doing exchange partition I'm getting error Index mismatch.
    v_parition_name:='mar 2012'
    v_stmt := 'create table staging_tab_st_hist as ( select * from retek.abc_st_hist partition(' ||
    v_parition_name || ') )';
    execute immediate v_stmt;
    v_stmt := ' alter table conv.abc_st_hist exchange partition ' ||
    v_parition_name ||
    ' with table staging_tab_st_hist
    including indexes without validation';
    execute immediate v_stmt;
    >
    I don't see any index creation on the staging table. You said this
    >
    I have created the same index and constraints for staging as there are in CONV table.
    >
    But you didn't create the indexes. When you do the CTAS (create table as select) it only creates the table with the same structure; it doesn't create ANY indexes.
    Add the code to create the necessary indexes after you populate the staging table.

  • Problem exchanging partitions using range partitioning

    I have a range-partitioned table. Here's a cut down version....
    CREATE TABLE MY_TABLE
       (     VALUE           NUMBER,
         PARTITION_KEY      NUMBER
      PARTITION BY RANGE ("PARTITION_KEY")
    (PARTITION "P1"  VALUES LESS THAN (2),
      PARTITION "P2"  VALUES LESS THAN (3),
      PARTITION "P3"  VALUES LESS THAN (4),
      PARTITION "P4"  VALUES LESS THAN (5),
      PARTITION "P5"  VALUES LESS THAN (6),
      PARTITION "P6"  VALUES LESS THAN (7),
      PARTITION "P7"  VALUES LESS THAN (8));For the process I'm working on, I want to be able to:
    - create a table as a copy of one of the partitions
    - do some processing on that table
    - exchange the updated table back into the partitioned table
    I can achieve this as follows....
    CREATE TABLE MY_TABLE_COPY_P7 AS (SELECT * FROM MY_TABLE WHERE PARTITION_KEY = 7);
    ... do processing ...
    ALTER TABLE MY_TABLE DROP PARTITION P7;
    ALTER TABLE MY_TABLE ADD PARTITION P7 VALUES LESS THAN (8);
    ALTER TABLE MY_TABLE EXCHANGE PARTITION P7 WITH TABLE MY_TABLE_COPY INCLUDING INDEXES;However, this only works if the partition I'm adding back in is the highest partition.
    If I try do take out one of the middle partitions, then add it back I get an error:
    SQL] ALTER TABLE MY_TABLE ADD PARTITION P5 VALUES LESS THAN (6);
    ALTER TABLE MY_TABLE ADD PARTITION P5 VALUES LESS THAN (6)
    ERROR at line 1:
    ORA-14074: partition bound must collate higher than that of the last partitionAny ideas on how I can exchange one of the middle partitions with having to first drop the higher ones?
    Btw, I have to use range partitioning as we're using spatial, which only supports range partitioning.
    Cheers,

    Actually, you can do the exchange partition thing with 8i and over. After creating my_table from your script, I did:
    SQL> INSERT INTO my_table VALUES (1,7.5);
    1 row created.
    SQL> INSERT INTO my_table VALUES (2, 7.2);
    1 row created.
    SQL> INSERT INTO my_table VALUES (3,7.7);
    1 row created.
    SQL> CREATE TABLE my_tab_tmp AS
      2  SELECT * FROM my_table
      3  WHERE 1=2;
    Table created.
    SQL> ALTER TABLE my_table EXCHANGE PARTITION P7 WITH TABLE my_tab_tmp;
    Table altered.
    SQL> SELECT * FROM my_tab_tmp;
         VALUE PARTITION_KEY
             1           7.5
             2           7.2
             3           7.7
    SQL> SELECT * FROM my_table;
    no rows selected
    SQL> UPDATE my_tab_tmp
      2  set value = value * 20;
    3 rows updated.
    SQL> COMMIT;
    Commit complete.
    SQL> ALTER TABLE my_table EXCHANGE PARTITION P7 WITH TABLE my_tab_tmp;
    Table altered.
    SQL> SELECT * FROM my_tab_tmp;
    no rows selected
    SQL> SELECT * FROM my_table;
         VALUE PARTITION_KEY
            20           7.5
            40           7.2
            60           7.7You will, of course, need to re-build any global indexes on my_table.
    When you first create my_tab_tmp, you should also create indexes to match any local indexes on the partitions, then do the exchange partition using the INCLUDING INDEXES clause. You could also skip creating the indexes and then re-create them after exchanging the updated table with the partition.
    Note that none of this will work if you are changing values of partition_key so thatthey fall out of the range for the partition.
    HTH
    John

  • Oracle TTS or Exchange Partitions -- Opinions?

    Hi All,
    So i have two tables with the same structure, with the same partition key and they are both partitioned hourly, but they reside in two different databases (one of them is actually a datawarehouse).
    We have a requirement to move data from one database to another and were researching on the fastest method to accomplish this. I was thinking of two possibilities:-
    1) Exchange Partitions.
    2) Transportable Tablespaces.
    And one of my main requirement is that both these tables must be available always. I cant take any tablespaces offline.
    Can you please advise on what is the best method to accomplish this? And why?
    Thanks

    These are neither SQL or PL/SQL related question - I suggest that you ask this in the [url http://forums.oracle.com/forums/forum.jspa?forumID=61]Database - General forum instead. It deals with general database and database administration questions.

  • TTS or Exchange Partitions -- Opinion needed

    Hi All,
    So i have two tables with the same structure, with the same partition key and they are both partitioned hourly, but they reside in two different databases (one of them is actually a datawarehouse).
    We have a requirement to move data from one database to another and were researching on the fastest method to accomplish this. I was thinking of two possibilities:-
    1) Exchange Partitions.
    2) Transportable Tablespaces.
    Can you please advise on what is the best method to accomplish this? And why?
    Thanks

    These are neither SQL or PL/SQL related question - I suggest that you ask this in the [url http://forums.oracle.com/forums/forum.jspa?forumID=61]Database - General forum instead. It deals with general database and database administration questions.

  • How to use "exchange partition" as performance trick?

    Hi,
    having a partitioned table in Oracle 10g release 2, I am searching for a performant to reload partitions completely.
    I heard about the possibility to load the new data (== complete partition which shall replace existing partition data) completely into a temporary partition and then just to exchange the partitions (throw away the old one and replace it with the new one). This (I was told - and it sounds good to me) is a most performant way of updating the complete data of one partition.
    Yet it is unclear to me how to load the new data (which automatically would be inserted in the partition which it shall replace).
    So is this possibility existing at all?
    Any link to an example?
    Best regards from sunny Black Forrest,
    Mattin

    Hi Martin,
    the procedere would be something like
    create table tmp_berichtswerte as select * from berichtswerte where 1=0;
    Populate the temp table
    alter table berichtswerte exchange partition brw_p200109 with table tmp_berichtswerte;
    Rebuild the indexes on that partition (and the global indexes on the table)P.S. Sunny? Right now? your are kidding!

Maybe you are looking for