当前位置:网站首页>Hologres query management and timeout processing
Hologres query management and timeout processing
2022-07-05 00:16:00 【The dawn of victory】
adopt Hologres Of Query Management can query SQL Operation information of , Set up Query Timeout for running , Better management SQL, Prevent deadlock .
Inquire about pg_stat_activity View information
select * from pg_stat_activity ;
pg_stat_activity Parameter description of view :
- datid:Hologres The database to which the backend is connected OID.
- datname:Hologres The name of the database to which the backend is connected .
- pid:Hologres Back end process ID.
- usesysid: Log in to Hologres Back end users OID.
- usename: The user name of the current connection .
- application_name: Application type of client .
- client_addr: Client's IP Address . According to the IP The address may be resolved , There is no guarantee that it must be the source IP.
- client_hostname: Host name of the client .
- client_port: Client port .
- backend_start: The time when the background process starts .
- xact_start: The time when the current transaction of the process was started .
- If there are no active transactions , Is empty .
- If the current query is the first transaction of the process , This column is equal to query_start.
- query_start: The time when the current active query started , If the current connection state is not active, The value is the start time of the previous query .
- state_change: The state of the connection (state) The last time it was changed .
- wait_event_type: The type of event the backend is waiting for , If it doesn't exist, it is NULL. The possible values are :
- LWLock: The backend is waiting for a lightweight lock .
- Lock: The backend is waiting for a heavyweight lock .
wait_eventWill identify the type of lock waiting . - BufferPin: The server process is waiting to access a data buffer , At this time, no other process is checking the buffer .
- Activity: The server process is idle . A system process used to wait for activity in its main processing loop .
- Extension: The server process is waiting for activity in an extension module .
- Client: The server process is waiting for some kind of query from the user application , And the server anticipates something that has nothing to do with its internal processing .
- PC: The server process is waiting for some activity from another process in the server .
- Timeout: The server process is waiting for a timeout to occur .
- IO: The server process is waiting for one IO complete .
- wait_event: If the backend is currently waiting , Is the name of the waiting event , Otherwise NULL.
- state: Indicates the status of the connection . Common states are as follows :
- active: active .
- idle: Free .
- idle in transaction: Idle state in long transactions .
- idle in transaction(Aborted): Idle state in failed transactions .
- \N: The state is empty , Represents a non user connected process , Generally, it belongs to the maintenance process in the background of the system , You can ignore .
- backend_xid:Hologres The top-level transaction identifier of the back end .
- backend_xmin: Current backend xmin Range .
- query: Recent queries executed by the backend . If state by
active, The currently executing query will be displayed . In all other states , Display the last executed query . - backend_type: Current backend type . Possible types are autovacuum launcher、autovacuum worker、logical replication launcher、logical replication worker、parallel worker、background writer、client backend、checkpointer、startup、walreceiver、walsender as well as walwriter. In addition, it also includes the back-end execution components , for example PQE etc. .
HoloWeb Active visualization Query management
Can pass HoloWeb Visual view active Query, And manage .
see SQL Operation information
Superuser You can view all users SQL Operation information ,RAM Users can only view their own SQL Operation information .
1. You can view the user's in the current instance through the following statement SQL Operation information .
SELECT datname::text,usename,query,pid::text,state FROM pg_stat_activity;
2. You can execute the following statement to view the currently running SQL Information .
SELECT datname::text,usename,query,pid::text,state
FROM pg_stat_activity
WHERE state != 'idle' ;
3. You can execute the following statement to view the current instance that is running and takes a long time SQL Information .
SELECT current_timestamp - query_start as runtime, datname::text, usename, query, pid::text
FROM pg_stat_activity
WHERE state != 'idle'
order by 1 desc;
4. End Query
If there is currently something that does not meet expectations Query, The following commands can be used to terminate according to the actual situation .
Cancel Query.
select pg_cancel_backend(<pid>);
Batch cancel Query.
SELECT pg_cancel_backend(pid)
,query
,datname::text
,usename
,application_name
,client_addr
,client_port
,backend_start
,state
FROM pg_stat_activity
WHERE length(query) > 0
AND pid != pg_backend_pid()
AND backend_type = 'client backend'
AND application_name != 'hologres'
AND usename != 'holo_admin'
AND query not like '%pg_cancel_backend%';
Modify active Query Timeout time
-- session Level modification ( To modify the timeout SQL Statements are executed together to take effect )
set statement_timeout = <time>;
-- db Level modification
alter database dbname set statement_timeout=<time>;
time The value range of timeout is 0~2147483647ms, The default unit is ms( When time You need to use single quotation marks when adding units , Otherwise, an error will be reported ). The current default timeout is 8 Hours .
Examples are as follows :
Set the timeout to 10min, The specific time zone unit ,10min You need to add single quotation marks as a whole .
set statement_timeout = '10min' ;
select * from tablename;
Set the timeout to 5000ms.
set statement_timeout = 5000 ;
select * from tablename;
Set up db The timeout is 10min.
alter database dbname set statement_timeout='10min';
Query whether the settings are effective :
show statement_timeout;
Modify idle Query Timeout time
Parameters idle_in_transaction_session_timeout Describes the transaction entry idle Timeout behavior after status , If the parameter value is not set , By default, the transaction timeout will not be released , Transactions are prone to occur without releasing , Causes the query to be locked .
When Query When execution generates deadlock , You need to set the timeout . For example, the following code , unexecuted commit, Opened a transaction , But didn't submit , It will cause transaction leakage , And then cause database level deadlock , Affect the normal use of the service .
begin;
select * from t;
When this deadlock scenario occurs , Can be set by idle_in_transaction_session_timeout Timeout to solve . When an idle connection with transactions exceeds idle_in_transaction_session_timeout The set time has not been committed or rolled back , The system will automatically rollback the transaction according to the timeout , And close the connection .
--session Modify idle transaction timeout
set idle_in_transaction_session_timeout=<time>;
--DB Level modify idle transaction timeout
alter database db_name set idle_in_transaction_session_timeout=<time>;
time The value range of timeout is 0~2147483647ms, The default unit is ms( When time You need to use single quotation marks when adding units , Otherwise, an error will be reported ). stay Hologres V0.10 Up to , The default value is 0, That is, it will not be cleaned automatically ; stay Hologres V1.1 edition , The default value is 10 minute , exceed 10 The transaction will be rolled back in minutes .
It is not recommended to set the timeout too short , If it is too short, it is easy to rollback the transaction in use .
Set the timeout to 300000ms.
--session Modify idle transaction timeout
set idle_in_transaction_session_timeout=300000;
--DB Level modify idle transaction timeout
alter database db_name set idle_in_transaction_session_timeout=300000;
Query whether the settings are effective :
show idle_in_transaction_session_timeout;
reference :https://help.aliyun.com/document_detail/263548.html
边栏推荐
- Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC
- Continuous modification of business scenario functions
- go踩坑——no required module provides package : go.mod file not found in current directory or any parent
- P3304 [sdoi2013] diameter (diameter of tree)
- JS 将伪数组转换成数组
- 华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
- 青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
- A new method for analyzing the trend chart of London Silver
- How to do the project of computer remote company in foreign Internet?
- 初识ROS
猜你喜欢

He worked as a foreign lead and paid off all the housing loans in a year

【雅思阅读】王希伟阅读P4(matching2段落信息配对题【困难】)

Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)

海思3559万能平台搭建:YUV422的踩坑记录
![[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection](/img/25/e2366cabf00e55664d16455a6049e0.png)
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection

Hash table, hash function, bloom filter, consistency hash

青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区

PMP certificate renewal process

Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention

Continuous modification of business scenario functions
随机推荐
多回路仪表在基站“转改直”方面的应用
同事的接口文档我每次看着就头大,毛病多多。。。
Upload avatar on uniapp
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
(脚本)一键部署redis任意版本 —— 筑梦之路
电力运维云平台:开启电力系统“无人值班、少人值守”新模式
Go pit - no required module provides Package: go. Mod file not found in current directory or any parent
uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
Date time type and format in MySQL
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
js如何实现数组转树
Microservice
两个数相互替换
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
华为200万年薪聘请数据治理专家!背后的千亿市场值得关注
Is the account opening link of Huatai Securities with low commission safe?
[paper reading] cavemix: a simple data augmentation method for brain vision segmentation
How to use fast parsing to make IOT cloud platform