产品动态
postgres=> show shared_preload_libraries;shared_preload_libraries-----------------------------------------------------------------------------------------------------------------------------------------------------pg_stat_statements,pg_stat_log,wal2json,decoderbufs,decoder_raw,pg_hint_plan,rds_server_handler,tencentdb_pwdcheck,pgaudit,tencentdb_sql_throttling(1 row)
postgres=> create extension tencentdb_sql_throttling; CREATE EXTENSION postgres=> select * from pg_extension where extname='tencentdb_sql_throttling';oid | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition-------+--------------------------+----------+--------------+----------------+------------+-----------+--------------16415 | tencentdb_sql_throttling | 16385 | 2200 | t | 1.0 | |(1 row)
postgres=> select datname,usename,client_addr,state,query_id,query from pg_stat_activity where usename='dbadmin' and client_addr='172.16.76.48' limit 10; datname | usename | client_addr | state | query_id | query ----------+---------+---------------+--------+--------------------+-------------------------------- postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 1 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 53 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 54 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 4 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 52 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 51 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 7 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 10 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 11 postgres | dbadmin | 172.16.76.48 | active | 497939862935121343 | SELECT id FROM t WHERE id = 8 (10 rows)
tencentdb_sql_throttling.add_rule_with_queryid(queryid bigint,work_node int,max_concurrency int,is_enabled boolean,memory_only boolean,query_string text);
postgres=> SELECT tencentdb_sql_throttling.add_rule_with_queryid(497939862935121343,0,10,true); add_rule_with_queryid ----------------------- (1 row)
tencentdb_sql_throttling.add_rule_with_query(query_string text,work_node int,max_concurrency int,is_enabled boolean,memory_only boolean)
postgres=# select tencentdb_sql_throttling.add_rule_with_query('select pg_sleep(1);',0,1,true);add_rule_with_query-----------------------3416356442043621232(1 row)
tencentdb_sql_throttling.drop_rule(queryid bigint,memory_only boolean);
postgres=> SELECT tencentdb_sql_throttling.drop_rule(497939862935121343,true); -[ RECORD 1 ] drop_rule |
tencentdb_sql_throttling.drop_all_rules(memory_only boolean);
postgres=> select tencentdb_sql_throttling.drop_all_rules(true);drop_all_rules----------------(1 row)
tencentdb_sql_throttling.load_rule(queryid bigint);
postgres=> SELECT tencentdb_sql_throttling.load_rule(497939862935121343); -[ RECORD 1 ] load_rule | postgres=> SELECT * FROM tencentdb_sql_throttling.rules; -[ RECORD 1 ]-------+----------------------------------- queryid | 497939862935121343 work_node | 0 max_concurrency | 10 is_enabled | t query_string | SELECT id FROM t WHERE id = 594017 current_concurrency | 10 total_hit_count | 4760 reject_count | 4713 postgres=>
tencentdb_sql_throttling.load_all_rules();
postgres=> select tencentdb_sql_throttling.load_all_rules();load_all_rules----------------(1 row)
tencentdb_sql_throttling.dump_rule(queryid bigint);
postgres=> select tencentdb_sql_throttling.dump_rule(440101247839410938);dump_rule-----------(1 row)
tencentdb_sql_throttling.dump_all_rules();
postgres=> select tencentdb_sql_throttling.dump_all_rules();;dump_all_rules----------------(1 row)
postgres=> SELECT tencentdb_sql_throttling.dump_all_rules(); NOTICE: duplicate key value violates unique constraint "persistent_rules_table_pkey" NOTICE: duplicate key value violates unique constraint "persistent_rules_table_pkey" dump_all_rules ---------------- (1 row)
SELECT * FROM tencentdb_sql_throttling.rules;来查看当前内存中的限流规则,输出的字段解释如下:postgres=> SELECT * FROM tencentdb_sql_throttling.rules; -[ RECORD 1 ]-------+-------------------------------- queryid | 497939862935121343 work_node | 0 max_concurrency | 10 is_enabled | t query_string | SELECT id FROM t WHERE id = 553 current_concurrency | 0 total_hit_count | 91 reject_count | 81 postgres=>
SELECT * FROM tencentdb_sql_throttling.persistent_rules_table;来查看当前存储中的限流规则,输出的字段解释如下:postgres=> SELECT * FROM tencentdb_sql_throttling.persistent_rules_table; -[ RECORD 1 ]---+----------------------------------- queryid | 497939862935121343 work_node | 0 max_concurrency | 10 is_enabled | t query_string | SELECT id FROM t WHERE id = 594017
tencentdb_sql_throttling.change_rule_status(queryid bigint,is_enabled boolean,max_concurrency int);
postgres=> select tencentdb_sql_throttling.change_rule_status(440101247839410938,true,300);change_rule_status--------------------(1 row)
tencentdb_sql_throttling.change_rule_current_concurrency(queryid bigint,new_currenct_concurrency int);
postgres=> SELECT tencentdb_sql_throttling.change_rule_current_concurrency(497939862935121343,20); -[ RECORD 1 ]-------------------+- change_rule_current_concurrency | postgres=> SELECT * FROM tencentdb_sql_throttling.rules; -[ RECORD 1 ]-------+-------------------------------- queryid | 497939862935121343 work_node | 0 max_concurrency | 10 is_enabled | t query_string | SELECT id FROM t WHERE id = 553 current_concurrency | 20 total_hit_count | 286028 reject_count | 283788 postgres=>
postgres=> SELECT * FROM tencentdb_sql_throttling.rules; -[ RECORD 1 ]-------+-------------------------------- queryid | 497939862935121343 work_node | 0 max_concurrency | 10 is_enabled | t query_string | SELECT id FROM t WHERE id = 553 current_concurrency | 20 total_hit_count | 286028 reject_count | 283788 postgres=> SELECT tencentdb_sql_throttling.change_rule_status(497939862935121343,false,20); -[ RECORD 1 ]------+- change_rule_status | postgres=> SELECT * FROM tencentdb_sql_throttling.rules; -[ RECORD 1 ]-------+-------------------------------- queryid | 497939862935121343 work_node | 0 max_concurrency | 20 is_enabled | f query_string | SELECT id FROM t WHERE id = 553 current_concurrency | 20 total_hit_count | 358931 reject_count | 356691
文档反馈