Querying and maintaining data in scenarios that involve database sharding and table partitioning can be complex. Data Management Service (DMS) simplifies this process with its logical database and logical table features. This capability allows you to group one or more physical databases into a single logical database, providing a unified view for querying and managing your distributed data.
Background
In an architecture that uses database sharding and table partitioning, business data is distributed across many tables in multiple physical databases based on a routing algorithm. This architecture often presents the following challenges:
Querying and analyzing data is difficult because you often need to scan every table to find the required information.
Adding or removing a field requires significant effort because the change must be applied to every table partition.
The logical database feature in DMS addresses these challenges. It enables you to create a logical table from physical tables that share the same structure and a common name prefix. You can then manage this logical table as if it were a single table.
Prerequisites
The physical databases must be of a supported type:
Relational databases:
MySQL: ApsaraDB RDS for MySQL, PolarDB for MySQL, ApsaraDB MyBase for MySQL, AnalyticDB for MySQL V3.0, and MySQL databases from other sources
SQL Server: ApsaraDB RDS for SQL Server, ApsaraDB MyBase for SQL Server, and SQL Server databases from other sources
PostgreSQL: ApsaraDB RDS for PostgreSQL, PolarDB for PostgreSQL, ApsaraDB MyBase for PostgreSQL, AnalyticDB for PostgreSQL, and PostgreSQL databases from other sources
OceanBase: ApsaraDB for OceanBase in MySQL mode, ApsaraDB for OceanBase in Oracle mode, and self-managed OceanBase databases
PolarDB for PostgreSQL (Compatible with Oracle)
Oracle
Db2
Data warehouses: Data Lake Analytics (DLA), ApsaraDB for ClickHouse, and Hologres
The instances that host the physical databases must be managed in Security Collaboration mode. For more information, see View the control mode.
You must be an administrator, a DBA, or the data owner of the physical databases. For more information, see View system roles and View resource roles.
Configure a logical database
Log in to DMS 5.0.
Move the pointer over the
icon in the upper-left corner of the DMS console and choose . NoteIf you use the DMS console in normal mode, choose in the top navigation bar.
In the search box, enter the name of a physical database and click the
icon.In the Actions column for the target physical database, choose . This physical database becomes the first database shard in the logical database.
Optional: In the Create Logical Database Configuration dialog box, add more physical database shards.
The physical database shards that you add must meet the following requirements:
They must be of the same database type. For example, all must be MySQL databases.
They must belong to the same environment type, such as the development (dev) environment. For more information, see Instance environments.
A physical database can be configured in only one logical database. If a physical database is already part of Logical Database A, you must first remove it from A before you can add it to Logical Database B.
To add physical database shards:
Search for and select the target physical databases.
Click the
icon to add the selected physical databases to the list on the right.NoteThe order of the physical databases in the list on the right determines the sharding order within the logical database. This order must match the actual sharding sequence to ensure that logical table queries function correctly.
Set an alias for the logical database.
The logical database name is displayed in the following format: Logical Database Name [Alias].
Set the data owner.
If you are an administrator or a DBA, you can click Change Data Owners to assign one or more users as the data owner for all physical database shards. These users become the data owners of the logical database.
NoteIf you receive the message "Failed to provide recommendations because databases in the logical database belong to different owners.", it means the physical database shards have different data owners. You must assign a unified data owner for all shards. For instructions, see Manage permissions.
Click Save Configuration.
Next steps
After you configure a logical database, you must create logical tables before you can query data in them. For more information, see Logical tables.