This chapter introduces you to some of the monitoring and tuning operations as performed through Enterprise Manager.
This chapter discusses the following:
| Proactively Monitoring your Database | ||
| Diagnosing and Resolving Performance Problems | ||
| Using the SQL Tuning Advisor | ||
| Using the SQL Access Advisor | ||
| Using the Memory Advisor | ||
Move your mouse over this icon to show all screenshots.
You can also move your mouse over each individual icon to see only the screenshot
associated with it.
Alerts help you monitor your database proactively. Most alerts are notifications when particular metrics thresholds are crossed. For each alert, you can set critical and warning threshold values. These threshold values are meant to be boundary values that when crossed indicate that the system is in an undesirable state.
In this section, you will perform the following tasks:
| Creating a Tablespace and Table with a Specified Threshold | ||
| Triggering a Tablespace Space Usage Alert | ||
| Setting Metric Thresholds | ||
| Setting up Notifications | ||
First, you create a new tablespace with a 20 MB data file. This tablespace should be locally managed, and use Automatic Segment Space Management (ASSM). You will then create a new table in this new tablespace. This table will have the Enable Row Movement option set to yes to allow for space reclamation in the table. Perform the following:
You will now update the table to trigger a space utilization alert. Perform the following:
| 1. |
Open a SQL*Plus session and execute the following command: sqlplus system/oracle |
| 2. |
Copy and paste the following SQL commands into your SQL*Plus session to simulate user activity on the EMPLOYEES1 table: begin
for i in 1..1000 loop
insert into employees1
select * from hr.employees;
commit;
end loop;
end;
/
|
| 3. |
Go to the Enterprise Manager window. Click the Database breadcrumb to return to the Administration page then click the Tablespaces link.
|
| 4. |
Notice that the TBSALERT tablespace space used percentage has increased.
|
| 5. |
Switch back to the SQL*Plus window and copy and paste the following commands into your SQL*Plus session to simulate more user activity on the EMPLOYEES1 table: delete employees1 where department_id = 50; begin
for i in 1..500 loop
insert into employees1
select * from hr.employees;
commit;
end loop;
end;
/
|
| 6. |
Go to the Enterprise Manager window. Refresh your browser (for Linux Mozilla, select View from the menubar then select Reload). Notice that the TBSALERT tablespace space usage percentage has increased.
|
| 7. |
Switch back to the SQL*Plus window and copy and paste the following commands into your SQL*Plus session to simulate more user activity on the EMPLOYEES1 table: begin
for i in 1..500 loop
insert into employees1
select * from hr.employees;
commit;
end loop;
end;
/
|
| 8. |
Copy and paste the following SQL commands into your SQL*Plus session to simulate user activity on the EMPLOYEES1 table: delete employees1 where department_id = 30; commit; delete employees1 where department_id = 100; commit; delete employees1 where department_id = 50; commit; delete employees1 where department_id = 80; commit; exit
|
| 9. |
Go to the Enterprise Manager window. Refresh your browser (for Linux Mozilla, select View from the menubar then select Reload). Notice that the TBSALERT tablespace space usage percentage has now exceeded the critical threshold level of 68%.
|
| 10. |
While you are waiting for the space usage alert to be displayed on the Enterprise Manager home page, review the table segment statistics. Click the Database breadcrumb then click the Tables link.
|
| 11. |
To locate the SYSTEM.EMPLOYEES1 table, enter system in the Schema field and emp in the Object Name field. Click Go.
|
| 12. |
Click the EMPLOYEES1 link.
|
| 13. |
Click Segments.
|
| 14. |
Notice the percentage of wasted space in the EMPLOYEES1 table. You may be able to resolve the tablespace space usage alert by reclaiming unused space in this table. On this same page, you can project the EMPLOYEES1 table's future space usage by specifying a date range for Space Usage Trend and clicking the Refresh button. Because there has not been a enough activity history on the EMPLOYEES1 table, you will not see very meaningful data in the space usage analysis graph. Click the Database breadcrumb and then click the Home page tab.
|
| 15. |
Click the Refresh button a few times until you see a red x and the number 1 next to Problem Tablespaces. Scroll down to the Alerts table.
|
| 16. |
You should see a Tablespaces Full alert. Click on the Tablespace [TBSALERT] is [70 percent] full link.
|
Oracle provides a set of predefined metrics, some of which initially have thresholds defined for them. You previously defined a metric for Tablespace Usage for the TBSALERT tablespace. To review all the metrics, perform the following:
| 1. |
Click Manage Metrics in the Related Links region.
|
| 2. |
Click Edit Thresholds.
|
| 3. |
Scroll down to the Tablespace Space Used (%) and select this metric. Scroll back up to the top of the window.
|
| 4. |
Click Specify Multiple Thresholds.
|
| 5. |
For the TBSALERT tablespace, change the Warning Threshold to 70 and the Critical Threshold to 80. Click OK.
|
| 6. |
The change has been made. Click OK to save the data in the database.
|
| 7. |
The update was successful. Click the Database breadcrumb.
|
You can optionally provide notification when events that require your intervention arise. By default, alerts in critical state such as Database Down, Generic Alert Log Error Stats, and Tablespace Used are set up for notification. Perform the following:
| 1. |
Click Setup at the top of the Database home page.
|
| 2. |
Click Notification Methods.
|
| 3. |
Enter <your mailserver> in the Outgoing Mailserver field, dbaalert in the Identify Sender As field and notify01@oracle.com in the Sender's Email field and click Apply.
|
| 4. |
Your update was successful. Click Preferences at the top of the page.
|
| 5. |
click Add Another Row for E-mail Addresses the General option.
|
| 6. |
Enter notify01@oracle.com as the email address and click Apply. Then click Database.
|
At times database performance problems arise that require your diagnosis and correction. Sometimes problems are brought to your attention by users who complain about slow performance. Other times you might notice performance spikes in the Host CPU chart on the home page.
In all cases, these problems are flagged by the Automatic Database Diagnostics Monitor (ADDM), which does a top-down system analysis every 60 minutes by default and reports its findings on the Oracle Enterprise Manager Home page. ADDM runs automatically every 60 minutes to coincide with the snapshots taken by the Automatic Workload Repository (AWR). Its output consists of a description of each problem it has identified, and a recommended action.
| Creating a Performance Finding | ||
| Resolving the Performance Finding using ADDM | ||
To show how ADDM works, you will create a performance finding. In this case, you will create a session waiting on a row lock. To perform certain operations such as updates and deletes, the session must obtain a lock on the row. Perform the following steps to create a performance finding:
| 1. |
Open a terminal window and execute the following commands: sqlplus hr/hr create table emp as select * from employees; delete emp;
|
| 2. |
Open another terminal window and execute the following commands to create a row locking conflict: sqlplus hr/hr delete emp;
|
| 3. |
Click Performance in your Enterprise Manager window .
|
| 4. |
You see that the sessions waiting is very high. Wait about 10 minutes and scroll down to the bottom of the window.
|
| 5. |
You will now create a snapshot to capture the performance finding. Click on Snapshots.
|
| 6. |
Click Create to create a snapshot.
|
| 7. |
Click Yes to create a Manual Snapshot.
|
| 8. |
A snapshot is now being taken.
|
| 9. |
Once the snapshot is created, click the database breadcrumb and then home.
|
| 10. |
A performance finding is now detected through an alert in the Alert section of the Home page.
|
When a performance finding is encountered, you can use ADDM to resolve it. Perform the following:
| 1. |
Click the Alert Database Time Spent Waiting.
|
| 2. |
You notice that the recommended action is to run ADDM to get more performance analysis about your system. Click Additional Advice.
|
| 3. |
Make sure the snapshot you took is selected from the list. Notice that SQL statements were found waiting for row lock waits impacting your system for more than 86% of your database time. Click this finding in the list.
|
| 4. |
You see the action that needs to be taken to resolve the performance issue. Click View Rationale.
|
| 5. |
You see the particular SQL ID that is causing the problem. Click Close.
|
| 6. |
To resolve the performance finding, click the Database breadcrumb.
|
| 7. |
Click Performance.
|
| 8. |
Scroll down and select Blocking Sessions under
Additional Monitoring Links.
|
| 9. |
Make sure the highest level HR is selected and click Kill Session.
|
| 10. |
Click Yes to kill the session.
|
| 11. |
The session has been killed. Click the Database breadcrumb and then click Home.
|
| 12. |
Notice the alert has disappeared.
|
The following are tasks a database administrator or operator performs to reactively monitor and diagnose database performance issues:
| Viewing Database Waits | ||
| Examining Top SQL for a Database Wait Class | ||
| Tune a SQL Statement Using the SQL Tuning Advisor | ||
| Reviewing SQL Execution Details for a SQL Statement | ||
| 1. |
Open a command line window, and run the following OS script: ./setup_perflab.sh Note: This script will take approximately four minutes to run.
|
|
| 2. |
Switch back to your Enterprise Manager window. Select the Administration link.
|
|
| 3. |
In the section titled Workload, click on the Automatic Workload Repository link.
|
|
| 4. |
Determine how many snapshots have already been collected for this database. Look under Snapshots for the count and the time the last ADDM snapshot was taken. There should be at least three snapshots. Click the Database breadcrumb.
|
|
| 5. |
Click the Performance link.
|
|
| 6. |
In the Performance Window, review the Sessions: Waiting and Working graph. A chart representing the current workload of your database is shown. (It may take a minute for the chart to be populated with data) This chart is populated with data collected by the ADDM snapshots. To the side of the graph is the legend. Each legend entry is coded to a different color. You can determine quickly from the graph that the item with the largest time is yellow, or User I/O. Click on the User I/O link.
|
|
| 7. |
Below the Active Sessions Waiting: User I/O chart, there are two pie charts. Investigate the pie chart on the left, Top Waiting SQL. This shows that the overwhelming majority of waits, 53%, were caused by one SQL statement. Investigate the pie chart on the right, Top Waiting Sessions. This pie chart shows that the current top active sessions are waiting about the same percentage of time.
|
|
As was shown in the previous task, there is one SQL statement causing the majority of the database waits. In this task you will drill down to find the root cause. Perform the following:
| 1. |
From within the Active Sessions Waiting: User I/O page, click Top SQL in the middle of the page.
|
|
| 2. |
On the detail page that appears, view the Wait Events for Top SQL table, which is ordered by Activity (%). You can see the Top SQL statement spent most of its time on the activity 'db file scattered read'. Click on the SQL ID of the SQL statement with the highest percentage of activity.
|
|
| 3. |
The execution plan for this SQL statement is displayed. Click the Current Statistics tab.
|
|
| 4. |
The statistics for this SQL statement is displayed. Click the Execution History tab.
|
|
| 5. |
The statistical analysis chart for this SQL statement is displayed. The CPU and Elapsed Time chart shows the amount of CPU used by all executions of this SQL statement over a period of time. Select Seconds Per Execution and click on Go to display the time and resources used for each execution of this SQL statement.
|
|
| 6. |
From the displayed charts, it can be determined that CPU resource usage is increasing, and the time it takes to execute this SQL statement is also increasing. Click the Tuning History tab.
|
|
| 7. |
The previous tuning recommendations for this SQL statement is displayed. At this time, there are none. You are now ready to tune the SQL statement using the SQL Tuning Advisor.
|
|
As determined in the previous section on reactive tuning, the targeted SQL statement needs tuning. The SQL Tuning Advisor will tune the execution plan for you. Perform the following:
| 1. |
Click Run SQL Tuning Advisor.
|
| 2. |
At the Schedule Advisor window, make sure the Scope Comprehensive is selected and the job will be scheduled Immediately. Click OK.
|
| 3. |
The SQL Tuning Advisor will create a task to analyze the SQL statement, and upon completion of this task, display a set of tuning recommendations.
|
| 4. |
Click View Recommendations.
|
| 5. |
Click the New Explain Plan button to view the suggested change.
|
| 6. |
As can be seen, the new explain plan removes the full table scans. Click the browser back button to return to the previous page.
|
| 7. |
Click the Implement button to implement the tuning recommendation.
|
| 8. |
A confirmation page appears indicating that the SQL Profile was successfully created. Click the Database breadcrumb.
|
Now that you have implemented the tuning suggestion, review the SQL statement and its execution details. Perform the following steps.
| 1. |
Click Performance.
|
|
| 2. |
Scroll down to the Sessions: Waiting and Working chart. Wait for about one minute and observe how the User I/O is decreasing.
|
|
The SQL Access Advisor provides a number of procedures which can be called to help decide which materialized views and indexes to create and drop. It makes this decision using either a hypothetical workload, which it bases on your schema, or from an actual workload which can be provided by the user, from Oracle Trace or from the contents of the SQL cache.
Workloads may also be filtered according to different criteria, such as only use queries containing these tables or queries which have a priority between this range.
| Preparing the Environment | ||
| Using the SQL Cache to Get Recommendations | ||
| Reviewing and Implementing the Recommendations | ||
To prepare the environment for using the SQL Access Advisor, perform the steps below. Materialized views and indexes can be present when the advisor is run, but for the purposes of this example they are removed so that you can see what the advisor will recommend. You need to also set up the cache so that the SQL Access Advisor can generate recommendations. Perform the following:
| 1. |
Open a terminal window and execute the following commands to clean up your environment: sqlplus system/<password> DROP MATERIALIZED VIEW all_cust_sales_mv;
|
|
| 2. |
Now you need to create the cache. Execute the following commands: alter system flush shared_pool;
|
|
You will use the SQL Cache you just set up to obtain recommendations from the SQL Access Advisor. Perform the following:
| 1. |
Open your browser and enter the following URL: http://<hostname>:5500/em Enter sys/<password> as SYSDBA and click Login.
|
|
| 2. |
Scroll to the bottom of the Home page and click on Advisor Central under Related Links.
|
|
| 3. |
Click on the SQL Access Advisor link.
|
|
| 4. |
Make sure Current and Recent SQL Activity is checked and click on Show Advanced Options.
|
|
| 5. |
Scroll down. Under Filter Options, select Filter workload based on these options. Select Only the top resource consuming SQL statements and Only SQL statements executed by the following users. Then enter SH in the Users field and click Next.
|
|
| 6. |
Select Both Indexes and Materialized Views and click Next.
|
|
| 7. |
Enter the task name OBE<Today's Date>, select Standard for the Schedule Type and click Next.
|
|
| 8. |
At the summary window, click Submit.
|
|
Now you can look at the results and implement them if you wish. Perform the following:
| 1. |
Make sure your job is selected and click View Result.
|
|
| 2. |
Click on the Recommendation ID 1 to see the details of the Recommendations.
|
|
| 3. |
Here you can customize the Object Name, Schema and Tablespace to implement the recommendations. Scroll down and change the Schema Name for the Create Materialized View to SH and click OK.
|
|
| 4. |
To see the SQL Script that will be executed when you schedule the implementation, click Show SQL.
|
|
| 5. |
Scroll down to the bottom and you will see the statements to create the materialized view with the change you just made. Click OK.
|
|
| 6. |
To implement the recommendations, click Schedule Implementation.
|
|
| 7. |
Enter OBEIMPL<today's date> for the Job Name and click Submit.
|
|
| 8. |
Your implementation job was created and is now running. Click the Run History tab.
|
|
| 9. |
Make sure your job is selected and click View.
|
|
| 10. |
Review the summary and click your database breadcrumb.
|
|
| 11. |
Click Materialized View.
|
|
| 12. |
Enter SH in the schema field and click Go.
|
|
| 13. |
Notice that the newly created Materialized View appears in the list. Click the Database breadcrumb then click the Home tab.
|
|
In this section, you will proactively manage and automate some of the tasks related to Oracle Instance memory configuration. By automating memory configuration, you have more time to deal with real application or business issues that affect your enterprise.
The Memory Advisor is an intelligent expert system within the Oracle database that proactively determines optimal settings for various SGA and PGA components. When automated, Oracle will automatically adjust the settings for the various pools and caches according to the requirements of the workload.
| Enabling Automatic Shared Memory Management | ||
| Change the Total SGA Size | ||
| Using the PGA Advisor | ||
To enable automatic shared memory management of the SGA, perform the following:
| 2. |
Scroll down to the bottom of the home page and click on Advisor Central under Related Links.
|
|
| 3. |
Select Memory Advisor.
|
|
| 4. |
Click Enable for Automatic Shared Memory Management.
|
|
| 5. |
Click OK to enable Automatic Shared Memory Management.
|
|
| 6. |
The Oracle server will now automatically adjust the settings for the various pools and caches according to the requirements of the workload.
|
|
To change the total SGA size when in automatic shared memory management mode, you will need to make sure the maximum SGA Size is large enough. Perform the following:
| 1. |
Scroll down the page. Change Maximum SGA Size to 261 MB and click Apply. Note: If you receive an error, click the Refresh button and try it again.
|
|
| 2. |
Click Yes to confirm the change.
|
|
| 3. |
Supply the host credentials and the database credentials.
Click OK.
|
|
| 4. |
When you changing the Max SGA Size parameter, the instance must be restarted. Click Yes to confirm restart of the database.
|
|
| 5. |
The database restart process will start. Click Refresh.
|
|
| 6. |
Enter sys/<password>as SYSDBA and click Login.
|
|
| 7. | Scroll down and click Advisor Central.
|
|
| 8. | Click Memory Advisor.
|
|
| 9. | Change the Total SGA Size parameter
to 260 MB. Click Apply.
Note that the Max SGA Size parameter was automatically adjusted to conform to the memory granule size Though you had set it to be 261 MB originally, the Oracle server automatically changed it to 264 MB.
|
|
| 10. |
Once you receive the confirmation notice that the parameter was changed successfully, you'll also notice that memory allocation to some of the SGA components was adjusted automatically.
|
|
To allocate memory associated with the PGA, perform the following:
| 1. |
Click PGA.
|
|
| 2. |
Click Advice....
|
|
| 3. |
The PGA Aggregate Target Advice graph shows the frequency in which data is found in cache so that you do not have to access disk. In this case, it should be noted that the current PGA Aggregate Size is set to approximately 24 MB, and over 88% of all the requested services are gotten from memory. This also shows the overflow range which starts around 12 MB. At 12 MB, the PGA requests hit the cache around 90%. The PGA Aggregate Size implies that (based on current workloads and the number of sessions in the database), no more than 24 MB should be allocated for all PGAs in this database. Click OK.
|
|
| 4. |
Click PGA Memory Usage Details.
|
|
| 5. |
This graph shows the usage details in memory size requests and executions percentages for various PGA memory requests. Click OK.
|
|
Move your mouse over this icon to hide all screenshot