Oracle database 12c performance tuning recipes

621 177 0
Oracle database 12c performance tuning recipes

Đ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

www.it-ebooks.info For your convenience Apress has placed some of the front matter material after the index Please use the Bookmarks and Contents at a Glance links to access them www.it-ebooks.info Contents at a Glance About the Authors�������������������������������������������������������������������������������������������������������������� xlv About the Technical Reviewers��������������������������������������������������������������������������������������� xlvii Acknowledgments������������������������������������������������������������������������������������������������������������ xlix Introduction��������������������������������������������������������������������������������������������������������������������������li ■■Chapter 1: Optimizing Table Performance�������������������������������������������������������������������������1 ■■Chapter 2: Choosing and Optimizing Indexes������������������������������������������������������������������51 ■■Chapter 3: Optimizing Instance Memory�������������������������������������������������������������������������95 ■■Chapter 4: Monitoring System Performance�����������������������������������������������������������������125 ■■Chapter 5: Minimizing System Contention��������������������������������������������������������������������157 ■■Chapter 6: Analyzing Operating System Performance��������������������������������������������������193 ■■Chapter 7: Troubleshooting the Database����������������������������������������������������������������������217 ■■Chapter 8: Creating Efficient SQL����������������������������������������������������������������������������������259 ■■Chapter 9: Manually Tuning SQL������������������������������������������������������������������������������������307 ■■Chapter 10: Tracing SQL Execution��������������������������������������������������������������������������������335 ■■Chapter 11: Automated SQL Tuning�������������������������������������������������������������������������������375 ■■Chapter 12: Execution Plan Optimization and Consistency�������������������������������������������415 ■■Chapter 13: Configuring the Optimizer��������������������������������������������������������������������������457 ■■Chapter 14: Implementing Query Hints�������������������������������������������������������������������������501 ■■Chapter 15: Executing SQL in Parallel���������������������������������������������������������������������������537 Index���������������������������������������������������������������������������������������������������������������������������������569 v www.it-ebooks.info Introduction Oracle Database 12c Performance Tuning Recipes is a book of solutions—a crib sheet of sorts Database performance problems often rear themselves suddenly, and with that suddenness comes great pressure from management and users to somehow work magic and get response time back under control Everyone is in a panic Everyone is upset (except idealy you!) Such is no time for a leisurely read of a book This book is written with that pressure in mind It is chock-full of prewritten queries and other solutions that you can immediately apply and get results Of course, you should not wait until the last minute Take the time now when you’re not in crisis mode to get familiar with the content in this book Try the solutions for monitoring and analyzing See what you can learn about your current database performance levels Then take action to set some benchmarks and work on improvements so as to become practiced for when a crisis eventually hits Or better yet, maybe you can avoid a crisis altogether Who This Book Is For Oracle Database 12c Performance Tuning Recipes was written primarily for database administrators who manage Oracle Database environments The book is especially useful to those administrators involved in tackling performance optimization problems Serious SQL developers will also find the book useful, especially the chapters on aspects of SQL How This Book Is Structured Solutions in this book are grouped into categories by chapter Each chapter is composed of a number of recipes relating to the chapter’s topic Each recipe takes the following form: Problem: A succinct description of the problem solved by the recipe Solution: A terse and to-the-point presentation of queries and commands to execute in order to accomplish the task described in the recipe’s problem statement How It Works: A longer discourse on the solution and how and why it works, for those who are interested in a deeper understanding of the material The book’s structure allows you to open it to a chapter relating to a problem you are trying to solve Then find a recipe in the chapter that solves the problem or that can be adapted to solve the problem Read the solution Read the “How It Works” description to fully understand the solution Then apply the solution to your real-world problem Downloading the Code The authors have made a zip file available with the queries and scripts from the recipe solutions To download the zip file, first visit the book’s catalog page on the Apress.com web site The URL is as follows: http://www.apress.com/9781430261872 Then scroll down the page and look for a tabbed section Click the Source Code/Downloads tab, and download the zip file of examples using the provided link li www.it-ebooks.info Chapter Optimizing Table Performance This chapter details database features that impact the performance of storing and retrieving data within a table Table performance is partially determined by database characteristics implemented prior to creating tables For example, the physical storage features implemented when first creating a database and associated tablespaces subsequently influence the performance of tables Similarly, performance is also impacted by your choice of initial physical features such as table types and data types Therefore implementing practical database, tablespace, and table creation standards (with performance in mind) forms the foundation for optimizing data availability and scalability An Oracle database is comprised of the physical structures used to store, manage, secure, and retrieve data When first building a database, there are several performance-related features that you can implement at the time of database creation For example, the initial layout of the datafiles and the type of tablespace management are specified upon creation Architectural decisions taken at this point often have long-lasting implications ■■Tip  An Oracle instance is defined to be the memory structures and background processes Whereas an Oracle database consists of physical files—namely, data files, control files, and online redo log files As depicted in Figure 1-1, a tablespace is the logical structure that allows you to manage a group of datafiles Datafiles are the physical datafiles on disk When configuring tablespaces, there are several features to be aware of that can have far-reaching performance implications, namely locally managed tablespaces and automatic segment storage managed (ASSM) tablespaces When you reasonably implement these features, you maximize your ability to obtain acceptable future table performance www.it-ebooks.info Chapter ■ Optimizing Table Performance physical storage database users (owners) data files OS blocks extents database blocks logical storage tablespaces schemas segments: - tables - indexes - partitions - rollback - and so on Figure 1-1.  Relationships of logical and physical storage The table is the object that stores data in a database One measure of database performance is the speed at which an application is able to insert, update, delete, and select data Therefore it’s appropriate that we begin this book with recipes that provide solutions regarding problems related to table performance We start by describing aspects of database and tablespace creation that impact table performance We next move on to topics such as choosing table types and data types that meet performance-related business requirements Later topics include managing the physical implementation of tablespace usage We detail issues such as detecting table fragmentation, dealing with free space under the high-water mark, row migration/chaining, and compressing data Also described is the Oracle Segment Advisor This handy tool helps you with automating the detection and resolution of table fragmentation and unused space 1-1 Building a Database That Maximizes Performance Problem You realize when initially creating a database that some features (when enabled) have long-lasting implications for table performance and availability Specifically, when creating the database, you want to the following: • Enforce that every tablespace ever created in the database must be locally managed Locally managed tablespaces deliver better performance than the obsolete dictionary-managed technology • Ensure users are automatically assigned a default permanent tablespace This guarantees that when users are created they are assigned a default tablespace other than SYSTEM With the deferred segment feature (more on this later), if a user has the CREATE TABLE privilege, then it is possible for that user to create objects in the SYSTEM tablespace even without having a space quota on the SYSTEM tablespace This is undesirable It’s true they won’t be able to insert data into tables without appropriate space quotas, but they can create objects, and thus inadvertently clutter up the SYSTEM tablespace • Ensure users are automatically assigned a default temporary tablespace This guarantees that when users are created they are assigned the correct temporary tablespace when no default is explicitly provided www.it-ebooks.info Chapter ■ Optimizing Table Performance Solution There are two different tools that you can use to create an Oracle database: • SQL*Plus using the CREATE DATABASE statement • Database Configuration Assistant (dbca) These techniques are described in the following subsections SQL*Plus Use a script such as the following to create a database that adheres to reasonable standards that set the foundation for a well-performing database:   CREATE DATABASE O12C MAXLOGFILES 16 MAXLOGMEMBERS MAXDATAFILES 1024 MAXINSTANCES MAXLOGHISTORY 680 CHARACTER SET AL32UTF8 DATAFILE '/u01/dbfile/O12C/system01.dbf' SIZE 500M REUSE EXTENT MANAGEMENT LOCAL UNDO TABLESPACE undotbs1 DATAFILE '/u02/dbfile/O12C/undotbs01.dbf' SIZE 800M SYSAUX DATAFILE '/u01/dbfile/O12C/sysaux01.dbf' SIZE 500M DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/u02/dbfile/O12C/temp01.dbf' SIZE 500M DEFAULT TABLESPACE USERS DATAFILE '/u01/dbfile/O12C/users01.dbf' SIZE 50M LOGFILE GROUP ('/u01/oraredo/O12C/redo01a.rdo', '/u02/oraredo/O12C/redo01b.rdo') SIZE 200M, GROUP ('/u01/oraredo/O12C/redo02a.rdo', '/u02/oraredo/O12C/redo02b.rdo') SIZE 200M, GROUP ('/u01/oraredo/O12C/redo03a.rdo', '/u02/oraredo/O12C/redo03b.rdo') SIZE 200M USER sys IDENTIFIED BY f0obar USER system IDENTIFIED BY f0obar;   www.it-ebooks.info Chapter ■ Optimizing Table Performance The prior CREATE DATABASE script helps establish a good foundation for performance by enabling features such as the following: • Defines the SYSTEM tablespace as locally managed via the EXTENT MANAGEMENT LOCAL clause; this ensures that all tablespaces ever created in database are locally managed Starting with Oracle Database 12c, the SYSTEM tablespace is always created as locally managed • Defines a default tablespace named USERS for any user created without an explicitly defined default tablespace; this helps prevent users from being assigned the SYSTEM tablespace as the default • Defines a default temporary tablespace named TEMP for all users; this helps prevent users from being assigned the SYSTEM tablespace as the default temporary tablespace Users created with a default temporary tablespace of SYSTEM can have an adverse impact on performance, as this will cause contention for resources in the SYSTEM tablespace Solid performance starts with a correctly configured database The prior recommendations help you create a reliable infrastructure for your table data dbca Oracle’s dbca utility has a graphical interface and a command line mode from which you can configure and create databases The visual tool is easy to use and has a very intuitive interface In Linux/Unix environments to use the dbca in graphical mode, ensure you have the proper X software installed, then issue the xhost + command, and make certain your DISPLAY variable is set; for example:   $ xhost + $ echo $DISPLAY :0.0    $ xhost + $ echo $DISPLAY :0.0   The dbca is invoked from the operating system as follows:   $ dbca   You’ll be presented with a series of screens that allow you to make choices on the configuration You can choose the “Advanced Mode” option which gives you more control on aspects such as file placement and multiplexing of the online redo logs By default, the dbca creates a database with the following characteristics: • Defines the SYSTEM tablespace as locally managed • Defines a default tablespace named USERS for any user created without an explicitly defined default tablespace • Defines a default temporary tablespace named TEMP for all users Like the SQL*Plus approach, these are all desirable features that provide a good foundation to build applications on The dbca utility also allows you to create a database in silent mode, without the graphical component Using dbca in silent mode with a response file is an efficient way to create databases in a consistent and repeatable manner This approach also works well when you’re installing on remote servers, which could have a slow network connection or not have the appropriate X software installed www.it-ebooks.info Chapter ■ Optimizing Table Performance You can also run the dbca in silent mode with a response file In some situations, using dbca in graphical mode isn’t feasible This may be due to slow networks or the unavailability of X software To create a database, using dbca in silent mode, perform the following steps: Locate the dbca.rsp file Make a copy of the dbca.rsp file Modify the copy of the dbca.rsp file for your environment Run the dbca utility in silent mode First, navigate to the location in which you copied the Oracle database installation software, and use the find command to locate dbca.rsp:   $ find -name dbca.rsp /12.1.0.1/database/response/dbca.rsp   Copy the file so that you’re not modifying the original (in this way, you’ll always have a good, original file):   $ cp dbca.rsp mydb.rsp   Now, edit the mydb.rsp file Minimally, you need to modify the following parameters: GDBNAME, SID, SYSPASSWORD, SYSTEMPASSWORD, SYSMANPASSWORD, DBSNMPPASSWORD, DATAFILEDESTINATION, STORAGETYPE, CHARACTERSET, and NATIONALCHARACTERSET Following is an example of modified values in the mydb.rsp file:   [CREATEDATABASE] GDBNAME = "O12C" SID = "O12C" TEMPLATENAME = "General_Purpose.dbc" SYSPASSWORD = "f00bar" SYSTEMPASSWORD = "f00bar" SYSMANPASSWORD = "f00bar" DBSNMPPASSWORD = "f00bar" DATAFILEDESTINATION ="/u01/dbfile" STORAGETYPE="FS" CHARACTERSET = "AL32UTF8" NATIONALCHARACTERSET= "UTF8"   Next, run the dbca utility in silent mode, using a response file:   $ dbca -silent -responseFile /home/oracle/orainst/mydb.rsp   You should see output such as   Copying database files 1% complete Creating and starting Oracle instance 62% complete Completing Database Creation 100% complete Look at the log file for further details   www.it-ebooks.info Chapter ■ Optimizing Table Performance If you look in the log files, note that the dbca utility uses the rman utility to restore the data files used for the database Then, it creates the instance and performs post-installation steps On a Linux server you should also have an entry in the /etc/oratab file for your new database Many DBAs launch dbca and configure databases in the graphical mode, but a few exploit the options available to them using the response file With effective utilization of the response file, you can consistently automate the database creation process You can modify the response file to build databases on ASM and even create RAC databases In addition, you can control just about every aspect of the response file, similar to launching the dbca in graphical mode ■■Tip  You can view all options of the dbca via the help parameter: dbca -help How It Works A properly configured and created database will help ensure that your database performs well It is true that you can modify features after the database is created However, often a poorly crafted CREATE DATABASE script leads to a permanent handicap on performance In production database environments, it’s sometimes difficult to get the downtime that might be required to reconfigure an improperly configured database If possible, think about performance at every step in creating an environment, starting with how you create the database When creating a database, you should also consider features that affect maintainability A sustainable database results in more uptime, which is part of the overall performance equation The CREATE DATABASE statement in the “Solution” section also factors in the following sustainability features: • Creates an automatic UNDO tablespace (automatic undo management is enabled by setting the UNDO_MANAGEMENT and UNDO_TABLESPACE initialization parameters); this allows Oracle to automatically manage the rollback segments This relieves you of having to regularly monitor and tweak • Places datafiles in directories that follow standards for the environment; this helps with maintenance and manageability, which results in better long-term availability and thus better performance • Sets passwords to non-default values for DBA-related users; this ensures the database is more secure, which in the long run can also affect performance (e.g., if a malcontent hacks into the database and deletes data, then performance will suffer) • Establishes three groups of online redo logs, with two members each, sized appropriately for the transaction load; the size of the redo log directly affects the rate at which they switch When redo logs switch too often, this can degrade performance Keep in mind that when you create a new database that you may not know the appropriate size and will have to adjust this later You should take the time to ensure that each database you build adheres to commonly accepted standards that help ensure you start on a firm performance foundation If you’ve inherited a database and want to verify the default permanent tablespace setting, use a query such as this:   SELECT * FROM database_properties WHERE property_name = 'DEFAULT_PERMANENT_TABLESPACE';   If you need to modify the default permanent tablespace, so as follows:   SQL> alter database default tablespace users;   www.it-ebooks.info ■ Contents 11-14 Selectively Deleting Statements from a SQL Tuning Set������������������������������������������������401 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 401 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 401 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 401 11-15 Transporting a SQL Tuning Set���������������������������������������������������������������������������������������402 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 402 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 402 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 404 11-16 Creating a Tuning Task���������������������������������������������������������������������������������������������������404 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 404 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 405 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 407 11-17 Running the SQL Tuning Advisor������������������������������������������������������������������������������������407 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 407 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 408 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 410 11-18 Generating SQL Tuning Advice from the Automatic Database Diagnostic Monitor��������411 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 411 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 411 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 414 ■■Chapter 12: Execution Plan Optimization and Consistency�������������������������������������������415 Background�������������������������������������������������������������������������������������������������������������������������������416 Seeing the Big Picture���������������������������������������������������������������������������������������������������������������417 12-1 Creating and Accepting a SQL Profile������������������������������������������������������������������������������420 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 420 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 420 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 423 12-2 Determining if a Query is Using a SQL Profile������������������������������������������������������������������424 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 424 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 424 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 425 xxxiii www.it-ebooks.info ■ Contents 12-3 Automatically Accepting SQL Profiles������������������������������������������������������������������������������425 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 425 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 426 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 426 12-4 Displaying SQL Profile Information����������������������������������������������������������������������������������428 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 428 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 428 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 428 12-5 Selectively Testing a SQL Profile��������������������������������������������������������������������������������������429 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 429 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 429 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 430 12-6 Transporting a SQL Profile to a Different Database����������������������������������������������������������430 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 430 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 431 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 432 12-7 Disabling a SQL Profile����������������������������������������������������������������������������������������������������433 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 433 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 433 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 433 12-8 Dropping a SQL Profile�����������������������������������������������������������������������������������������������������434 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 434 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 434 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 434 12-9 Creating a Plan Baseline for a SQL Statement in Memory�����������������������������������������������435 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 435 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 435 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 436 xxxiv www.it-ebooks.info ■ Contents 12-10 Creating Plan Baselines for SQL Contained in SQL Tuning Set��������������������������������������������438 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 438 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 438 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 440 12-11 Automatically Adding Plan Baselines�����������������������������������������������������������������������������440 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 440 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 440 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 441 12-12 Altering a Plan Baseline�������������������������������������������������������������������������������������������������442 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 442 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 442 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 442 12-13 Determining If Plan Baselines Exist�������������������������������������������������������������������������������443 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 443 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 443 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 444 12-14 Determining if a Query is Using a Plan Baseline������������������������������������������������������������445 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 445 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 446 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 446 12-15 Displaying Plan Baseline Execution Plans���������������������������������������������������������������������447 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 447 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 447 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 447 12-16 Manually Adding a New Execution Plan to Plan Baseline (Evolving)�����������������������������448 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 448 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 448 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 450 xxxv www.it-ebooks.info ■ Contents 12-17 Toggling the Automatic Acceptance of New Low-Cost Execution Plans������������������������451 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 451 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 451 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 451 12-18 Disabling Plan Baselines������������������������������������������������������������������������������������������������451 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 451 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 452 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 452 12-19 Removing Plan Baseline Information�����������������������������������������������������������������������������452 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 452 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 452 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 453 12-20 Transporting Plan Baselines�������������������������������������������������������������������������������������������454 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 454 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 454 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 455 ■■Chapter 13: Configuring the Optimizer��������������������������������������������������������������������������457 13-1 Choosing an Optimizer Goal���������������������������������������������������������������������������������������������457 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 457 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 457 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 458 13-2 Enabling Automatic Statistics Gathering��������������������������������������������������������������������������458 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 458 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 458 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 459 13-3 Setting Preferences for Statistics Collection�������������������������������������������������������������������460 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 460 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 461 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 461 xxxvi www.it-ebooks.info ■ Contents 13-4 Manually Generating Statistics����������������������������������������������������������������������������������������466 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 466 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 466 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 467 13-5 Locking Statistics������������������������������������������������������������������������������������������������������������467 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 467 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 468 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 468 13-6 Handling Missing Statistics���������������������������������������������������������������������������������������������469 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 469 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 469 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 469 13-7 Exporting Statistics����������������������������������������������������������������������������������������������������������471 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 471 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 471 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 472 13-8 Restoring Previous Versions of Statistics������������������������������������������������������������������������472 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 472 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 472 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 473 13-9 Gathering System Statistics���������������������������������������������������������������������������������������������473 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 473 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 474 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 475 13-10 Validating New Statistics�����������������������������������������������������������������������������������������������477 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 477 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 477 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 478 xxxvii www.it-ebooks.info ■ Contents 13-11 Forcing the Optimizer to Use an Index���������������������������������������������������������������������������479 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 479 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 479 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 479 13-12 Enabling Query Optimizer Features�������������������������������������������������������������������������������480 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 480 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 480 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 481 13-13 Keeping the Database from Creating Histograms����������������������������������������������������������482 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 482 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 482 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 482 13-14 Improving Performance When Not Using Bind Variables�����������������������������������������������483 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 483 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 483 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 483 13-15 Understanding Adaptive Cursor Sharing������������������������������������������������������������������������485 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 485 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 485 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 486 13-16 Creating Statistics on Expressions��������������������������������������������������������������������������������491 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 491 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 491 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 491 13-17 Creating Statistics for Related Columns������������������������������������������������������������������������492 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 492 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 492 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 493 xxxviii www.it-ebooks.info ■ Contents 13-18 Automatically Creating Column Groups�������������������������������������������������������������������������493 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 493 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 493 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 494 13-19 Maintaining Statistics on Partitioned Tables������������������������������������������������������������������494 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 494 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 495 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 495 13-20 Concurrent Statistics Collection for Large Tables����������������������������������������������������������496 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 496 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 496 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 496 13-21 Determining When Statistics Are Stale��������������������������������������������������������������������������498 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 498 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 498 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 498 13-22 Previewing Statistics Gathering Targets������������������������������������������������������������������������499 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 499 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 499 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 500 ■■Chapter 14: Implementing Query Hints�������������������������������������������������������������������������501 14-1 Writing a Hint�������������������������������������������������������������������������������������������������������������������501 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 501 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 501 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 502 14-2 Changing the Access Path�����������������������������������������������������������������������������������������������503 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 503 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 503 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 504 xxxix www.it-ebooks.info ■ Contents 14-3 Changing the Join Order��������������������������������������������������������������������������������������������������507 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 507 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 507 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 508 14-4 Changing the Join Method�����������������������������������������������������������������������������������������������508 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 508 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 509 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 511 14-5 Changing the Optimizer Version���������������������������������������������������������������������������������������511 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 511 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 512 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 512 14-6 Choosing Between a Fast Response and Overall Optimization����������������������������������������513 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 513 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 513 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 515 14-7 Performing a Direct-Path Insert���������������������������������������������������������������������������������������515 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 515 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 516 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 517 14-8 Placing Hints in Views������������������������������������������������������������������������������������������������������519 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 519 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 519 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 521 14-9 Caching Query Results�����������������������������������������������������������������������������������������������������521 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 521 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 522 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 524 xl www.it-ebooks.info ■ Contents 14-10 Directing a Distributed Query to a Specific Database����������������������������������������������������525 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 525 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 526 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 526 14-11 Gathering Extended Query Execution Statistics�������������������������������������������������������������529 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 529 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 530 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 531 14-12 Enabling Query Rewrite�������������������������������������������������������������������������������������������������531 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 531 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 531 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 532 14-13 Improving Star Schema Query Performance�����������������������������������������������������������������533 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 533 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 533 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 535 ■■Chapter 15: Executing SQL in Parallel���������������������������������������������������������������������������537 15-1 Enabling Parallelism for a Specific Query������������������������������������������������������������������������537 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 537 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 537 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 538 15-2 Enabling Parallelism at Object Creation���������������������������������������������������������������������������541 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 541 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 542 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 542 15-3 Enabling Parallelism for an Existing Object���������������������������������������������������������������������543 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 543 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 543 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 544 xli www.it-ebooks.info ■ Contents 15-4 Implementing Parallel DML����������������������������������������������������������������������������������������������544 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 544 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 544 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 545 15-5 Creating Tables in Parallel�����������������������������������������������������������������������������������������������547 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 547 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 547 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 547 15-6 Creating Indexes in Parallel���������������������������������������������������������������������������������������������549 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 549 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 550 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 550 15-7 Rebuilding Indexes in Parallel������������������������������������������������������������������������������������������550 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 550 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 551 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 551 15-8 Moving Partitions in Parallel��������������������������������������������������������������������������������������������553 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 553 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 553 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 553 15-9 Splitting Partitions in Parallel������������������������������������������������������������������������������������������555 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 555 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 555 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 555 15-10 Enabling Automatic Degree of Parallelism���������������������������������������������������������������������556 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 556 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 556 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 558 xlii www.it-ebooks.info ■ Contents 15-11 Examining Parallel Explain Plans�����������������������������������������������������������������������������������559 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 559 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 560 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 561 15-12 Monitoring Parallel Operations��������������������������������������������������������������������������������������562 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 562 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 562 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 564 15-13 Finding Bottlenecks in Parallel Processes���������������������������������������������������������������������564 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 564 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 564 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 565 15-14 Getting Detailed Information on Parallel Sessions���������������������������������������������������������566 Problem������������������������������������������������������������������������������������������������������������������������������������������������������������� 566 Solution������������������������������������������������������������������������������������������������������������������������������������������������������������� 566 How It Works������������������������������������������������������������������������������������������������������������������������������������������������������ 567 Index���������������������������������������������������������������������������������������������������������������������������������569 xliii www.it-ebooks.info About the Authors Sam R Alapati is a senior database architect at Cash America International in Fort Worth, Texas Sam is an Oracle OCP 12c certification holder Earlier, Sam worked as an Oracle DBA at AT&T, Boy Scouts of America, and Oracle Corporation Sam has published several Oracle Database and middleware administration–related books, including forthcoming books such as Oracle WebLogic Server 12c Administration Handbook and OCP Oracle Database 12c New Features for Administrators Exam Guide Darl Kuhn is currently a DBA working for Oracle He has written books on a variety of IT topics including SQL, performance tuning, Linux, backup and recovery, RMAN, and database administration Darl also teaches Oracle classes for Regis University and does volunteer DBA work for the Rocky Mountain Oracle Users Group xlv www.it-ebooks.info ■ About the Authors Bill Padfield is an Oracle Certified Professional, working for a large telecommunications company in Denver, Colorado, as a senior database administrator Bill helps administer and manage a large data warehouse environment consisting of more than 100 databases Bill has been an Oracle Database administrator for more than 16 years and has been in the IT industry since 1985 Bill also teaches graduate database courses at Regis University and currently resides in Aurora, Colorado, with his wife, Oyuna, and son, Evan xlvi www.it-ebooks.info About the Technical Reviewers Stéphane Faroult is a French consultant who first discovered relational databases and the SQL language 30 years ago Stéphane joined Oracle France in its early days (after a brief spell with IBM and a period of time teaching at the University of Ottawa) and developed an interest in performance and tuning topics, on which he soon started writing training courses After leaving Oracle in 1988, Stéphane briefly tried going straight and did a bit of operational research, but after only a year, he succumbed again to the allure of relational databases For his sins, Stéphane has been performing database consultancy continuously ever since and founded RoughSea Ltd in 1998 In recent years, Stéphane has had a growing interest in education, which has taken various forms, including books (The Art of SQL, soon followed by Refactoring SQL Applications, both published by O’Reilly) and more recently a textbook (SQL Success, published by RoughSea), a series of seminars in Asia, and video tutorials (www.youtube.com/user/roughsealtd) Arup Nanda has been an Oracle DBA for more than 18 years (and counting) working on all aspects of Oracle Database from modeling, performance tuning, backup, disaster recovery, security, and, more recently, Exadata Currently he is the global database lead at a major multinational corporation near New York, managing, among other things, several Exadata installations Arup has coauthored five books; published more than 500 articles in Oracle Magazine, OTN, and other publications; presented about 300 sessions at various Oracle technology conferences all over the world; and delivered 30 Oracle Celebrity Seminar series courses He is an editor for SELECT Journal, the IOUG publication; a member of the board of directors of the Exadata SIG; an Oracle ACE director; and a member of the Oak Table Network Acknowledging his professional expertise and involvement in the user community, Oracle awarded him the DBA of the Year title in 2003 and Architect of the Year in 2012 xlvii www.it-ebooks.info Acknowledgments Thanks to fellow coauthors Sam Alapati and Bill Padfield and also thanks to the numerous DBAs and developers who I’ve learned performance tuning techniques from over the years: Dave Jennings, Scott Schulze, Bob Suehrstedt, Pete Mullineaux, Janet Bacon, Sue Wagner, Mohan Koneru, Arup Nanda, Charles Kim, Bernard Lopuz, Barb Sannwald, Tim Gorman, Shawn Heisdorffer, Doug Davis, Sujit Pattanaik, Sudeep Pattanaik, Ken Roberts, Roger Murphy, Mehran Sowdaey, Kevin Bayer, Dan Fink, Guido Handley, Nehru Kaja, Tim Colbert, Glenn Balanoff, Bob Mason, Brad Blake, Cathy Wilson, Ravi Narayanaswamy, Abdul Ebadi, Kevin Hoyt, Trent Sherman, Sandra Montijo, Jim Secor, Maureen Frazzini, Sean Best, Stephan Haisley, Geoff Strebel, Patrick Gates, Buzzy Cheadle, Mark Blair, Karen Kappler, Mike Hutchinson, Liz Brill, Ennio Murroni, John Phillips, Mike O’Neill, Jack Donnelly, Beth Loker, Mike Eason, Greg Roberts, Debbie Earman, Bob Sell, Tom Wheltle, Chad Heckman, Ken Toney, Gabor Gyurovszky, Scott Norris, Joey Canlas, Eric Wendelin, Gary Smith, Mark Lutze, Kevin Quinlivan, Dean Price, Dave Bourque, Roy Backstrom, John Lilly, Valerie Eipper, Steve Buckmelter, John DiVirgilio, John Goggin, Simon Ip, Pascal Ledru, Kevin O’Grady, Peter Schow, Todd Sherman, Mike Tanaka, Doug Cushing, Will Thornburg, Steve Roughton, Sudha Verma, Christian Hessler, Tae Kim, Margaret Carson, Jed Summerton, Lea Wang, Ambereen Pasha, Dinesh Neelay, Kye Bae, Thom Chumley, Jeff Sherard, Erik Jasiak, Aaron Isom, Kristi Jackson, Karolyn Vowles, Britni Barovick, Amin Jiwani, Laurie Bourgeois, Vasanthan Dasan, Todd Wichers, Venkatesh Ranganathan, Dave Wood, Jeff Shoup, Brett Guy, and Jim Stark —Darl Kuhn I’d like to thank Sam Alapati and Darl Kuhn for all of their help and support Thanks to my managers over the years in helping me in my career This includes but is not limited to Bob Ranney, Beth Bowen, Larry Wyzgala, John Zlamal, Billie Ortega, Linda Scheldrup, Amy Neff, and Maureen Frazzini I’d like to thank my current DBA team, for their great support and friendship This includes Dave Carter, Debbie Fitzgerald, Sandy Hass, Pankaj Guleria, Brent Wagner, Kevin Tomimatsu, and John Townley Over the years, I’ve learned an awful lot from the following folks, who have always been generous with their time and help and have been patient with my questions I have to thank the Oracle architect at our company, Roby Sherman, for all his support and help over the years There are a myriad of developers, testers, system administrators, and other folks who have been a tremendous help in my career This includes Mark Nold, Mick McMahon, Sandra Montijo, Jerry Sanderson, Glen Sanderson, Jose Fernandez, Mike Hammontre, Pat Cain, Dave Steep, Gary Whiting, Ron Fullmer, Becky Enter, John Weber, Tony Romo, Avanish Gupta, Scott Bunker, Paul Mayes, Bill Read, Rod Ermish, Rick Barry, Sun Yang, Sue Wagner, John Saxe, Glenn Balanoff, Linda Lee Burau, Deborah Lieou-McCall, Bob Zumpf, Pete Sardaczuk, Kristi Sargent, George Huner, Pad Kail, Curtis Gay, Ross Bartholomay, Carol Rosenow, Scott Richards, Sheryl Gross, Lachelle Shambe, John Piel, Rob Grote, Rex Ellis, Zane Warton, Steve Pearson, Kim Lake, Jim Barclay, Jason Hermstad, Shari Plantz-Masters, Denise Duncan, Bob Mason, Brad Blake, Mike Nims, Cathie Wilson, Rob Coates, Shirley Amend, Rob Bushlack, Cindy Patterson, Debbie Chartier, Blair Christensen, Meera Ganesan, Kedar Panda, Srivatsan Muralidaran, Tony Arlt, Atul Shirke, Deb Kingsley, Brenda Carney, Paul Obering, Don Miller, Ned Ashby, Pat Wuller, and Adric Norris —Bill Padfield xlix www.it-ebooks.info ... crisis altogether Who This Book Is For Oracle Database 12c Performance Tuning Recipes was written primarily for database administrators who manage Oracle Database environments The book is especially... Index���������������������������������������������������������������������������������������������������������������������������������569 v www.it-ebooks.info Introduction Oracle Database 12c Performance Tuning Recipes is a book of solutions—a crib sheet of sorts Database performance problems often rear themselves suddenly,... Optimizing Table Performance This chapter details database features that impact the performance of storing and retrieving data within a table Table performance is partially determined by database characteristics

Ngày đăng: 12/03/2019, 14:25

Từ khóa liên quan

Mục lục

  • Contents at a Glance

  • Contents

  • About the Authors

  • About the Technical Reviewers

  • Acknowledgments

  • Introduction

  • Chapter 1: Optimizing Table Performance

    • 1-1. Building a Database That Maximizes Performance

      • Problem

      • Solution

        • SQL*Plus

        • dbca

        • How It Works

        • 1-2. Creating Tablespaces to Maximize Performance

          • Problem

          • Solution

          • How It Works

          • 1-3. Matching Table Types to Business Requirements

            • Problem

            • Solution

            • How It Works

            • 1-4. Choosing Table Features for Performance

              • Problem

              • Solution

              • How It Works

              • 1-5. Selecting Data Types Appropriately

                • Problem

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan