当前位置:网站首页>Azure SQL db/dw series (10) -- re understanding the query store (3) -- configuring the query store
Azure SQL db/dw series (10) -- re understanding the query store (3) -- configuring the query store
2022-06-13 03:21:00 【Hair dung coating wall】
This paper belongs to Azure SQL DB/DW series
Last article :Azure SQL DB/DW series (9)—— Reunderstanding Query Store(2)—— working principle
In this paper, Query Store Configuration of , Include PaaS Platform and non cloud versions
default setting
Just like other functions , To maximize its potential use , It needs to be configured on demand .Query Store In the non cloud version ( Except managed instances , Because managed instances are very close to non cloud versions ) Not on by default , If you need to use it , Of course, open it , You can use the following command to directly open .
ALTER DATABASE [ Database name ] SET QUERY_STORE = ON;
If you have sufficient authority , I also hope that all user libraries are opened , Then you can use the following command to open except master and Tempdb The library outside :
DECLARE @SQL NVARCHAR(MAX) = N'';
SELECT @SQL += REPLACE(N'ALTER DATABASE [{
{DBNAME}}] SET QUERY_STORE=ON ',
'{
{DBName}}', [name])
FROM sys.databases
WHERE state_desc = 'ONLINE'
AND [name] NOT IN ('master', 'tempdb')
ORDER BY [name];
EXEC (@SQL);
As mentioned earlier , Not right master and TempDB Enable , But you can Model Enable , It doesn't really collect Model Running information of the library , But just like other configurations , Encapsulate this configuration , So that the newly created database will automatically have this attribute . about msdb, Just like the running mode of the user library .
The following is a list of configuration items , Contains Azure SQL DB And non cloud versions :
The following describes the contents listed in the above table .
OPERATION_MODE
Query Store Can run in read-only perhaps read and write In mode , In read-only mode , The data will still be Query Store, But new queries are no longer collected from the time this option is configured . This option is often used for Query Store When the space is full , But you need to analyze the stored data first . Generally speaking, it is recommended to use READ_WRITE:
ALTER DATABASE [<Database Name>] SET QUERY_STORE ( OPERATION_MODE = READ_WRITE );
Query storage has the concept of actual state and desired state . If the desired status is READ_WRITE, But the actual status is READ_ONLY, In the catalog view sys.database_query_store_options In the column readonly_reason The default setting of the display reason is READ_WRITE.
CLEANUP_POLICY (STALE_QUERY_THRESHOLD_DAYS)
Query Store Need to store data , The retention time of data is the same as SIZE_BASED_CLEAN_UP and QUERY_STORE_CAPTURE_MODE May affect the final data storage . The default value is 30 God .
ALTER DATABASE [<Database Name>] SET QUERY_STORE ( CLEANUP_POLICY = ( STALE_QUERY_THRESHOLD_DAYS = <Value> ) );
DATA_FLUSH_INTERVAL_SECONDS
Due to performance ,Query Store The collected data will be stored in memory and then written to disk asynchronously according to the configured value . This time is data flush interval, This value is in seconds .
This value needs to be configured carefully , Too soon will be right I/O Carry out pressure , It is too slow and easy to lose a large amount of data or the data is not updated in time when problems occur . Generally speaking, no change is required , Especially shorter .
The default value is 900 Second is 15 minute , Modify the command to :
ALTER DATABASE [<Database Name>] SET QUERY_STORE ( DATA_FLUSH_INTERVAL_SECONDS = <Value> );
MAX_STORAGE_SIZE_MB
Namely Query Store Free space for , If space is running out , that Query Store The status of will automatically change from READ_WRITE become READ_ONLY, This is related to the database LDF The database becomes read-only when the file is full .
Even if SIZE_BASED_CLEARUP_MODE Set to AUTO, In very high load environments , It is still possible to reach the space limit quickly .
If you have a lot of space , Of course, it is good to set it larger , But consider STALE_QUERY_THRESHOLD_DAYS Value , Retention time is also a factor .
ALTER DATABASE [<Database Name>] SET QUERY_STORE ( MAX_STORAGE_SIZE_MB = <Value> );
QUERY_STORE_CAPTURE_MODE
The default is ALL, The other is for NONE, Set up NONE Will make Query Store Stop collecting new queries , But will not stop collecting already in Query Store Runtime statistics for queries in . The third option is AUTO, tell SQL Server Do not capture queries that are resource intensive or infrequently executed .
ALTER DATABASE [<Database Name>] SET QUERY_STORE ( QUERY_STORE_CAPTURE_MODE = [<Value>] );
about CUSTOM, There are three values to control Query Store The collection behavior of . I will not extend the introduction here . Examples are as follows :
ALTER DATABASE [<Database Name>]
SET QUERY_STORE = ON
(
QUERY_CAPTURE_MODE = CUSTOM,
QUERY_CAPTURE_POLICY = (
STALE_CAPTURE_POLICY_THRESHOLD = 24 HOURS,
EXECUTION_COUNT = 30,
TOTAL_COMPILE_CPU_TIME_MS = 1000,
TOTAL_EXECUTION_CPU_TIME_MS = 100
)
);
MAX_PLANS_PER_QUERY
The default is 200 Execution plans , however 2016 I won't support it . The greater the numerical , The more space you take up , however 200 An execution plan is useful for analyzing the performance of a query , It can be said that it is just right . If you find not enough , You can check and expand with the following command :
SELECT query_hash,
COUNT (DISTINCT query_plan_hash) distinct_plans
FROM sys.dm_exec_query_stats
GROUP BY query_hash
ORDER BY distinct_plans DESC;
ALTER DATABASE [<Database Name>] SET QUERY_STORE ( MAX_PLANS_PER_QUERY = <Value> );
WAIT_STATISTICS_CAPTURE_MODE
The default is ON, It's also not suitable for 2016, Another value is OFF, This part is more important , It's not going to unfold here for the time being , It will be introduced later :
ALTER DATABASE [<Database Name>] SET QUERY_STORE ( WAIT_STATISTICS_CAPTURE_MODE = <Value> );
because GUI It's easier to use , Just know the configuration , I'm not going to do that here . however GUI Some values cannot be modified , Therefore, it is recommended to use the command to configure .
sys.database_query_store_options The configuration values are stored inside , Can be used to check .
Best practices
First configuration MAX_STORAGE_SIZE_MB, Make sure not too few , At the same time pay attention to 30 Whether the retention time of days is enough . General recommendations 2048MB As a starting point . Also note that this data is stored in PRIMARY Filegroups , Make sure there is enough space .
The second is QUERY_STORE_CAPTURE_MODE, It is suggested to change to AUTO, Unless you have other reasons .
SIZE_BASED_CLEANUP_MODE It should also be set to AUTO.
Next is INTERVAL_LENGTH_MINUTES, The default is 60, If the system is not very busy , You can just change it to 15 second , If a very busy system , You can change to 60 above , But not too much .
WAIT_STATISTICS_CAPTURE_MODE Set to ON, Later on .
Next article :Azure SQL DB/DW series (11)—— Reunderstanding Query Store(4)——Query Store maintain
边栏推荐
- Spark Foundation
- KITTI数据集无法下载的解决方法
- Redis memory optimization and distributed locking
- Common command records of redis client
- Available types in C #_ Unavailable type_ C double question mark_ C question mark point_ C null is not equal to
- Neil eifrem, CEO of neo4j, interprets the chart data platform and leads the development of database in the next decade
- Using linked list to find set union
- C language function strcmp() (compare two strings)
- [JVM Series 5] performance testing tool
- Es and kibana deployment and setup
猜你喜欢

JVM class loading (I)

Pytorch record: pytorch variables parameter and buffer. self. register_ buffer()、self. register_ parameter()

SQL execution process in MySQL (3)

Spark Foundation

Introduction to redis (using redis, common commands, persistence methods, and cluster operations)

2-year experience summary to tell you how to do a good job in project management

简述:分布式CAP理论和BASE理论

Available types in C #_ Unavailable type_ C double question mark_ C question mark point_ C null is not equal to

MySQL transactions and locks (V)

Scala implements workcount
随机推荐
Vscode liveserver use_ Liveserver startup debugging
视频播放屡破1000W+,在快手如何利用二次元打造爆款
Quickly obtain the attributes of the sub graph root node
Application framework / capability blueprint
Solution of Kitti data set unable to download
Use of jstack
MySQL imports and exports multiple libraries at one time
Simple use of qtreeview of QT (including source code + comments)
Level II C test skills
开源-校园论坛和资源共享小程序
In my ten years, every bit has become a landscape?
Code d'initialisation de l'arbre binaire
JVM heap (IV)
Wechat applet coordinate location interface usage (II) map interface
简述:分布式CAP理论和BASE理论
How to write product requirements documents
MySQL and PostgreSQL installation subtotal
Entity framework extends the actual combat, small project reconfiguration, no trouble
Vs 2022 new features_ What's new in visual studio2022
On the career crisis of programmers at the age of 35