Capability | PostgreSQL Version | Supported Version |
Custom multi-tenancy enablement capability | PostgreSQL 17 | v17.11_r1.26 or later |
SHOW tencentdb_version;.shared_preload_libraries parameter under console parameter settings, select tencentdb_serverless, save the changes, and restart the instance.tencentdb_multi_tenant_mode parameter to on.Parameter | Level | Default Value | Description |
tencentdb_multi_tenant_mode | postmaster | off | Master switch for multi-tenancy mode. Modify it in the console parameter settings, and restart the instance after modification. |
shared_preload_libraries | postmaster | - | Select tencentdb_serverless, modify it in the console parameter settings, and restart the instance after modification. |
tencentdb_multi_tenant_role_prefix | sighup | tencentdb_ | Multi-tenancy mode: name prefix for management roles. Only roles whose names start with this prefix are treated as management identities (can log in remotely, can hold the REPLICATION privilege, and can exercise tencentdb_superuser privileges), and are not affected by tenant database view isolation restrictions. |
tencentdb_serverless.throttle_replay_database | postmaster | postgres | Resource isolation: limits the quota replay worker processes to read only the databases specified in the restriction configuration, with postgres as the default database. |
min_cpu_cores/max_cpu_cores parameters. It is configured entirely on a per-database basis through the SQL interface of tencentdb_serverless.root (a member of tencentdb_superuser), the tenant role tenant_a and its database tenant_a_db, and the public read-only role proxy_ro.pg_database and pg_roles. The view isolation feature enables row-level security (RLS) policies on shared system tables so that each tenant can only see information related to their own database.Isolated System Table | Tenant-Visible Scope |
pg_database (pg_database view) | Current database only |
pg_authid (views such as pg_roles and pg_user) | Roles of the database owner and additional roles from parameter configuration |
pg_auth_members (pg_auth_members view) | Membership relationships between visible roles |
pg_db_role_setting (pg_db_role_setting view) | Parameter settings for the current database only |
pg_shdepend (pg_shdepend view) | Dependencies for the current database only |
pg_shdescription (pg_shdescription view) | Comments for the current database and visible roles only |
pg_shseclabel (security label view) | Security labels for the current database and visible roles only |
pg_subscription (pg_subscription view) | Subscriptions for the current database only |
pg_tablespace (pg_tablespace view) | Tablespaces used by the current database only |
postgres=# \\c tenant_a_db rootYou are now connected to database "tenant_a_db" as user "root".root=> CREATE EXTENSION tencentdb_serverless;CREATE EXTENSIONroot=> SELECT tencentdb_serverless.enable_system_view_isolation();NOTICE: policy "p_pg_database" for relation "pg_catalog.pg_database" does not exist, skippingNOTICE: policy "p_pg_authid" for relation "pg_catalog.pg_authid" does not exist, skippingNOTICE: policy "p_pg_auth_members" for relation "pg_catalog.pg_auth_members" does not exist, skippingNOTICE: policy "p_pg_db_role_setting" for relation "pg_catalog.pg_db_role_setting" does not exist, skippingNOTICE: policy "p_pg_shdepend" for relation "pg_catalog.pg_shdepend" does not exist, skippingNOTICE: policy "p_pg_shdescription" for relation "pg_catalog.pg_shdescription" does not exist, skippingNOTICE: policy "p_pg_seclabel" for relation "pg_catalog.pg_shseclabel" does not exist, skippingNOTICE: policy "p_pg_subscription" for relation "pg_catalog.pg_subscription" does not exist, skippingNOTICE: policy "p_pg_tablespace" for relation "pg_catalog.pg_tablespace" does not exist, skippingenable_system_view_isolation------------------------------(1 row)
DROP POLICY IF EXISTS statement inside the enable script and is a normal message.proxy_ro), a superuser or administrator must configure a database-level parameter, with multiple roles separated by commas:postgres=# ALTER DATABASE tenant_a_db SET tencentdb_multi_tenant_visible_roles = 'tenant_a,proxy_ro';ALTER DATABASE
tenant_a=> SELECT datname FROM pg_database ORDER BY 1;datname-------------tenant_a_db(1 row)tenant_a=> SELECT rolname FROM pg_roles WHERE rolname NOT LIKE 'pg\\_%' ORDER BY 1;rolname----------proxy_rotenant_a(2 rows)tenant_a=> SELECT spcname FROM pg_tablespace ORDER BY 1;spcname------------pg_default(1 row)
root=> SELECT tencentdb_serverless.disable_system_view_isolation();disable_system_view_isolation-------------------------------(1 row)tenant_a=> SELECT datname FROM pg_database ORDER BY 1;datname-------------postgrestemplate0template1tenant_a_dbtenant_b_dbtenant_c_db(6 rows)
tenant_a_db. The sample table big_table (8 million rows) is a business table in the tenant database and is created in the tenant database:postgres=# \\c tenant_a_db rootYou are now connected to database "tenant_a_db" as user "root".root=> CREATE TABLE big_table AS SELECT g FROM generate_series(1, 8000000) g;SELECT 8000000root=> ANALYZE big_table;ANALYZE
set_database_cpu_limit are as follows: database name, CPU lower limit (reserved, not enabled in the current version), and CPU upper limit. The following limits the tenant database to a maximum of 0.5 cores:root=> SELECT tencentdb_serverless.set_database_cpu_limit('tenant_a_db', 0.1, 0.5);set_database_cpu_limit------------------------(1 row)
root=> SELECT * FROM tencentdb_serverless.resource_limit_view;database_name | min_cpu_cores | max_cpu_cores | min_mem_kilobytes | max_mem_kilobytes---------------+---------------+---------------+-------------------+-------------------tenant_a_db | 0.1 | 0.5 | |(1 row)
min_mem_kilobytes and max_mem_kilobytes are reserved columns and are not used in the current version.root=> SELECT * FROM tencentdb_serverless.get_cpu_throttle_usage('tenant_a_db');cpu_limit | cpu_usage_rate | throttled_count | throttled_time_ms-----------+----------------+-----------------+-------------------0.5 | 0 | 0 | 0(1 row)
cpu_limit: The currently effective CPU upper limit (in cores).cpu_usage_rate: The average number of CPU cores used by the database within the last 5-second observation window.throttled_count: The total number of times throttling has been triggered for the database since the limit was first set.throttled_time_ms: The total number of milliseconds the database has spent waiting due to throttling since the limit was first set.root=> EXPLAIN (ANALYZE, COSTS OFF) SELECT count(*) FROM big_table;QUERY PLAN----------------------------------------------------------------------------------------------------Finalize Aggregate (actual time=409.405..410.836 rows=1 loops=1)-> Gather (actual time=409.301..410.824 rows=3 loops=1)Workers Planned: 2Workers Launched: 2-> Partial Aggregate (actual time=407.081..407.083 rows=1 loops=3)-> Parallel Seq Scan on big_table (actual time=0.033..247.186 rows=2666667 loops=3)Planning Time: 0.212 msExecution Time: 410.958 ms(8 rows)
root=> SELECT tencentdb_serverless.set_database_cpu_limit('tenant_a_db', 0.1, 0.1);set_database_cpu_limit------------------------(1 row)root=> EXPLAIN (ANALYZE, COSTS OFF) SELECT count(*) FROM big_table;QUERY PLAN------------------------------------------------------------------------------------------------------Finalize Aggregate (actual time=10422.597..10424.092 rows=1 loops=1)-> Gather (actual time=10422.498..10424.083 rows=3 loops=1)Workers Planned: 2Workers Launched: 2-> Partial Aggregate (actual time=10420.262..10420.264 rows=1 loops=3)-> Parallel Seq Scan on big_table (actual time=0.030..10276.123 rows=2666667 loops=3)Planning Time: 0.215 msExecution Time: 10424.213 ms(8 rows)
root=> SELECT * FROM tencentdb_serverless.get_cpu_throttle_usage('tenant_a_db');cpu_limit | cpu_usage_rate | throttled_count | throttled_time_ms-----------+---------------------+-----------------+-------------------0.1 | 0.09571135357027115 | 328 | 46545.3(1 row)
cpu_usage_rate is accounted for collectively across all sessions in the database, so the overall usage is kept near the cap.root=> SELECT tencentdb_serverless.reset_database_limit('tenant_a_db');reset_database_limit----------------------(1 row)root=> SELECT * FROM tencentdb_serverless.resource_limit_view;database_name | min_cpu_cores | max_cpu_cores | min_mem_kilobytes | max_mem_kilobytes---------------+---------------+---------------+-------------------+-------------------(0 rows)
tencentdb_serverless.reset_all_database_limit() to delete all limits in the instance at once.root=> SELECT tencentdb_serverless.set_database_cpu_limit('db_not_exists', 0.1, 0.5);ERROR: Database db_not_exists does not exist.CONTEXT: PL/pgSQL function tencentdb_serverless.set_database_cpu_limit(text,numeric,numeric) line 9 at RAISE
root=> SELECT tencentdb_serverless.set_database_cpu_limit('tenant_a_db', 0.5, 0.1);ERROR: max_cpu_cores should larger than min_cpu_cores.CONTEXT: PL/pgSQL function tencentdb_serverless.set_database_cpu_limit(text,numeric,numeric) line 28 at RAISE
ALTER DATABASE ... SET tencentdb_multi_tenant_visible_roles to add the role to the list. The change takes effect after the tenant reconnects.get_cpu_throttle_usage to check whether throttling has occurred.throttled_count and throttled_time_ms are cumulative values for the database since the limit was first set. Deleting the limit does not reset them to zero.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback