Oracle Globally Distributed Database (formerly Oracle Sharding) allows data to be distributed across a pool of databases.
Note: This feature is only supported in python-oracledb Thick mode.
To route a connection directly to a specific shard, use the shardingkey and (if using composite sharding) supershardingkey parameters in oracledb.connect() or ConnectionPool.acquire().
Key Details:
- Sharding Key: A required sequence of values used to route to a shard. Supported types:
string (VARCHAR2), number (NUMBER), bytes (RAW), and date (DATE). TIMESTAMP is not supported. - Super Sharding Key: Required when using composite sharding (partitioning by a range/list, then by a shard key).
- Connection Pooling: Use the
max_sessions_per_shard attribute in oracledb.create_pool() to balance connections across shards. - Coordinator Shard: To access data across multiple shards, connect to the coordinator shard catalog database without providing shard keys.
# Sharding by VARCHAR2
connection = oracledb.connect(user="hr", password=userpwd,
dsn="dbhost.example.com/orclpdb",
shardingkey=["SCOTT"])
# Sharding by NUMBER
connection = oracledb.connect(user="hr", password=userpwd,
dsn="dbhost.example.com/orclpdb",
shardingkey=[110])
# Sharding by DATE
import datetime
d = datetime.datetime(2014, 7, 3)
connection = oracledb.connect(user="hr", password=userpwd,
dsn="dbhost.example.com/orclpdb",
shardingkey=[d])
# Sharding by RAW
b = b'\x01\x04\x08'
connection = oracledb.connect(user="hr", password=userpwd,
dsn="dbhost.example.com/orclpdb",
shardingkey=[b])
# Multiple keys (Composite Sharding)
key_list = [70, "SCOTT", "gold", b'\x00\x01\x02']
connection = oracledb.connect(user="hr", password=userpwd,
dsn="dbhost.example.com/orclpdb",
shardingkey=key_list)
# Using a Super Sharding Key
connection = oracledb.connect(user="hr", password=userpwd,
dsn="dbhost.example.com/orclpdb",
supershardingkey=["goldclass"],
shardingkey=["SCOTT"])