1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu OCA: Oracle Database 11g Administrator Certified Associate- P20 ppt

50 339 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 1,22 MB

Nội dung

Proactive Database Maintenance 781 EXTSTAT -------------------------------- SYS_STUZVS6GX30A0GN_5YRYSD2LPM SQL> SQL> exec dbms_stats.gather_table_stats(null, ‘customers’, method_opt=>’for all columns size skewonly’); PL/SQL procedure successfully completed. SQL> select column_name, num_distinct, histogram 2 from user_tab_col_statistics 3* where table_name = ‘CUSTOMERS’ SQL> / COLUMN_NAME NUM_DISTINCT HISTOGRAM ------------------------------ ------------ --------------- CUST_NAME 47692 HEIGHT BALANCED CUST_STATE 6 FREQUENCY CUST_COUNTRY 3 FREQUENCY SYS_STUZVS6GX30A0GN_5YRYSD2LPM 8 FREQUENCY SQL> select * from customers where cust_country = ‘India’ and cust_state = ‘TN’; ------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 86 | 2580 | 137 (1)| 00:00:02 | |* 1 | TABLE ACCESS FULL| CUSTOMERS | 86 | 2580 | 137 (1)| 00:00:02 | ------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(“CUST_STATE”=’TN’ AND “CUST_COUNTRY”=’India’) As you can see in the example, before extended statistics were collected, the estimated number of rows was 1447, whereas after the extended statistics collection, the number of rows optimizer estimated to return is 86. 95127c14.indd 781 2/17/09 2:54:18 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 782 Chapter 14 N Maintaining the Database and Managing Performance To drop the extend statistics, use the DROP_EXTENDED_STATISTICS procedure: SQL> exec dbms_stats.drop_extended_stats(null,’CUSTOMERS’, ‘(CUST_COUNTRY, CUST_STATE)’); PL/SQL procedure successfully completed. SQL> To define the extension and collect statistics in one step, you can do the following: SQL> exec dbms_stats.gather_table_stats(null, ‘customers’, method_opt=>’for all columns size skewonly for columns (cust_country, cust_state)’); PL/SQL procedure successfully completed. SQL> select extension_name, extension from user_stat_extensions 2 where table_name = ‘CUSTOMERS’; EXTENSION_NAME EXTENSION ------------------------------------ ----------------------------- SYS_STUZVS6GX30A0GN_5YRYSD2LPM (“CUST_COUNTRY”,”CUST_STATE”) In the next section, you’ll learn to enable and disable the automatic statistics collection as well as perform other AutoTask jobs. Configuring Automated Maintenance Tasks Using EM The following are three default automated maintenance tasks: Gathering optimizer statistics ÛN Running the Segment Advisor ÛN Running the SQL Tuning Advisor ÛN You can also enable and disable the AutoTask jobs using EM Grid Control. On the Server tab, choose Automated Maintenance Tasks under Oracle Scheduler. Figure 14.8 shows the Automated Maintenance Tasks screen. By clicking the Configure button, you can enable or disable the default AutoTask jobs, as well as adjust the days on which these tasks are run, as shown in Figure 14.9. To learn more about Automated Maintenance Tasks and Oracle Scheduler, read the “Oracle Database Administrator’s Guide 11g Release 1 (11.1) Part Number B28310-04” Oracle documentation. 95127c14.indd 782 2/17/09 2:54:18 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Proactive Database Maintenance 783 Figure 14.8 Automated Maintenance Tasks screen Figure 14.9 Configure Automated Maintenance Tasks screen 95127c14.indd 783 2/17/09 2:54:18 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 784 Chapter 14 N Maintaining the Database and Managing Performance Gathering Performance Statistics Oracle Database generates several performance statistics that are used for self-tuning purposes and are available for administrators to better tune the database. Most of the performance statistics information is available through V$ dictionary views (also known as dynamic performance views). The information in the V$ views are not persistent; that is, informa- tion is lost when the database is shut down. Automatic Workload Repository (AWR) saves the performance information in system tables and is made available for analysis through EM Database Control and other third-party tools. AWR information is persistent across database shutdowns. The AWR data is captured at a system or database level, and session-level information is captured using another mechanism called the Active Session History (ASH). You will learn about AWR and ASH in the following sections. Using Automatic Workload Repository Two background processes are responsible for collecting the performance statistics: Memory Monitor (MMON) and Memory Monitor Light (MMNL). These processes work together to collect performance statistics directly from the system global area (SGA). The MMON process does most of the work by waking up every 60 minutes and gathering statistical information from the data dictionary views, dynamic performance views, and optimizer and then storing this information in the database. The tables that store these sta- tistics are the Automatic Workload Repository. These tables are owned by the user SYSMAN and are stored in the SYSAUX tablespace. To activate the AWR feature, you must set the pfile/spfile’s parameter STATISTICS_LEVEL to the appropriate value. The values assigned to this parameter determine the depth of the statistics that the MMON process gathers. Table 14.3 shows the values that can be assigned to the STATISTICS_LEVEL parameter. table 14.3 Specifying Statistics Collection Levels Collection Level Description BASIC Disables the AWR and most other diagnostic monitoring and advisory activities. Few database statistics are gathered at each collection inter- val when operating the instance in this mode. TYPICAL Activates the standard level of collection activity. This is the default value for AWR and is appropriate for most environments. ALL Captures all the statistics gathered by the TYPICAL collection level, plus the execution plans and timing information from the operating system. 95127c14.indd 784 2/17/09 2:54:18 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Proactive Database Maintenance 785 Once gathered, the statistics are stored in the AWR for a default duration of eight days. However, you can modify both the frequency of the snapshots and the duration for which they are saved in the AWR. One way to modify these intervals is by using the Oracle-supplied package DBMS_WORKLOAD_REPOSITORY . The following SQL command shows the DBMS_WORKLOAD_ REPOSITORY package being used to change the AWR collection interval to 1 hour and the retention period to 30 days: SQL> execute dbms_workload_repository.modify_snapshot_settings (interval=>60,retention=>43200); PL/SQL procedure successfully completed. The 30-day retention value shown here is expressed in minutes: 60 minutes per hour × 24 hours per day × 30 days = 43,200 minutes. You can also change the AWR collection interval, retention period, and collection depth using EM Database Control. Choose the Server tab, and click Automatic Workload Reposi- tory under Statistics Management (see Figure 14.10). Figure 14.10 AWR statistics collection and retention using EM Click the Edit button to change the settings, as shown in Figure 14.11. 95127c14.indd 785 2/17/09 2:54:18 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 786 Chapter 14 N Maintaining the Database and Managing Performance Figure 14.11 Changing AWR statistics collection and retention using EM In Figure 14.11, the retention period for statistics gathered by the MMON process is set to 15 days, and statistics are collected every 30 minutes. You can also modify the depth at which statistics are collected by the AWR by clicking the Collection Level link. Clicking this link opens the Initialization Parameters screen where you can specify any of the three predefined collection levels shown in Table 14.3. Figure 14.12 shows the AWR collection level being changed from TYPICAL to ALL . Figure 14.12 Changing the AWR statistics collection level 95127c14.indd 786 2/17/09 2:54:19 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Proactive Database Maintenance 787 Take care when specifying the AWR statistics collection interval. Gath- ering snapshots too frequently requires additional space in the SYSAUX tablespace and adds database overhead each time the statistics are col- lected. AWR does not use any space in the SGA. Using EM Database Control, you can view the AWR report. Click the Run AWR Report but- ton on the Automatic Workload Repository screen shown earlier in Figure 14.10. You can get the same report using SQL*Plus by running the script $ORACLE_HOME/rdbms/admin/awrrpt.sql . You can manage the AWR snapshots with SQL*Plus by utilizing the DBMS_WORKLOAD_ REPOSITORY package, as described in the next section. Managing AWR Snapshots Manually You can create AWR snapshots by using the CREATE_SNAPSHOT procedure, as shown here: SQL> EXECUTE DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT (); PL/SQL procedure successfully completed. SQL> You can use the DROP_SNAPSHOT_RANGE procedure to delete a range of snapshots, and you can query valid snapshot IDs from the DBA_HIST_SNAPSHOT view. The following example shows how to query the DBA_HIST_SNAPSHOT view: SQL> SELECT snap_id, begin_interval_time, end_interval_time 2 FROM dba_hist_snapshot 3 ORDER BY snap_id; SNAP_ID BEGIN_INTERVAL_TIME END_INTERVAL_TIME ---------- ------------------------------ ------------------------------ 1 24-SEP-08 02.06.11.000 AM 24-SEP-08 03.00.14.156 AM 2 25-SEP-08 12.06.26.000 AM 25-SEP-08 12.17.55.437 AM 3 25-SEP-08 12.17.55.437 AM 25-SEP-08 01.00.51.296 AM 4 25-SEP-08 01.00.51.296 AM 25-SEP-08 02.00.22.109 AM … … … 27 27-SEP-08 07.03.17.375 PM 29-SEP-08 04.03.47.687 AM 28 29-SEP-08 04.03.47.687 AM 29-SEP-08 05.00.39.437 AM 29 29-SEP-08 05.00.39.437 AM 29-SEP-08 05.42.13.718 AM To delete snapshots in the range 5–15, you can execute the following code. Note that the ASH (discussed in the next section) data is also purged between the time periods specified by the snapshot range. SQL> BEGIN 2 DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE (5, 15); 3 END; 4 / PL/SQL procedure successfully completed. SQL> 95127c14.indd 787 2/17/09 2:54:19 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 788 Chapter 14 N Maintaining the Database and Managing Performance Once AWR snapshots are taken and stored in the database, the Automatic Database Diagnostic feature uses the AWR data, as described in the “Automatic Database Diagnostic Monitoring” section. Active Session History ASH is sampled data at specified intervals from the current state of all active sessions. The data is collected in memory and can be accessed by V$ views. The ASH information is also written to a persistent store by the AWR snapshots. The V$ACTIVE_SESSION_HISTORY provides the information collected by the ASH sampler. The sessions are sampled every second and are stored in a circular buffer in SGA. Each session is stored as a row. The current and historical information is available in the data dictionary view DBA_HIST_ACTIVE_SESS_HISTORY . ASH information also includes the execu- tion plan for each SQL captured. Oracle provides a script to generate an ASH report, $ORACLE_HOME/rdbms/admin/ ashrpt.sql . You will be prompted for the report type (HTML or text), the begin time in minutes prior to SYSDATE , the duration in minutes for the report, and a name for the report. You can also use EM Database Control to generate the ASH report. On the EM Database Control home screen, click the Performance tab, and click the Run ASH Report button, as shown in Figure 14.13. Figure 14.13 Performance screen in EM Database Control 95127c14.indd 788 2/17/09 2:54:19 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Proactive Database Maintenance 789 The screen shown in Figure 14.14 captures parameters for the ASH report. Specify the start time and end time for the report, and click the Generate Report button. Figure 14.14 ASH report parameters Any session that is connected to the database and does not wait for a wait event that belongs to the idle wait class is considered as an active session. AWR Baselines It is a good practice to baseline your database when everything is working as expected. When things go south, you can use this baseline to compare system statistics and perfor- mance metrics. AWR baselines contain performance data from a specific time period that is preserved for comparison when problems occur. This baseline data is excluded from the AWR purging process. You can create two types of baselines: a single baseline and a repeating baseline. A single baseline is captured at a single fixed-time interval, such as October 5 between 10 a.m. and 1 p.m. A repeating baseline repeats during a time interval for a specific period, such as every Friday between 10 a.m. and 1 p.m. You can create and delete AWR baselines using EM Database Control or SQL*Plus. Managing AWR Baselines Using SQL*Plus To create a single baseline, use the CREATE_BASELINE procedure as shown in the following code. You can include the optional expiration parameter to automatically delete the snap- shot after the specified number of days. 95127c14.indd 789 2/17/09 2:54:19 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 790 Chapter 14 N Maintaining the Database and Managing Performance SQL> BEGIN 2 DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE( 3 start_snap_id => 27, 4 end_snap_id => 29, 5 baseline_name => ‘OCP Example’, 6 expiration => 21); 7 END; SQL> / PL/SQL procedure successfully completed. SQL> To drop a baseline, use the DROP_BASELINE procedure as shown in the following code. The cascade parameter specifies that only the baseline should be dropped, not the snap- shots associated with the baseline. SQL> BEGIN 2 DBMS_WORKLOAD_REPOSITORY.DROP_BASELINE( 3 baseline_name => ‘OCP Example’, 4 cascade => FALSE); 5 END; SQL> / PL/SQL procedure successfully completed. SQL> You can create a baseline for the future date and time. These are called baseline templates. The following code creates a baseline template: SQL> BEGIN 2 DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE_TEMPLATE( 3 start_time => TO_DATE(‘01-JAN-09 05.00.00’,’DD-MON-YY HH.MI.SS’), 4 end_time => TO_DATE(‘01-JAN-09 08.00.00’,’DD-MON-YY HH.MI.SS’), 5 baseline_name => ‘baseline_090101’, 6 template_name => ‘template_090101’, 7 expiration => 21); 8 END; SQL> / PL/SQL procedure successfully completed. SQL> AWR baselines and baseline templates are never dropped automatically (or purged) from the database unless explicitly dropped by the DBA or the expiration period ends. Managing AWR Baselines Using EM Database Control Using EM Database Control to create, rename, and drop AWR baselines is easier than using SQL*Plus and error-free. From the database home page, click the Server tab (shown 95127c14.indd 790 2/17/09 2:54:19 PM Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... Problem Count Active Incident Count VALUE TRUE c: \oracle c: \oracle\ diag\rdbms\w11gr1\w11gr1 c: \oracle\ diag\rdbms\w11gr1\w11gr1\trace c: \oracle\ diag\rdbms\w11gr1\w11gr1\alert c: \oracle\ diag\rdbms\w11gr1\w11gr1\incident c: \oracle\ diag\rdbms\w11gr1\w11gr1\cdump c: \oracle\ diag\rdbms\w11gr1\w11gr1\hm c:\…\w11gr1\trace\w11gr1_ora_6036.trc 0 0 The standard directory structure and diagnostic... the Database and Managing Performance n In Oracle 11g, an alert log file is written in XML format as well as in text format The XML-format file is under the alert directory, whereas the text-format file is under the trace directory Table 14.6 shows where to look for log and trace files in Oracle 11g Ta b l e   1 4 6  ​ Alert File and Trace File Locations  ​ Type of File Pre Oracle 11g Location Oracle. .. against these ADDM views only if EM Database Control were unavailable To gain further insight into the recommendations and information gathered by the ADDM, Oracle 11g also provides several advisor utilities in EM Database Control I will discuss these advisors in the next section The Advisory Framework Oracle 11g comes with several advisors to help proactively manage the database The top portion of Figure 14.22... time to recover, segments, and undo activity, an Oracle 11g database can also proactively monitor itself for other types of problems related to configuration, security, and space management To do so, you use the server-generated alerts feature A server-generated alert is an alert from the Oracle 11g database that says it suspects a problem with the database These alerts are also an integral part of... available in Oracle 11g that help you tune and gather system information When it comes to tuning, managing the instance memory is very important How much memory should you allocate for all the various SGA components? In the following sections, you will learn how Oracle 11g can help you take the guesswork out of database administration and tune the database Sources of Tuning Information EM Database Control... performance bottlenecks See Note 171647.1 at http://metalink .oracle. com for a discussion of using the 10046 trace event as a tuning technique Managing Performance  F i g u r e   1 4 2 7  ​ Top Sessions screen on EM  ​ Dynamic Performance Views As described in Chapter 8, “Introducing Oracle Database 11g Components and Architecture,” Oracle Database 11g contains several dynamic performance views Table 14.7... triggered when a specified event occurs, such as a database error Proactive Database Maintenance  803 Viewing and Configuring Alerts Using EM Database Control The EM Database Control home page displays the alerts when they are triggered Figure 14.23 shows the Alerts section of the Database Control home page F i g u r e   1 4 2 3  ​ Alerts section of the Database Control home page  ​ You can see the alert... Proactive Database Maintenance  795 The EM Database Control Performance Tab You can also click the Performance tab on the EM Database Control main screen to view performance data collected by AWR and analyzed by ADDM You can click the Run ADDM Now button to take an AWR snapshot and perform ADDM analysis Figure 14.20 shows the Performance tab of EM Database Control F i g u r e   1 4 2 0  ​ EM Database. .. bottom of the EM Database Control main screen You’ll see sample output from each of the EM Database Control screens in the following sections The EM Database Control Performance Findings Link The EM Database Control home screen contains a section called Diagnostic Summary One of the links under this section is ADDM Findings Figure 14.18 shows this section 794  Chapter 14    Maintaining the Database and... compressing these segments, space is returned to the database for use by other objects, and the total number of I/Os needed to access these objects is reduced, potentially improving the performance of SQL statements that access these objects In the next section, you’ll learn about another tool in the Oracle 11g database that helps you proactively monitor the database with timely alerts Monitoring Server-Generated . Maintenance Tasks and Oracle Scheduler, read the Oracle Database Administrator s Guide 11g Release 1 (11.1) Part Number B28310-04” Oracle documentation watermark. 784 Chapter 14 N Maintaining the Database and Managing Performance Gathering Performance Statistics Oracle Database generates several performance

Ngày đăng: 24/12/2013, 02:17

TỪ KHÓA LIÊN QUAN