Introduction To Oracle Sharding
Introduction To Oracle Sharding
2 New Feature
Author:
NirmalaDevi Selvakumar, Principal Software Engineer
High Availability, Oracle
This Article is intended to detail the features of Sharding which is available in Oracle 12.2. Oracle
Sharding is a database scaling technology based on horizontal partitioning of data across multiple
databases.
Table of Contents
What is Sharding?
Why Sharding?
Implementation: Simple three steps to configure Sharding
Prerequisites
Disable iptable on Catalog and all Shard Databases
Check for following directories
Create Base directory on all Shard DB
Prepare Catalog DB
Create Catalog User and Grant necessary Privilege
Configure the REMOTE scheduler
Set the Scheduler Port and Password
Start scheduler On Catalog DB and all Shard DB
DEPLOY and Create the SHARD TABLE
DEPLOY
Create Shard Tables
Post Verification
Troubleshooting
What is Sharding?
Each database in a pool (Shards) runs in dedicated storage and different server.
All Shards together makeup the single logical group called Sharded Databases called
SDB. Each database in a pool (Shards) contains a table with same column but different
subsets of rows called CHUNKS. Sharding based on Oracle Partitioning. Partitions
decompose a large table in to small partitions. Sharding keeps each partition into
different databases called Shards. Number of partitions decided number of Shards.
Sharding uses Global Data Service (GDS) framework for automatic deployment
and management. GDS uses GDSCTL utility. The Advantages of GDS is, it provides
connection load balancing and role based routing in SDB (Shard Catalog). GSM Manager
is a central component of GDS which provides direct routing of client connections to
Shards. GSM is called as Shard Director. Shard catalog (SDB) stores the information
about Shard table. Additionally it provides centralized schema maintenance and cross
shard queries.
Overview
The diagram outlines the difference between non Sharding with Sharding environment.
Database PRODS with table CUSTOMER having six partitions on the non Shard environment. Unlikely in
Sharding environment three different database with dedicated hardware sharing partitions of single
table CUSTOMER.
On Sharding environment shown in the diagram has the table CUSTOMER with 2 partitions
referred as CHUNKS. Table load is shard across three different Shards. For application it is a single logical
database (SDB). Application/Clients connect to GSM and it internally routes the connection to the
respective Shard. Now Shard directly sends the requested data to clients directly.
TYPE
Example
User has control over database means user specifies the mapping of data to individual Shards. It
is useful in cases where application decides certain data need to be kept in a particular Shard and user
have control on moving data between Shards. The advantage of this method is that in case of
maintenance planned and unplanned outage of a Shard, the user knows exactly what data is not
available. But the disadvantage of this model is user has to keep track of data to maintain the balanced
distribution and workload across shards. User defined Sharding uses partitioning by Range or list. User
defined Partitioning not available in 12.2.0.1 Beta.
Example:
Composite Sharding
Composite Sharding is a combination of system managed and user defined Sharding. Data first
partitioned by list or range and then further partitioned in to consistent hash. Consistent partition
maintains balanced distribution of data across set of Shards.
Why Sharding?
Prerequisites:
Install GDS - refer KM Article Installation and GDS Configuration for Data guard and Golden
Gate (Doc ID 2144138.1)
Install Oracle 12.2 Software in all Shard(s) including Shard catalog server
Create Shard catalog Database (NON CDB)
IMPLEMENTATIN:
Once the environment is ready invoke GDSCTL to create Shard catalog (SDB)
Before create Shard catalog do the following on Shard catalog server and all Shard servers.
Disable FIREWALL
Create necessary directories
Create Shard Catalog Schema on SDB
Configure Remote Scheduler
Start scheduler on SDB and all Shard servers
mkdir -p $ORACLE_BASE/oradata
mkdir -p $ORACLE_BASE/fast_recovery_area
ls -lst $ORACLE_BASE/oradata
ls -lst $ORACLE_BASE/fast_recovery_area
Connect to Catalog database use SYS user, create Shard catalog user and assign necessary priviledge.
$ sqlplus / as sysdba
alter system set db_create_file_dest='/u01/app/oracle/oradata' scope=both;
alter system set open_links=16 scope=spfile;
alter system set open_links_per_instance=16 scope=spfile;
alter user gsmcatuser identified by gsmcatuser account unlock;
create user mygds identified by mygds;
grant connect, create session, gsmadmin_role to mygds;
grant inherit privileges on user SYS to GSMADMIN_INTERNAL;
alter system set events 'immediate trace name GWM_TRACE level 7';
alter system set event='10798 trace name context forever, level 7'
scope=spfile;
startup force
On SDB database connect to SYS user and execute following command to configure remote scheduler.
set echo on
set termout on
spool config_remote_scheduler.lst
@?/rdbms/admin/prvtrsch.plb
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 80
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 100
SET SERVEROUTPUT ON;
WHENEVER SQLERROR EXIT;
Begin
dbms_isched.agent_install_pre_steps;
end;
/
alter session set "_ORACLE_SCRIPT" = false;
begin
dbms_isched.agent_install_post_steps;
end;
/
On the same session set the AGNET port and password. NOTE: Same port will be used in all the
Shard server agents to communicate with SDB server.
exec DBMS_XDB.sethttpport(8080);
commit;
exec DBMS_SCHEDULER.SET_AGENT_REGISTRATION_PASS('welcome');
alter system register;
Register SDB database on all the Shards. On all the Shard server connect to 12.2 ORACLE_HOME,
start the agent and register SDB database.
schagent -start
schagent -status
echo welcome | schagent -registerdatabase blr 8080
GSM acts as a Sharddirector for Sharding. It receives the client connection and route to
respective Shard based on Shard_key. Once connection is established then Shard database sends the
requested information back to clients directly.
Invoke GDSCTL and login using shard catalog user. First cerate SahrdCatalog(SDB) on the SDB
server. In my example blr is the SDB server hostname. Later on add GSM with any unused port. If any
issue on add GSM and start GSM refer to GSM log which will be present in GDS_HOME.
$.oraenv
GSM
$gdsctl
GDSCTL>add gsm -gsm shardDGdirector -listener 12106 -pwd gsmcatuser -catalog blr:1526:scat -
region region1 -trace_level 16
Create Shard(s)
GDSCTL>config shard
Name Shard Group Status State Region Availability
---- ----------- ------ ----- ------ ------------
sh103 primary_shardgroup U none region1 -
sh104 standby_shardgroup U none region2 -
GDSCTL>deploy
GDSCTL>config shard
Name Shard Group Status State Region Availability
---- ----------- ------ ----- ------ ------------
sh103 primary_shardgroup Ok Deployed region1 ONLINE
sh104 standby_shardgroup Ok Deployed region2 READ_ONLY
GDSCTL>config chunks
Chunks
------------------
Database From To
--------- ----- --
sh103 1 12
sh104 1 12
Create role based services for the applications to connect read_write operations on primary and
read_only operation on Standby. Additionally services with load balancing created for Sharding with
DUPLCATED tables.
GDSCTL>databases
Database: "sh103" Registered: Y State: Ok ONS: N. Role: PRIMARY Instances: 1 Region:
region1
Service: "prim_srv" Globally started: Y Started: Y
Scan: N Enabled: Y Preferred: Y
Service: "stdby_srv" Globally started: Y Started: N
Scan: N Enabled: Y Preferred: Y
Registered instances:
scat%1
Database: "sh104" Registered: N State: Errors ONS: N. Role: N/A Instances: 0 Region:
region2
Service: "prim_srv" Globally started: Y Started: N
Scan: N Enabled: Y Preferred: Y
Service: "stdby_srv" Globally started: Y Started: N
Scan: N Enabled: Y Preferred: Y
$ sqlplus / as sysdba
alter session enable shard ddl;
create user app_schema identified by app_schema;
grant all privileges to app_schema;
grant gsmadmin_role to app_schema;
grant select_catalog_role to app_schema;
grant connect, resource to app_schema;
grant dba to app_schema;
grant execute on dbms_crypto to app_schema;
CREATE TABLESPACE SET TSP_SET_2 using template (datafile size 100m extent management
local segment space management auto );
CREATE TABLESPACE products_tsp_1 datafile size 100m extent management local uniform
size 1m;
Connect to application schema and create three dependent tables namely Customer, Orders
and LineItems
SQL>connect app_schema/app_schema;
Run following query from SDB to verify the Tablespace name and size.
SQL>
set echo off
select a.name Shard, count( b.chunk_number) Number_of_Chunks from
gsmadmin_internal.database a, gsmadmin_internal.chunk_location b where
a.database_num=b.database_num group by a.name;
SQL>connect app_schema/app_schema_password
col TNAME for a20
select table_name from user_tables;
On Primary Shard DGMGRL show configuration will give you the details of
primary and replicated standby shards detail with FSFO enabled.
dgmgrl /
dgmgrl>connect sys
DGMGRL>show configuration;
Configuration - sh103
Configuration Status;
Success (status updated 51 seconds ago)
TROBUBLESHOOTING
Any issue in GSM check the GSM log which will be present in GSM_HOME,
$ORACLE_BASE/diag/gsm/<host_name>/GSM_NAME>/trace.
Example,
GDSCTL>config
GDSCTL>status gsm -gsm <gsm_name>
GDSCTL>status gsm gsmDGDirector
Alias SHARDDGDIRECTOR
Version 12.2.0.0.0
Start Date 07-MAY-2016 16:25:35
Trace Level support
Listener Log File /u02/app/oracle/diag/gsm/blr/sharddgdirector/alert/log.xml
Listener Trace File
/u02/app/oracle/diag/gsm/blr/sharddgdirector/trace/ora_23825_140392884396416.trc
Endpoint summary (ADDRESS=(HOST=blr)(PORT=12106)(PROTOCOL=tcp))
GSMOCI Version 2.1.1
Mastership Y
Connected to GDS catalog Y
Process Id 23827
Number of reconnections 0
Pending tasks. Total 0
Tasks in process. Total 0
Regional Mastership TRUE
Total messages published 0
Time Zone +05:30
Orphaned Buddy Regions:
None
GDS region region1
CONCLUSION