The document describes the steps to configure Oracle sharding in an Oracle 12c environment. It includes installing Oracle software on shardcat, shard1, and shard2 nodes, creating an SCAT database, installing the GSM software, configuring the shard catalog, registering the shard nodes, creating a shard group and adding shards, deploying the shards to create databases on shard1 and shard2, verifying the shard configuration, creating a global service, and creating a sample schema and shard table to verify distribution across shards.
3. Part 1 ORACLE │97
FISCAL_QUARTER_ID NUMBER ,
DAYS_IN_CAL_QUARTER NUMBER ,
DAYS_IN_FIS_QUARTER NUMBER ,
END_OF_CAL_QUARTER DATE ,
END_OF_FIS_QUARTER DATE ,
CALENDAR_QUARTER_NUMBER NUMBER(1,0) ,
FISCAL_QUARTER_NUMBER NUMBER(1,0) ,
CALENDAR_YEAR NUMBER(4,0) ,
CALENDAR_YEAR_ID NUMBER ,
FISCAL_YEAR NUMBER(4,0) ,
FISCAL_YEAR_ID NUMBER ,
DAYS_IN_CAL_YEAR NUMBER ,
DAYS_IN_FIS_YEAR NUMBER ,
END_OF_CAL_YEAR DATE ,
END_OF_FIS_YEAR DATE )
PARTITION BY RANGE( time_id )(
PARTITION partition_test1 VALUES less than (to_date('1998-12-31','YYYY-MM-DD')) ,
PARTITION partition_test2 VALUES less than (to_date('1999-12-31','YYYY-MM-DD')) ,
PARTITION partition_test3 VALUES less than (to_date('2000-12-31','YYYY-MM-DD')) ,
PARTITION partition_test4 VALUES less than (to_date('2001-12-31','YYYY-MM-DD')) ,
PARTITION partition_test5 VALUES less than (to_date('2003-12-31','YYYY-MM-DD')) );
??? ?? DDL (Partition_test2)
CREATE TABLE partition_test2 (TIME_ID DATE ,
DAY_NAME VARCHAR2(9),
DAY_NUMBER_IN_WEEK NUMBER(1,0) ,
DAY_NUMBER_IN_MONTH NUMBER(2,0) ,
CALENDAR_WEEK_NUMBER NUMBER(2,0) ,
FISCAL_WEEK_NUMBER NUMBER(2,0) ,
WEEK_ENDING_DAY DATE ,
WEEK_ENDING_DAY_ID NUMBER ,
CALENDAR_MONTH_NUMBER NUMBER(2,0) ,
FISCAL_MONTH_NUMBER NUMBER(2,0) ,
CALENDAR_MONTH_DESC VARCHAR2(8) ,
CALENDAR_MONTH_ID NUMBER ,
FISCAL_MONTH_DESC VARCHAR2(8) ,
FISCAL_MONTH_ID NUMBER,
DAYS_IN_CAL_MONTH NUMBER ,
DAYS_IN_FIS_MONTH NUMBER ,
END_OF_CAL_MONTH DATE ,
4. 98│2013 ???? White Paper
END_OF_FIS_MONTH DATE ,
CALENDAR_MONTH_NAME VARCHAR2(9) ,
FISCAL_MONTH_NAME VARCHAR2(9) ,
CALENDAR_QUARTER_DESC CHAR(7) ,
CALENDAR_QUARTER_ID NUMBER ,
FISCAL_QUARTER_DESC CHAR(7) ,
FISCAL_QUARTER_ID NUMBER ,
DAYS_IN_CAL_QUARTER NUMBER ,
DAYS_IN_FIS_QUARTER NUMBER ,
END_OF_CAL_QUARTER DATE ,
END_OF_FIS_QUARTER DATE ,
CALENDAR_QUARTER_NUMBER NUMBER(1,0) ,
FISCAL_QUARTER_NUMBER NUMBER(1,0) ,
CALENDAR_YEAR NUMBER(4,0) ,
CALENDAR_YEAR_ID NUMBER ,
FISCAL_YEAR NUMBER(4,0) ,
FISCAL_YEAR_ID NUMBER ,
DAYS_IN_CAL_YEAR NUMBER ,
DAYS_IN_FIS_YEAR NUMBER ,
END_OF_CAL_YEAR DATE ,
END_OF_FIS_YEAR DATE );
??? ??(? ??? ??)
INSERT /*+ append */
INTO partition_test
SELECT a.*
FROM sh.times a ,
(
SELECT LEVEL
FROM dual
CONNECT BY LEVEL <= 10000
) b;
?? ???(Partition_test2) ? ??? ??
SQL> delete partition_test2
2 where time_id<= (to_date('2000-12-31','YYYY-MM-DD'));
10960000 ?? ???????.
Execution Plan
5. Part 1 ORACLE │99
----------------------------------------------------------
Plan hash value: 3385385008
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | DELETE STATEMENT | | 5718 | 51462 | 141K (1)| 00:28:15 |
| 1 | DELETE | PARTITION_TEST2 | | | | |
|* 2 | TABLE ACCESS FULL| PARTITION_TEST2 | 5718 | 51462 | 141K (1)| 00:28:15 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("TIME_ID"<=TO_DATE(' 2000-12-31 00:00:00', 'syyyy-mm-ddhh24:mi:ss'))
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
5516 recursive calls
13289330 db block gets
521869 consistent gets
520081 physical reads
5831072716 redo size
565 bytes sent via SQL*Net to client
544 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
7 sorts (memory)
0 sorts (disk)
10960000 rows processed
??? ???(Partition_test)? ??? ??
SQL> alter table partition_test drop partition partition_test1;
???? ???????.
SQL> alter table partition_test drop partition partition_test2;
???? ???????.
SQL> alter table partition_test drop partition partition_test3;
11. Part 1 ORACLE │105
Array Processing ? ???? Insert ?? Procedure Source - P_BULK_INSERT_TEST1
CREATE OR REPLACE PROCEDURE P_BULK_INSERT_TEST1 IS
CURSOR sales_cur IS
SELECT PROD_ID,
CUST_ID,
TIME_ID,
CHANNEL_ID,
PROMO_ID,
QUANTITY_SOLD,
AMOUNT_SOLD
FROM SH.SALES;
TYPE SALES_TBL_TYPE IS TABLE OF sales_cur%ROWTYPE INDEX BY BINARY_INTEGER;
SALES_TBL SALES_TBL_TYPE;
BEGIN
OPEN sales_cur;
LOOP
FETCH sales_cur BULK COLLECT INTO sales_tbl LIMIT 1000; -- PGA ??? ?? ????
?? 1000 ??? ??
FOR i IN sales_tbl.FIRST..sales_tbl.LAST LOOP --?? ??? ????
sales_tbl(i).AMOUNT_SOLD := sales_tbl(i).AMOUNT_SOLD * 1.5;
END LOOP;
-- FETCH ? 1000 ?? SQL 1 ? ???? ??
FORALL i IN sales_tbl.FIRST..sales_tbl.LAST
INSERT INTO SALES2 VALUES (sales_tbl(i).PROD_ID,
sales_tbl(i).CUST_ID,
sales_tbl(i).TIME_ID,
sales_tbl(i).CHANNEL_ID,
sales_tbl(i).PROMO_ID,
sales_tbl(i).QUANTITY_SOLD,
sales_tbl(i).AMOUNT_SOLD
);
EXIT WHEN sales_cur%NOTFOUND;
END LOOP;
CLOSE sales_cur;
COMMIT;
EXCEPTION
12. 106│2013 ???? White Paper
WHEN OTHERS THEN
ROLLBACK;
RAISE_APPLICATION_ERROR(-20001,'RAISE_APPLICATION_ERROR : '
||SQLCODE||':'|| SUBSTR(SQLERRM,1,200));
END;
/
??? Loop ? ?? Insert ?? Procedure Source - P_BULK_INSERT_TEST2
CREATE OR REPLACE PROCEDURE P_BULK_INSERT_TEST2 IS
CURSOR sales_cur IS
SELECT PROD_ID,
CUST_ID,
TIME_ID,
CHANNEL_ID,
PROMO_ID,
QUANTITY_SOLD,
AMOUNT_SOLD
FROM SH.SALES;
TYPE SALES_TBL_TYPE IS TABLE OF sales_cur%ROWTYPE INDEX BY BINARY_INTEGER;
SALES_TBL SALES_TBL_TYPE;
BEGIN
OPEN sales_cur;
LOOP
FETCH sales_cur BULK COLLECT INTO sales_tbl LIMIT 1000; -- PGA ??? ?? ????
?? 1000 ??? ??
FOR i IN sales_tbl.FIRST..sales_tbl.LAST LOOP --?? ??? ????
sales_tbl(i).AMOUNT_SOLD := sales_tbl(i).AMOUNT_SOLD * 1.5;
END LOOP;
-- LOOP ? ???? ??; INSERT SQL 1000 ? ??
FOR i IN sales_tbl.FIRST..sales_tbl.LAST LOOP -- FORALL ??? ??
INSERT INTO SALES2 VALUES (sales_tbl(i).PROD_ID,
sales_tbl(i).CUST_ID,
sales_tbl(i).TIME_ID,
sales_tbl(i).CHANNEL_ID,
sales_tbl(i).PROMO_ID,
sales_tbl(i).QUANTITY_SOLD,
sales_tbl(i).AMOUNT_SOLD
);
13. Part 1 ORACLE │107
END LOOP;
EXIT WHEN sales_cur%NOTFOUND;
END LOOP;
CLOSE sales_cur;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE_APPLICATION_ERROR(-20001,'RAISE_APPLICATION_ERROR : '
||SQLCODE||':'|| SUBSTR(SQLERRM,1,200));
END;
/
P_BULK_INSERT_TEST2 Vs. P_BULK_INSERT_TEST2
SQL> exec P_BULK_INSERT_TEST1;
PL/SQL ??? ????? ???????.
? ?: 00:00:02.20
SQL>
SQL>
SQL> exec P_BULK_INSERT_TEST2;
PL/SQL ??? ????? ???????.
? ?: 00:00:35.08
?? : Array Processing ? ??? Update Procedure Source
CREATE OR REPLACE PROCEDURE P_BULK_INSERT_TEST2 IS
CURSOR sales_cur IS
SELECT PROD_ID,
CUST_ID,
TIME_ID,
CHANNEL_ID,
PROMO_ID,
QUANTITY_SOLD,
AMOUNT_SOLD
FROM SH.SALES;
14. 108│2013 ???? White Paper
TYPE SALES_TBL_TYPE IS TABLE OF sales_cur%ROWTYPE INDEX BY BINARY_INTEGER;
SALES_TBL SALES_TBL_TYPE;
BEGIN
OPEN sales_cur;
LOOP
FETCH sales_cur BULK COLLECT INTO sales_tbl LIMIT 1000; -- PGA ??? ?? ????
?? 1000 ??? ??
FOR i IN sales_tbl.FIRST..sales_tbl.LAST LOOP --?? ??? ????
sales_tbl(i).AMOUNT_SOLD := sales_tbl(i).AMOUNT_SOLD * 1.5;
END LOOP;
-- UPDATE / DELETE ? ??
FORALL i IN sales_tbl.FIRST..sales_tbl.LAST
UPDATE SALES SET AMOUNT_SOLD = sales_tbl(i).AMOUNT_SOLD
WHERE PROD_ID = sales_tbl(i).PROD_ID
AND CUST_ID = sales_tbl(i).CUST_ID
AND TIME_ID = sales_tbl(i).TIME_ID
AND CHANNEL_ID = sales_tbl(i).CHANNEL_ID
AND PROMO_ID = sales_tbl(i).PROMO_ID;
EXIT WHEN sales_cur%NOTFOUND;
END LOOP;
CLOSE sales_cur;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE_APPLICATION_ERROR(-20001,'RAISE_APPLICATION_ERROR : '
||SQLCODE||':'|| SUBSTR(SQLERRM,1,200));
END;
/