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

OCA /OCP Oracle Database 11g A ll-in-One Exam Guide- P91 ppsx

10 177 0

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 373,27 KB

Nội dung

OCA/OCP Oracle Database 11g All-in-One Exam Guide 856 avoids these problems. It can be run without any impact on end users. A limitation is that the table’s tablespace must have been created to use automatic segment space management. Tables in tablespaces that use the older freelist technique for managing segment space usage cannot be shrunk, because (unlike the new bitmap method) the freelist does not include sufficient information for Oracle to work out how full each block actually is. The syntax of SHRINK is alter <table_name> shrink space [ cascade ] [ compact ] ; The underlying implementation of a table shrink is to relocate rows from the end of the table into blocks toward the beginning of the table, by means of matched INSERT and DELETE operations. Then when all possible moves have been done, to bring the high water mark of the table down to the last currently used block, release all the space above this point. There are two distinct phases: the compact phase moves the rows in a series of small transactions, through normal DML that generates both undo and redo and uses row locks. The second phase is a DDL command. As with any DDL command, this is a transaction against the data dictionary: it will execute almost instantaneously, but will require a very short table lock. EXAM TIP A table shrink operation generates undo and redo. Indexes are maintained, because the shrink is implemented as a set of DML transactions. There is no table lock during the compaction, but individual rows will be locked while they are being moved. Using the keyword COMPACT carries out the first phase, but not the second: the rows are relocated, but the space is not actually released from the segment. The reason for using this is that while the compaction can occur during normal running hours (though it may take many hours to complete on a large table), it is possible that the DDL at the end will hang due to concurrency with other transactions. So it may be necessary to shrink the table with the COMPACT keyword first, and then again without COMPACT during a maintenance period: it will be fast, because the compaction will have already been done. EXAM TIP The SHRINK SPACE COMPACT command reorganizes the contents of the segment, but does not return space to the tablespace. The CASCADE keyword instructs Oracle also to shrink dependent objects, such as indexes. Indexes do deteriorate as DML is executed: if a row is deleted, this will result in wasted space in the index. Oracle’s index maintenance algorithm does not permit reuse of this space. It is logically impossible to reclaim this space by relocating other index keys because the index keys must always be stored in order. The best that can be done is to merge adjacent, partially used, leaf blocks of the index. If such a merge results in one completely empty block, then this block can be reused within the index. You can also shrink an index directly: Chapter 23: Moving and Reorganizing Data 857 PART III alter index <index_name> shrink space [ cascade ] [ compact ] ; However, while this works syntactically, shrinking an index will not actually reduce its size. It may, however, stop it from getting bigger. TIP Older DBAs will recognize that ALTER INDEX SHRINK SPACE is functionally equivalent to the ALTER INDEX COALESCE command. The latter command is still available, but may be deprecated in later releases. Before a table can be shrunk, you must enable row movement for the table: alter table <table_name> enable row movement; Enabling row movement is necessary because the nature of the operation means that rowids will be changing. The same row (no change to primary key) will be in a different physical location, and therefore have a different rowid. This is something that Oracle will not permit unless row movement has been enabled. EXAM TIP A table must be in a tablespace with automatic segment space management and row movement must have been enabled, or it cannot be shrunk. If these conditions have not been met, a MOVE may be the only way to reorganize the table. To identify whether a table would benefit from a shrink space operation, you can analyze the table and then query the DBA_TABLES view to retrieve the amount of free space, on average, in each block. This query computes the ratio of free space as a proportion of the block size. select avg_space/(select value from v$parameter where name='db_block_size') from user_tables where table_name = '<table_name>'; However, as there may be thousands of tables in the database and some may undergo very different patterns of activity, this information may not be sufficient to work out whether a shrink is necessary. For this reason, there is a supplied advisor: the Segment Advisor. The Segment Advisor inspects tables to detect “wasted” space but then makes use of information in the Automatic Workload Repository to make a decision on whether the space should be released by a reorganization, or if the historical pattern of activity against the table suggests that the space may be required again and should not therefore be released. The Segment Advisor runs, be default, every night. Figure 23-5 shows the results of an automatic run of the Segment Advisor, viewed in Database Control. In Figure 23-5, the Segment Advisor has detected a table (which happens to be in the SYSMAN schema) that would benefit from a reorganization. This advice will be based on the current state of the table (it is six times as large as it needs to be) with previous activity taken into account. Clicking the SHRINK button will take you to the OCA/OCP Oracle Database 11g All-in-One Exam Guide 858 window shown in Figure 23-6, where the wizard gives you the options of performing a complete shrink operation (the Compact Segments and Release Space radio button) or stopping after the compaction phase (the Compact Segments radio button). The wizard also generates statements to enable row movement on the table(s). Note that it is not possible to shrink a table that has a column of type LONG. It is possible to shrink a table on which materialized views have been created (and if CASCADE is specified, the materialized views will be shrunk too) unless the materialized view is a refresh on commit materialized view. This restriction is because even though table shrink is implemented internally as a set of INSERT and DELETE commands, any DML triggers will be automatically disabled for the shrink operation. On-commit materialized views are in fact maintained by triggers and so would be broken by a shrink operation. EXAM TIP You cannot shrink a table that is in a freelist-managed tablespace, that has a LONG column, or has a refresh-on-commit materialized view. Figure 23-5 The Segment Advisor’s recommendation in Database Control Chapter 23: Moving and Reorganizing Data 859 PART III Two-Minute Drill Describe and Use Methods to Move Data (Directory Objects, SQL*Loader, External Tables) • An Oracle directory is a database object that points to a physical path. • Directories are not schema objects: no matter who creates them, they are owned by SYS. • SQL*Loader is a client-server tool that connects over a normal session, and reads a text file to construct rows for insertion into tables. • SQL*Loader can insert rows using normal INSERT statements, or can write blocks directly to datafiles. During a direct load, the table will be locked for DML. • An external table exists as a data dictionary construct that points to an operating system file, in a directory. • External tables can be read with SELECT but cannot be written to with DML commands. Figure 23-6 The Database Control interface to the shrink facility OCA/OCP Oracle Database 11g All-in-One Exam Guide 860 Explain the General Architecture of Oracle Data Pump • The expdp and impdp utilities are client-server tools that use database sessions, but the Data Pump processes are server background processes. • Data Pump will always use the direct path (bypassing the SGA) to read and write tables, unless the object is sufficiently complex that the conventional path is necessary. • Data Pump can create dump files, log files, and SQL files. Use Data Pump Export and Import to Move Data Between Oracle Databases • The directory that Data Pump will use can be specified when defining the Data Pump job or by the DATA_PUMP_DIR environment variable. If neither of these is done, it will default to the location specified by the DATA_PUMP_ DIR initialization parameter. • A Data Pump import can read only dump files created with a Data Pump export; Data Pump can read and write no other formats. • A Data Pump dump file can be generated on one platform and imported into a database on another platform. Describe the Concepts of Transportable Tablespaces and Databases • Tablespace datafiles can be transported across platforms, but the databases must use the same character set. If the platforms are different endian, the datafiles must be converted with RMAN. • A tablespace must be made read only before transport. • Data Pump is used to export and import the metadata describing the contents of a tablespace transport set. • A tablespace transport set must be self-contained: it cannot contain objects with dependencies on objects that are not in the set. • Transporting an entire database involves creating a new controlfile with CREATE CONTROLFILE, new online redo log files with RESETLOGS, and transporting in the entire set of tablespaces. Manage Resumable Space Allocation • Resumable space allocation can be enabled for a session with ALTER SESSION ENABLE RESUMABLE or for all sessions with the RESUMABLE_TIMEOUT instance parameter. Chapter 23: Moving and Reorganizing Data 861 PART III • While a session is suspended, it will retain all resources taken, including row locks, undo space, temporary space, and PGA memory. • Suspended sessions are visible in DBA_RESUMABLE and reported by Database Control. • When a space error condition is cleared, the suspended session will resume work with no need for manual intervention. Reclaim Wasted Space from Tables and Indexes by Using the Segment Shrink Functionality • A table shrink is implemented as matched deletions and insertions, to move rows from the end of the table segment toward the beginning. • DML locks are needed during a shrink, but a DDL lock is only needed for the final, very fast, step of moving the high water mark to release the freed space. • The COMPACT keyword will move the rows, but not complete the operation by returning space to the tablespace. • Only heap tables can be shrunk. This includes regular tables, and other objects that use heap tables for storage such as materialized views, materialized view logs, and partitions of heap tables. • It is possible syntactically to shrink an index, but the implementation is a coalesce of free space that may be reused by the index. No space will be returned to the tablespace. Self Test 1. You are using Data Pump to upload rows into a table, and you wish to use the direct path. Which of the following statements are correct? (Choose two answers.) A. You must include the “DIRECT” keyword in the Data Pump controlfile. B. This is not possible if the table is in a cluster. C. You have no control over this; Data Pump will use the direct path automatically if it can. D. Direct path is slower than the external table path because it doesn’t cache data in memory. 2. Which of the following is not a Data Pump file type? (Choose the best answer.) A. Dump file B. Log file C. Controlfile D. SQL file OCA/OCP Oracle Database 11g All-in-One Exam Guide 862 3. Which of the following is not a SQL*Loader file? (Choose the best answer.) A. Bad file B. Controlfile C. Discard file D. Good file E. Log file 4. You create a directory with the statement create directory dp_dir as 'c:\tmp'; but when you try to use it with Data Pump, there is an error. Which of the following could be true? (Choose three answers.) A. The Oracle software owner has no permissions on c:\tmp. B. The Oracle database user has no permissions on dp_dir. C. The path c:\tmp does not exist. D. The path c:\tmp must exist, or the “create directory” statement would have failed. E. If you use Data Pump in network mode, then there will be no need for a directory. F. Issuing the command grant all on 'c:\tmp' to public; may solve some permission problems. 5. You run SQL*Loader on your PC, to insert data into a remote database. Which of the following is true? (Choose the correct answer.) A. The input datafiles must be on your PC. B. The input datafiles must be on the server. C. Direct load is possible only if the input datafiles are on the server. D. Direct load is only possible if you run SQL*Loader on the server, not on the PC. 6. How can you enable the suspension and resumption of statements that hit space errors? (Choose all the correct answers.) A. Issue an ALTER SESSION ENABLE RESUMABLE command. B. Issue an ALTER SYSTEM ENABLE RESUMABLE command. C. Set the instance parameter RESUMABLE_STATEMENTS. D. Set the instance parameter RESUMABLE_TIMEOUT. E. Use the DBMS_RESUMABLE.ENABLE procedure. 7. If a statement is suspended because of a space error, what will happen when the problem is fixed? (Choose the best answer.) A. After the resumable timeout has expired, the statement will continue executing from the point it had reached. Chapter 23: Moving and Reorganizing Data 863 PART III B. After the resumable timeout has expired, the statement will start executing from the beginning again. C. The statement will start executing from the beginning immediately after the problem is fixed. D. The statement will continue executing from the point it had reached immediately after the problem is fixed. 8. You receive an alert warning you that a tablespace is nearly full. What actions could you take to prevent this becoming a problem, without any impact for your users? (Choose two correct answers.) A. Purge all recycle bin objects in the tablespace. B. Shrink the tables in the tablespace. C. Shrink the indexes in the tablespace. D. Move one or more tables to a different tablespace. E. Move one or more indexes to a different tablespace. 9. Which process is responsible for sending the alert when a tablespace usage critical threshold is reached? (Choose the best answer.) A. Database Control B. The DBMS_SERVER_ALERT package C. MMON, the manageability monitor process D. The server process of the session that detected the problem E. DBWn, the Database Writer, when it detects the problem 10. What must you do before executing a table shrink operation? (Choose the best answer.) A. Compact the table. B. Disable triggers on the table. C. Disable row movement for the table. D. Enable row movement for the table. Self Test Answers 1. þ B and C. Clusters are complex structures that cannot be directly loaded. Data Pump determines whether a direct load is possible automatically. ý A and D. There is no DIRECT keyword because the choice is automatic. Direct is faster because it bypasses the SGA. 2. þ C. SQL*Loader can use a controlfile, Data Pump does not. ý A, B, and D. These are the file types that Data Pump can generate. 3. þ D. There is no “good” file—the acceptable rows are inserted. ý A, B, C, and E. These are the file types that SQL*Loader can generate. OCA/OCP Oracle Database 11g All-in-One Exam Guide 864 4. þ A, B, and C. These conditions could all cause problems when using the directory, but not when creating it. ý D, E, and F. D is wrong because the existence of the directory is not checked at creation time. E is wrong because while network mode does not need a directory for the dump file(s) it will need a directory for the log file(s). F is wrong because it confuses the issue of Oracle permissions on directories with operating system permissions on physical paths. 5. þ A. SQL*Loader is a client-server process: the input files must be local to the user process. ý B, C, and D. B is wrong because the input files must be on the PC, accessible to the client-side process. C and D are wrong because direct load is not relevant to the location of the files. 6. þ A and D. These are the only two methods to enable resumable space allocation. ý B, C, and E. B and C are wrong because resumable space allocation is enabled at the system level with the instance parameter RESUMABLE_TIMEOUT. E is wrong because while there is a package DBMS_RESUMABLE, it does not (rather annoyingly) include a procedure to enable resumable space allocation. 7. þ D. As “suspended” implies, the statement will continue from the point at which it stopped. ý A, B, and C. The timeout controls how long the suspension can last before returning an error: it is the period during which the problem can be fixed. 8. þ A and B. Both purging dropped objects and shrinking tables will release space immediately, with no downtime. ý C, D, and E. An index can be shrunk, but this will release space within the index, not return it to the tablespace. Relocating either indexes or tables has implications for availability of the data. 9. þ C. The MMON background process raises alerts. ý A, B, D, and E. A is wrong because while Database Control reports alerts, it does not raise them. B is wrong because the DBMS_SERVER_ALERT API is used to configure the alert system; it does not implement it. D and E are wrong because foreground and background processes will encounter problems, not warn of their imminence. 10. þ D. Row movement is a prerequisite for a table shrink operation. ý A, B, and C. A is wrong because compaction is part of the shrink, not a prerequisite. B is wrong because there is no need to disable triggers—they will be disabled automatically. C is wrong because row movement must be enabled, not disabled. CHAPTER 24 The AWR and the Alert System Exam Objectives In this chapter you will learn to • 052.12.2 Use and Manage Automatic Workload Repository (AWR) • 052.12.3 Use Advisory Framework • 052.12.4 Manage Alerts and Thresholds 865 . OCA/ OCP Oracle Database 11g All-in-One Exam Guide 856 avoids these problems. It can be run without any impact on end users. A limitation is that the table’s tablespace must have been created. External tables can be read with SELECT but cannot be written to with DML commands. Figure 23-6 The Database Control interface to the shrink facility OCA/ OCP Oracle Database 11g All-in-One Exam. on another platform. Describe the Concepts of Transportable Tablespaces and Databases • Tablespace datafiles can be transported across platforms, but the databases must use the same character

Ngày đăng: 06/07/2014, 13:20

TỪ KHÓA LIÊN QUAN

w