Oracle Database includes several automated maintenance tasks that help maintain optimal database performance. These tasks are designed to run during specific maintenance windows, ensuring that the database is well-maintained without manual intervention. In this blog, we will explore what these tasks are, how to manage them using SQL commands, and how to enable or disable them as needed.
Understanding Oracle Auto Maintenance Tasks
Oracle’s automated maintenance tasks include:
- Automatic Optimizer Statistics Collection: This task gathers optimizer statistics for the database, which are crucial for the query optimizer to generate efficient execution plans.
- Automatic Segment Advisor: This task identifies segments that would benefit from space reclamation, helping to manage storage efficiently.
- SQL Tuning Advisor: This task analyzes high-load SQL statements and provides tuning recommendations to improve their performance.
Managing Auto Maintenance Tasks with Commands
Oracle provides PL/SQL packages such as DBMS_AUTO_TASK_ADMIN and DBMS_SCHEDULER to manage these tasks.
Enabling and Disabling Individual Tasks
You can enable or disable individual maintenance tasks using the following commands:
- Enable Automatic Optimizer Statistics Collection:
EXEC DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL);
- Disable Automatic Optimizer Statistics Collection:
EXEC DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL);
- Enable Automatic Segment Advisor:
EXEC DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'auto space advisor', operation => NULL, window_name => NULL);
- Disable Automatic Segment Advisor:
EXEC DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto space advisor', operation => NULL, window_name => NULL);
- Enable SQL Tuning Advisor:
EXEC DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'sql tuning advisor', operation => NULL, window_name => NULL);
- Disable SQL Tuning Advisor:
EXEC DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'sql tuning advisor', operation => NULL, window_name => NULL);
Checking the Status of Maintenance Tasks
To verify the status of these tasks, you can query the DBA_AUTOTASK_CLIENT view:SELECT client_name, status FROM DBA_AUTOTASK_CLIENT;
This query will return the status (enabled or disabled) of each maintenance task.
Enabling and Disabling All Auto Maintenance Tasks
If you need to enable or disable all auto maintenance tasks, you can do so with the following commands:
- Enable All Auto Maintenance Tasks:
EXEC DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL);
EXEC DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'auto space advisor', operation => NULL, window_name => NULL);
EXEC DBMS_AUTO_TASK_ADMIN.ENABLE(client_name => 'sql tuning advisor', operation => NULL, window_name => NULL);
- Disable All Auto Maintenance Tasks:
EXEC DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto optimizer stats collection', operation => NULL, window_name => NULL);
EXEC DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto space advisor', operation => NULL, window_name => NULL);
EXEC DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'sql tuning advisor', operation => NULL, window_name => NULL);
Default Settings and Maintenance Windows
By default, all these maintenance tasks are enabled in Oracle Database. They are scheduled to run during maintenance windows, which are predefined time periods allocated for automated maintenance tasks. These windows can be managed using the DBMS_SCHEDULER package.
Example: Altering a Maintenance Window
If you need to change the schedule of a maintenance window, you can use the following command:
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE( name => 'WEEKNIGHT_WINDOW', attribute => 'repeat_interval', value => 'FREQ=DAILY; BYDAY=MON, TUE, WED, THU, FRI; BYHOUR=22; BYMINUTE=0; BYSECOND=0'); END;
This command sets the maintenance window to run from Monday to Friday at 10 PM.
Conclusion
Oracle’s automated maintenance tasks are essential for maintaining database performance and storage efficiency. By understanding how to enable, disable, and manage these tasks, you can ensure that your Oracle Database remains optimized and well-maintained. Use the commands and information provided in this blog to take control of your database’s automated maintenance tasks effectively.