19c-高频自动优化器统计收集
(2019-08-01 15:11:10)3.
高频自动优化器统计收集
您可以配置轻量级,高频率的自动任务,定期收集过时对象的优化程序统计信息。在执行DBMS_STATS统计信息收集作业之间,统计信息可能会过时。通过更频繁地收集统计信息,优化程序可以生成更优化的计划。
https://docs.oracle.com/en/database/oracle/oracle-database/19/tgsql/gathering-optimizer-statistics.html#GUID-374ACB86-2512-4658-9170-8505B3EACF7D
原先每天晚上10点数据库统计信息收集不再存放在select * from dba_scheduler_jobs,而是:
SELECTCLIENT_NAME, STATUS
FROM
WHERE
select * FROM
select * FROM
select * FROM
select * from
select * from
select * from
BEGIN
,
,
);
END;
/
BEGIN
,
,
);
END;
/
How
To enable and disable the high-frequency task, set
the execution interval, and set the maximum run time, use
the DBMS_STATS.SET_GLOBAL_PREFS
Automatic statistics collection jobs that run in
the maintenance window are not affected by the high-frequency jobs.
The high-frequency tasks do not start during the maintenance
window, so only one statistics task runs at a time. You can monitor
the tasks by querying DBA_AUTO_STAT_EXECUTIONS
.
SELECT OPID, ORIGIN, STATUS, TO_CHAR(START_TIME, 'DD/MM HH24:MI:SS' ) AS BEGIN_TIME,
FROM
WHERE
ORDER BY OPID;
13.2.2
To enable and disable the task,
use
You can
use
- AUTO_TASK_STATUS
Enables or disables
the
-
-
ON
— Enables high-frequency automatic optimizer statistics collection. -
OFF
— Disables high-frequency automatic optimizer statistics collection. This is the default.
-
ON
- AUTO_TASK_MAX_RUN_TIME
Configures the maximum run time in
seconds of an execution of
- AUTO_TASK_INTERVAL
Specifies the interval in seconds between
executions of
To configure the high-frequency task:
- Log in to the database as a user with administrator privileges.
-
To enable the high-frequency task, set
the
AUTO_TASK_STATUS preference to ON.
The following example enables the automatic task:
EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_STATUS','ON');
-
To set the maximum run time, set
the
AUTO_TASK_MAX_RUN_TIME preference to the desired number of seconds.
The following example sets the maximum run time to 10 minutes:
EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_MAX_RUN_TIME','600');
-
To set the frequency, set
the
AUTO_TASK_INTERVAL preference to the desired number of seconds.
The following example sets the frequency to 8 minutes:
EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_INTERVAL','240');
13.2.3
In this example, you enable run DML statements, and then enable the high-frequency statistics collection job.
This example assumes the following:
- You are logged in to the database as an administrator.
-
The statistics for
the
sh schema are fresh. - High-frequency automatic optimizer statistics collection
is not enabled.
-
Query the data dictionary for the
statistics for the
sales and customerstables (sample output included):
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
SALES
The preceding output shows that none of the statistics are stale.
-
Perform DML
on
sales and customers:
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
COMMIT;
The total number
of
- Save the optimizer statistics to disk:
EXEC DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
- Query the table statistics again (sample output included):
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
SALES
101.
102. 31 rows selected.
The preceding output shows that the
statistics are not stale for
-
Configure
high-frequency automatic optimizer statistics collection:
104. EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_STATUS','ON');
105. EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_MAX_RUN_TIME','180');
EXEC DBMS_STATS.SET_GLOBAL_PREFS('AUTO_TASK_INTERVAL','240');
The preceding PL/SQL programs enable high-frequency collection, set the maximum run time to 3 minutes, and set the task execution interval to 4 minutes.
- Wait for a few minutes, and then query the data dictionary:
107. COL OPID FORMAT 9999
108. COL STATUS FORMAT a11
109. COL ORIGIN FORMAT a20
110. COL COMPLETED FORMAT 99999
111. COL FAILED FORMAT 99999
112. COL TIMEOUT FORMAT 99999
113. COL INPROG FORMAT 99999
114.
115. SELECT OPID, ORIGIN, STATUS, TO_CHAR(START_TIME, 'DD/MM HH24:MI:SS' ) AS BEGIN_TIME,
116.
117.
118.
FROM
119. ORDER BY OPID;
The output shows that the high-frequency job executed twice, and the standard automatic statistics collection job executed once:
----- -------------------- ----------- -------------- -------------- --------- ------ ------- ------