Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Oracle Database 11g.pdf
Скачиваний:
77
Добавлен:
10.06.2015
Размер:
12.69 Mб
Скачать

Managing Memory 

457

Managing Memory

In the following sections, we will first cover Automatic Memory Management, new to Oracle 11g, which allows the DBA to set one initialization parameter and then leave the memory management up to the Oracle instance. Our next topic for memory management is manually configuring System Global Area (SGA) parameters. DBAs who need more granular control over the SGA pools will find this discussion useful. We will then discuss configuring automatic Program Global Area (PGA) memory management.

Implementing Automatic Memory Management

In Oracle 11g, the DBA has the opportunity to set one initialization parameter and allow Oracle to manage the size of the SGA and instance PGA automatically. When you set the value of MEMORY_TARGET, Oracle will automatically resize the SGA and PGA components dynamically based on processing demands for optimal database performance. The instance will automatically deallocate and allocate memory between the SGA and instance PGA as needed. Automatic Memory Management, when enabled, automatically adjusts the cache and pool sizes as needed to keep the database performing optimally.

Automatic Memory Management is supported on Linux, Solaris, Windows, HP-UX, and AIX.

When you create a new database in Oracle 11g, the default is to use Automatic Memory Management. You can adjust individual SGA component minimum values to ensure that minimum performance thresholds are not compromised. However, the instance monitors the performance of each memory component and adjusts as necessary as workloads change to provide optimal performance.

Automatic Memory Management Options

To enable Automatic Memory Management for the instance, set the value of MEMORY_TARGET in the spfile. Also, MEMORY_MAX_TARGET sets the upper bound for MEMORY_TARGET. You can adjust MEMORY_TARGET dynamically up to the value of MEMORY_MAX_TARGET; however, MEMORY_ MAX_TARGET is not a dynamic initialization parameter and will require an instance restart for a modification to take effect.

NAME

TYPE

VALUE

------------------------------------

-----------

------

 

 

memory_max_target

big integer

1000M

memory_target

big integer

816M

 

 

SQL>

 

 

458  Chapter 11  n  Managing Database Resources

If you don’t set MEMORY_MAX_TARGET, it will default to the value of MEMORY_TARGET. By setting these values, you have set the maximum memory size that will be used by Oracle to manage all instance PGA and SGA objects.

If you would like more granular control over the SGA or instance PGA, Oracle will allow you to manage them manually with the Automatic Shared Memory Management, Manual Shared Memory Management, Automatic PGA Memory Management, or Manual PGA Memory Management option.

Oracle strongly recommends that you enable Automatic Memory Management and let the Oracle instance manage the memory components on your system. If you choose not to use Automatic Memory Management, use the Memory Advisor in Enterprise Manager to assist you with your instance memory configuration.

Automatic Shared Memory Management

To exercise control over the SGA, you’ll need to disable Automatic Memory Management and enable Automatic Shared Memory Management for the SGA by setting MEMORY_TARGET to zero and setting the values for SGA_MAX_SIZE and SGA_TARGET. You will also need to verify that the value of STATISTICS_LEVEL is set to TYPICAL or ALL. These parameters are dynamic, with the exception of SGA_MAX_SIZE, which requires an instance restart to take effect.

NAME

TYPE

VALUE

------------------------------------

-----------

-----

lock_sga

boolean

FALSE

 

 

sga_max_size

big integer

600M

sga_target

big integer

0

SQL>

 

 

Now that you have set the values for SGA_TARGET and SGA_MAX_SIZE, Oracle will manage the individual components of the SGA for optimal performance up to the SGA_TARGET value. You can dynamically increase the size of the SGA up to the value of SGA_MAX_SIZE, and Oracle will resize the pools as needed to take advantage of the additional memory.

When setting the value for SGA_TARGET, you’ll need to consider the combined sizes of the different SGA memory pools:

NN

Default pool of database buffer cache DB_CACHE_SIZE

 

NN

Shared pool SHARED_POOL_SIZE

NN

Large pool LARGE_POOL_SIZE

NN

Java pool JAVA_POOL_SIZE

 

NN

Streams pool STREAMS_POOL_SIZE

Managing Memory 

459

You can set the value for each of the associated initialization parameters to a nonzero value, and that value will indicate the minimum size for each pool. If you dynamically set SGA_TARGET to zero, you will disable Automatic Shared Memory Management and the current sizes of the pools will not change dynamically. You can manually change the sizes of the pools as needed by using the ALTER SYSTEM command.

The following pools are not impacted by Automatic Shared Memory Management; they are manually sized:

NN KEEP, RECYCLE, and non-default block-size buffer cache pools

NN

Fixed SGA and other internal memory structures

NN

Log buffer

 

The values of these manually configured pools are subtracted from the value of SGA_TARGET.

When you disable Automatic Memory Management and enable Automatic Shared Memory Management, you also enable Automatic PGA Memory Management. We’ll discuss Automatic PGA Memory Management later in this chapter.

Automatic Memory Management and Enterprise Manager

To use Enterprise Manager to configure and manage the Automatic Memory Management features, access the Memory Advisors page from the Advisor Central home page. You’ll see the following information, also displayed in Figure 11.1:

NNWhether Automatic Memory Management is enabled and the ability to toggle between enabled and disabled

NN

The current total and maximum memory size and advice

NN

Memory allocation history

 

 

NN

Tabs for SGA and PGA memory configuration details

F i g u r e 11.1   ​  Memory​

Advisors page

460  Chapter 11  n  Managing Database Resources

In Figure 11.2, we show the default lower half of the page displayed in Figure 11.1. This half of the page displays the detailed SGA configuration, which includes the SGA allocation history chart, the current SGA component MB allocated, and a pie chart showing the current SGA pool percentages:

NN

Shared pool

 

NN

Buffer cache

NN

Large pool

NN

Java pool

 

NN

Other

F i g u r e 11. 2   ​  Memory​ Advisor SGA detail

In Figure 11.3, we show the PGA details, which are viewed by clicking the PGA tab of the Memory Advisors page. Shown are the aggregate PGA target, current PGA allocated, maximum PGA allocated, and the cache hit percentage.

You can click the PGA Memory Usage Details button to see the current work area size executions, as shown in Figure 11.4. The chart shows the following:

NN

Optimal executions

 

NN

One-pass executions

 

NN

Multipass executions

Managing Memory 

461

On this page you have the options to change the chart view to see execution percentages and number of executions and also show memory-usage details for the PGA target that you choose from the drop-down list.

F i g u r e 11. 3   ​  Memory​ Advisor PGA detail

F i gu r e 11. 4   ​  PGA​ work area size detail

Disabling Automatic Memory Management Using Enterprise Manager

From the Memory Advisors page, you can disable Automatic Memory Management by clicking the Disable button. The change takes effect immediately. You can revert to

462  Chapter 11  n  Managing Database Resources

Automatic Memory Management by clicking the Enable button. We’ll discuss enabling in a later section titled “Enabling Automatic Memory Management Using Enterprise Manager.” When you disable Automatic Memory Management, the Memory Advisors page changes

to reflect that Automatic Memory Management is disabled, as shown in Figure 11.5. Now you have an SGA tab that gives you the ability to enable or disable Automatic Shared Memory Management as well as request advice (see Figure 11.6) and modify the total and maximum SGA sizes.

F i g u r e 11. 5   ​  Automatic​ Memory Management SGA configuration

If you click the PGA tab, you’ll see (Figure 11.7) that you can now request advice, as shown in Figure 11.8, and modify the aggregate PGA target based on the recommendations.

Managing Memory 

463

F i g u r e 11.6   ​  Automatic​ Memory Management SGA size advice

F i gu r e 11.7   ​  Automatic​ Memory Management PGA configuration

464  Chapter 11  n  Managing Database Resources

F i g u r e 11. 8   ​  Automatic​ Memory Management PGA size advice

Disabling Automatic Shared Memory Management Using Enterprise Manager

If you now want to disable Automatic Shared Memory Management and manually set the values for the various SGA pools, you can do so by clicking the Disable button in the Current Allocation section on the SGA tab. This action opens the Disable Automatic Shared Memory Management page, shown in Figure 11.9, where you can manually set the values for each component. You may revert to Automatic Shared Memory Management by canceling from this page, or click OK to continue and begin manually managing the SGA.

F i gu r e 11. 9   ​  Manually​ configuring the SGA

Managing Memory 

465

If you disable Automatic Shared Memory Management, you will manually configure and manage each of the SGA pools. We’ll discuss manual SGA memory management later in this chapter, in the section titled “Manually Configuring SGA Parameters.”

Enabling Automatic Shared Memory Management Using Enterprise Manager

Stepping back from full manual configuration of the SGA to Automatic Shared Memory Management is straightforward; simply click the Enable button presented next to the Automatic Shared Memory Management Disabled header in the SGA section of the Memory Advisors page, as shown in Figure 11.10.

F i g u r e 11.10   ​  Enabling​ Automatic Shared Memory Management

Enabling Automatic Memory Management Using Enterprise Manager

You can also go directly from manual SGA management to Automatic Memory Management by clicking the Enable button next to the Automatic Memory Management Disabled line directly under the Memory Advisors header on the Memory Advisors page (shown earlier, in Figure 11.10).

If you are currently running the instance in Automatic Shared Memory Management mode and want to enable Automatic Memory Management, click the Enable button, shown in Figure 11.11.

466  Chapter 11  n  Managing Database Resources

You’ll have the opportunity to modify the maximum memory size and the total size of automatic shared memory, as shown in Figure 11.12.

Figure 11.13 shows confirmation that the instance is now running in Automatic Memory Management mode.

F i g u r e 11.11   ​  Enabling​ Shared Memory Management

F i gu r e 11.12   ​  Configuring​ Automatic Memory Management

Managing Memory 

467

F i g u r e 11.13   ​  Automatic​ Memory Management enabled

Manually Configuring SGA Parameters

If you don’t want to let the Oracle instance manage the SGA memory allocations for you and you want greater control over the individual pools, Oracle provides the option for you to bypass both Automatic Memory Management and Automatic Shared Memory Management. By setting MEMORY_TARGET and SGA_TARGET initialization parameters to zero, you in effect force the manual configuration of each of the SGA memory pools and enable manual shared memory management.

While Oracle strongly recommends that you allow the instance to manage memory automatically, Oracle also understands that the DBA in some cases needs to manually configure specific pools based on specific knowledge of the application workload.

So when manually setting the SGA components, you’ll need to plan and verify that each pool is given sufficient memory to meet performance requirements. As shown previously, in Figure 11.9, you can specify values for the following SGA components:

NN

Default pool of database buffer cache DB_CACHE_SIZE

NN

Shared pool SHARED_POOL_SIZE

NN

Large pool LARGE_POOL_SIZE

NN

Java pool JAVA_POOL_SIZE

Additionally, you’ll need to set the value of SGA_MAX_SIZE to a value that represents the maximum amount of memory you would use for the SGA.

If you choose to manually configure the SGA components using Enterprise Manager after you have been running with Automatic Shared Memory Management, the SGA components

468  Chapter 11  n  Managing Database Resources

are sized based on the current Memory Advisors advice. Additionally, you may seek advice after you have manually set the values, as shown earlier, in Figure 11.10. Figure 11.14 shows the advice for the shared pool, launched by clicking the Advice button next to the Shared Pool line on the Memory Advisors page.

Figure 11.15 shows the same exercise for the default database buffer pool, also known as the buffer cache.

F i g u r e 11.14   ​  Shared​ pool size advice

F i gu r e 11.15   ​  Buffer​ cache size advice

Managing Memory 

469

If you attempt to manually size the SGA pools to a total SGA size greater than or equal to the value for Maximum SGA Size (SGA_MAX _SIZE), you will receive the messages “ORA-02097: Parameter cannot be modified because specified value is invalid” and “ORA-04033: Insufficient memory to grow pool.” If you attempt to grow the buffer cache too large, you will receive the ORA-02097 error and the message “ORA-00384: Insufficient memory to grow cache.” In either case, you will not be able to make the total size of the SGA greater than or equal to the Maximum SGA Size value. See Figure 11.16.

F i g u r e 11.16   ​  Attempting​ to manually resize beyond the maximum SGA size

Also note in Figure 11.16 that you can change the Maximum SGA Size value, SGA_ MAX_SIZE, but this will require a database-instance restart to take effect. Also on this screen you have the option to apply changes to the spfile only. If you do so, you will receive an update message indicating that changes were made to the spfile, as shown in Figure 11.17.

470  Chapter 11  n  Managing Database Resources

F i g u r e 11.17   ​  Save​ SGA size changes to the spfile

Configuring Automatic PGA Memory Management

Remember that when you configure the database instance for Automatic Memory Management, PGA memory is automatically allocated and deallocated from MEMORY_TARGET as needed. If you determine that you need greater control over the PGA, then you can go to Automatic Shared Memory Management or manual shared memory management, thereby being forced to choose between automatic or manual PGA memory management. In Automatic PGA Memory Management, you set the value of PGA_AGGREGATE_TARGET and the Oracle instance manages memory allocation to work areas as needed. If you choose manual PGA memory management, you will need to configure each of the work areas manually, which requires you to keep up with workload changes and modify the work areas accordingly.

If you choose to not utilize Automatic Memory Management for the instance, Oracle strongly recommends that you enable Automatic PGA Memory Management and let the Oracle instance manage the PGA components on your system. If you choose not to use Automatic PGA Memory Management, use the Memory Advisor in Enterprise Manager to assist you with your instance PGA memory configuration.

Managing Memory 

471

Automatic PGA Memory Management

In the following sections, we’ll discuss how to enable Automatic PGA Memory Management in Enterprise Manager, how to monitor Automatic PGA Memory Management, and how you can tune Automatic PGA Memory Management. We will also discuss how you can disable Automatic PGA Memory Management and tune the individual work areas manually.

Enabling Automatic PGA Memory Management Using Enterprise Manager

If you’re currently running your instance in Automatic or manual Shared Memory Management mode, then you are by default running Automatic PGA Memory Management. You can verify that the instance is in Automatic PGA Memory Management mode, and not manual mode, by viewing the PGA tab in the Memory Advisors page, as shown in Figure 11.18. On this page you can change the value of the PGA aggregate target based on the recommendations received when you click the Advice button.

F i g u r e 11.18   ​  Automatic​ PGA Memory Management

The minimum value for PGA_AGGREGATE_TARGET is 10MB, and the maximum value is 256GB.

If your database instance was running in Automatic Memory Management mode and you converted to Automatic Shared Memory Management mode, then the PGA_AGGREGATE_ TARGET was set at the value determined by the instance when it was running in Automatic Memory Management mode.

For an online transaction processing (OLTP) system, a good starting point for the PGA size, the value of the PGA_AGGREGATE_TARGET, should be approximately 20 percent of the memory available on the system; conversely, the value of the SGA should be about 80 percent of

472  Chapter 11  n  Managing Database Resources

the available memory. For a decision support system, data warehouse, or analytical database, a good starting point is 50 percent of available memory for PGA and 50 percent for SGA. Of course, you will need to tune the PGA_AGGREGATE_TARGET value based on advice from the Memory Advisors page or by querying dynamic views. Also note that if you run multiple instances on the same server, it is easy to overallocate the SGA and PGA so that the combined memory used by all the instances is larger than real memory on the server, which can lead

to memory paging and significant performance degradation.

Monitoring Automatic PGA Memory Management

You can monitor the PGA performance using several dynamic performance views:

NN V$PGASTAT

NN V$PROCESS

NN V$PROCESS_MEMORY

NN V$SQL_WORKAREA_ACTIVE

NN V$SQL_WORKAREA

NN V$SQL_WORKAREA_HISTOGRAM

A key statistic to look for in the V$PGASTAT view is the overallocation count, which tells you the cumulative number of times you have overallocated the PGA since instance startup; a large number indicates that the PGA_AGGREGATE_TARGET may be too small.

The V$PROCESS view has one row for each Oracle process for this instance. You can monitor PGA usage by observing the columns that start with PGA_*.

The V$PROCESS_MEMORY view goes into greater detail for each process, showing PGA memory used for these six categories: PL/SQL, SQL, Java, OLAP, Freeable, and “other.” V$SQL_WORKAREA_ACTIVE shows currently active work areas in the instance, excluding sorts that are less than 64KB. When a SQL operation is complete, the work area is deallocated from V$SQL_WORKAREA_ACTIVE and the V$SQL_WORKAREA view is updated to include the

cumulative execution statistics for each work area.

The V$SQL_WORKAREA_HISTOGRAM view shows the cumulative statistics for the number of work areas executed since instance startup for optimal, one-pass, and multipass memory sizes. The columns for low and high optimal size bytes represent the work-area size buckets that were used. Your expectation should be to run as many work areas as possible in the

OPTIMAL_EXECUTIONS column.

Tuning Automatic PGA Memory Management

The PGA advice performance views are available to help you tune the value of PGA_ AGGREGATE_TARGET. The dynamic views V$PGA_TARGET_ADVICE and V$PGA_TARGET_ ADVICE_HISTOGRAM are supplied to help you tune Automatic PGA Memory Management.

Set the value of STATISTICS_LEVEL to TYPICAL or ALL and set the value of PGA_AGGREGATE_ TARGET to between 10MB and 256GB to enable the automatic generation of PGA advice statistics and population of the advice views.

The V$PGA_TARGET_ADVICE view shows the predicted cache hit-ratio improvement as you increase the size of the PGA_AGGREGATE_TARGET. In this case, the small workload

Managing Memory 

473

indicates you could reduce the size of the 200MB PGA_AGGREGATE_TARGET and still have a good PGA hit ratio.

SQL> SELECT PGA_TARGET_FOR_ESTIMATE/1024/1024 “target mb”, 2 ESTD_PGA_CACHE_HIT_PERCENTAGE “cache_hit%“

3 FROM V$PGA_TARGET_ADVICE

4/

target mb cache_hit%

---------- ----------

25

99

50

99

100

100

150

100

200

100

240

100

280

100

320

100

360

100

400

100

600

100

800

100

1200

100

1600

100

14 rows selected. SQL>

Similarly, the V$PGA_TARGET_ADVICE_HISTOGRAM view forecasts how the V$SQL_WORKAREA_ HISTOGRAM will change if you modify the value of PGA_AGGREGATE_TARGET. It shows the predicted number of executions in each of the optimal, one-pass, and multipass work areas for each setting of PGA_AGGREGATE_TARGET.

Disabling Automatic PGA Memory Management Using Enterprise Manager

If you want to manually control the sizes of the individual work areas, going against the strong recommendation from Oracle, you will need to set the value of PGA_AGGREGATE_TARGET to zero and set the following parameters to a positive value:

NN SORT_AREA_SIZE

NN HASH_AREA_SIZE

NN BITMAP_MERGE_AREA_SIZE

NN CREATE_BITMAP_AREA_SIZE

Then restart the instance and enjoy tuning the work areas manually.

474  Chapter 11  n  Managing Database Resources

If you’re using OEM, set the PGA Aggregate Target value to zero and choose to make the changes to the spfile, as shown in Figure 11.19.

Once you’ve stopped and started the instance and returned to the PGA tab of the OEM Memory Advisor, you’ll notice that the page has changed from the view in Figure 11.18 to what you see in Figure 11.20.

F i g u r e 11.19   ​  Disabling​ Automatic PGA Memory Management

F i gu r e 11. 20   ​  Manual​ PGA Memory Management

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]