Schema Creation Examples
The following examples show the steps you would take to create a schema for a sharded database using the system-managed, user-defined, and composite sharding methods.
- Create a System-Managed Sharded Database Schema
Create the tablespace set, sharded tables, and duplicated tables for a sharded database that uses the system-managed sharding method. - Create a User-Defined Sharded Database Schema
Create the schema user, tablespace set, sharded tables, and duplicated tables for a sharded database that uses the user-defined sharding method. - Create a Composite Sharded Database Schema
Create the schema user, tablespace set, sharded tables, and duplicated tables for a sharded database that uses the composite sharding method. - Monitor DDL Execution and Verify Object Creation
You can monitor DDL execution using GDSCTL and SQL, to verify that the DDLs are propagated to all of the shards.
Parent topic: Sharded Database Schema Design
Create a System-Managed Sharded Database Schema
Create the tablespace set, sharded tables, and duplicated tables for a sharded database that uses the system-managed sharding method.
Next you should monitor the DDL execution and verify that the tablespace sets, tables, and chunks were correctly created on all of the shards.
Parent topic: Schema Creation Examples
Create a User-Defined Sharded Database Schema
Create the schema user, tablespace set, sharded tables, and duplicated tables for a sharded database that uses the user-defined sharding method.
Next you should monitor the DDL execution and verify that the tablespace sets, tables, and chunks were correctly created on all of the shards.
Parent topic: Schema Creation Examples
Create a Composite Sharded Database Schema
Create the schema user, tablespace set, sharded tables, and duplicated tables for a sharded database that uses the composite sharding method.
Next you should monitor the DDL execution and verify that the tablespace sets, tables, and chunks were correctly created on all of the shards.
Parent topic: Schema Creation Examples
Monitor DDL Execution and Verify Object Creation
You can monitor DDL execution using GDSCTL and SQL, to verify that the DDLs are propagated to all of the shards.
Monitor DDL Execution
You can check the status of the DDL propagation to the shards by using the GDSCTL
show ddl
and config shard
commands.
This check is mandatory when a DDL is executed using SQL*Plus on the shard catalog, because SQL*Plus does not return the execution status on all of the shards.
The show ddl
command output might be truncated. You can run
SELECT ddl_text FROM gsmadmin_internal.ddl_requests
on the
shard catalog to see the full text of the statements.
Run the following command from the shard director host.
GDSCTL> show ddl
id DDL Text Failed shards
-- -------- -------------
5 grant connect, resource to app_schema
6 grant dba to app_schema
7 grant execute on dbms_crypto to app_s...
8 CREATE TABLESPACE SET TSP_SET_1 usin...
9 CREATE TABLESPACE products_tsp datafi...
10 CREATE SHARDED TABLE Customers ( Cu...
11 CREATE SHARDED TABLE Orders ( Order...
12 CREATE SEQUENCE Orders_Seq;
13 CREATE SHARDED TABLE LineItems ( Or...
14 CREATE MATERIALIZED VIEW "APP_SCHEMA"...
Run the config shard
command on each shard
in your configuration, as shown here, and note the Last Failed DDL line in the
command output.
GDSCTL> config shard -shard sh1
Name: sh1
Shard Group: primary_shardgroup
Status: Ok
State: Deployed
Region: region1
Connection string: shard_host_1:1521/sh1_host:dedicated
SCAN address:
ONS remote port: 0
Disk Threshold, ms: 20
CPU Threshold, %: 75
Version: 18.0.0.0
Last Failed DDL:
DDL Error: ---
Failed DDL id:
Availability: ONLINE
Supported services
------------------------
Name Preferred Status
---- --------- ------
oltp_ro_srvc Yes Enabled
oltp_rw_srvc Yes Enabled
Verify Tablespace Set Creation
Verify that the tablespaces of the tablespace set you created for the sharded table family, and the tablespaces you created for the duplicated tables, are created on all of the shards.
The number of tablespaces in the tablespace set, shown below as
C001TSP_SET_1 through C006TSP_SET_1, is based on the number of chunks specified in
the GDSCTL create shardcatalog
command when the
sharded database configuration was deployed.
The duplicated Products tablespace is shown below as PRODUCTS_TSP.
Run SELECT TABLESPACE_NAME
on all of the shards in your
configuration, as shown here.
$ sqlplus / as sysdba
SQL> select TABLESPACE_NAME, BYTES/1024/1024 MB from sys.dba_data_files
order by tablespace_name;
TABLESPACE_NAME MB
----------------------- ----------
C001TSP_SET_1 100
C002TSP_SET_1 100
C003TSP_SET_1 100
C004TSP_SET_1 100
C005TSP_SET_1 100
C006TSP_SET_1 100
PRODUCTS_TSP 100
SYSAUX 650
SYSTEM 890
SYS_SHARD_TS 100
TSP_SET_1 100
TABLESPACE_NAME MB
------------------------ ----------
UNDOTBS1 105
USERS 5
13 rows selected.
Verify Chunk Creation and Distribution
Verify that the chunks and chunk tablespaces were created on all of the shards.
Run the GDSCTL config chunks
command as
shown here, and note the ranges of chunk IDs on each shard.
GDSCTL> config chunks
Chunks
------------------------
Database From To
-------- ---- --
sh1 1 6
sh2 1 6
sh3 7 12
sh4 7 12
Run the following SQL statements on each of the shards in your configuration, as shown here.
SQL> show parameter db_unique_name
NAME TYPE VALUE
---------------- ----------- ------------------------------
db_unique_name string sh1
SQL> select table_name, partition_name, tablespace_name
from dba_tab_partitions
where tablespace_name like 'C%TSP_SET_1'
order by tablespace_name;
TABLE_NAME PARTITION_NAME TABLESPACE_NAME
---------------- ---------------- --------------------
ORDERS CUSTOMERS_P1 C001TSP_SET_1
CUSTOMERS CUSTOMERS_P1 C001TSP_SET_1
LINEITEMS CUSTOMERS_P1 C001TSP_SET_1
CUSTOMERS CUSTOMERS_P2 C002TSP_SET_1
LINEITEMS CUSTOMERS_P2 C002TSP_SET_1
ORDERS CUSTOMERS_P2 C002TSP_SET_1
CUSTOMERS CUSTOMERS_P3 C003TSP_SET_1
ORDERS CUSTOMERS_P3 C003TSP_SET_1
LINEITEMS CUSTOMERS_P3 C003TSP_SET_1
ORDERS CUSTOMERS_P4 C004TSP_SET_1
CUSTOMERS CUSTOMERS_P4 C004TSP_SET_1
TABLE_NAME PARTITION_NAME TABLESPACE_NAME
---------------- ---------------- --------------------
LINEITEMS CUSTOMERS_P4 C004TSP_SET_1
CUSTOMERS CUSTOMERS_P5 C005TSP_SET_1
LINEITEMS CUSTOMERS_P5 C005TSP_SET_1
ORDERS CUSTOMERS_P5 C005TSP_SET_1
CUSTOMERS CUSTOMERS_P6 C006TSP_SET_1
LINEITEMS CUSTOMERS_P6 C006TSP_SET_1
ORDERS CUSTOMERS_P6 C006TSP_SET_1
18 rows selected.
Connect to the shard catalog database and verify that the chunks are uniformly distributed, as shown here.
$ sqlplus / as sysdba
SQL> SELECT a.name Shard, COUNT(b.chunk_number) Number_of_Chunks
FROM gsmadmin_internal.database a, gsmadmin_internal.chunk_loc b
WHERE a.database_num=b.database_num
GROUP BY a.name
ORDER BY a.name;
SHARD NUMBER_OF_CHUNKS
------------------------------ ----------------
sh1 6
sh2 6
sh3 6
sh4 6
Verify Table Creation
To verify that the sharded and duplicated tables were created, log in as the application schema user on the shard catalog database and each of the shards and query the tables on a database shard, as shown below with the example app_schema user.
$ sqlplus app_schema/app_schema_password
Connected.
SQL> select table_name from user_tables;
TABLE_NAME
-----------------------------------------------------------------------
CUSTOMERS
ORDERS
LINEITEMS
PRODUCTS
4 rows selected.
Parent topic: Schema Creation Examples