GFC_DEFRAG: FREE SPACE DEFRAGMENTATION UTILITY PACKAGE

Similar documents
FACTORS AFFECTING CONCURRENT TRUNCATE

IMPROVING THE PERFORMANCE OF SECURITY VIEWS IN PEOPLESOFT HCM8.8

Geodatabase Best Practices. Dave Crawford Erik Hoel

Administering your Enterprise Geodatabase using Python. Jill Penney

Geodatabase: Best Practices. Robert LeClair, Senior Instructor

Geodatabase Programming with Python John Yaist

Geodatabase An Introduction

Geodatabase Programming with Python

NEC PerforCache. Influence on M-Series Disk Array Behavior and Performance. Version 1.0

Mass Asset Additions. Overview. Effective mm/dd/yy Page 1 of 47 Rev 1. Copyright Oracle, All rights reserved.

ON SITE SYSTEMS Chemical Safety Assistant

OECD QSAR Toolbox v.4.1. Tutorial illustrating new options for grouping with metabolism

MySQL 5.1. Past, Present and Future. Jan Kneschke MySQL AB

Arup Nanda Starwood Hotels

From BASIS DD to Barista Application in Five Easy Steps

Homework Assignment 2. Due Date: October 17th, CS425 - Database Organization Results

Databases through Python-Flask and MariaDB

PAID INVOICE TAX REPORT

Database Systems SQL. A.R. Hurson 323 CS Building

CPU scheduling. CPU Scheduling

Mars Attacked! 2011 ICTSA Programming Challenge

Administering Your Enterprise Geodatabase using Python. Gerhard Trichtl

Section 4.5 Eigenvalues of Symmetric Tridiagonal Matrices

Internal Audit Report

The conceptual view. by Gerrit Muller University of Southeast Norway-NISE

Carnegie Mellon University Department of Computer Science /615 - Database Applications C. Faloutsos & A. Pavlo, Fall 2016

EEOS 381 -Spatial Databases and GIS Applications

With. Krista Zens. Manager, GIS - BC Oil and Gas Commission. Tammy Pham. Lead Business Analyst - Pacific GeoTech Systems Ltd.

ST-Links. SpatialKit. Version 3.0.x. For ArcMap. ArcMap Extension for Directly Connecting to Spatial Databases. ST-Links Corporation.

From BASIS DD to Barista Application in Five Easy Steps

Degree-days and Phenology Models

Advanced Forecast. For MAX TM. Users Manual

OECD QSAR Toolbox v.3.0

Package robustrao. August 14, 2017

Oracle Spatial: Essentials

CPU Scheduling. CPU Scheduler

QSQL: Incorporating Logic-based Retrieval Conditions into SQL

SDS developer guide. Develop distributed and parallel applications in Java. Nathanaël Cottin. version

Algorithms for Data Science

COMPUTER SCIENCE TRIPOS

OECD QSAR Toolbox v.3.2. Step-by-step example of how to build and evaluate a category based on mechanism of action with protein and DNA binding

OECD QSAR Toolbox v.3.4. Step-by-step example of how to build and evaluate a category based on mechanism of action with protein and DNA binding

OECD QSAR Toolbox v.3.3. Step-by-step example of how to build and evaluate a category based on mechanism of action with protein and DNA binding

CS425: Algorithms for Web Scale Data

OBEUS. (Object-Based Environment for Urban Simulation) Shareware Version. Itzhak Benenson 1,2, Slava Birfur 1, Vlad Kharbash 1

Ratio of Polynomials Fit One Variable

Geodatabase 101 Why, What, & How

Replication cluster on MariaDB 5.5 / ubuntu-server. Mark Schneider ms(at)it-infrastrukturen(dot)org

Demand Forecasting. for. Microsoft Dynamics 365 for Operations. User Guide. Release 7.1. April 2018

7600 Series Routers Adjacency Allocation Method

Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA === Homework submission instructions ===

Envy-free cake divisions cannot be found by finite protocols

OPENATOM for GW calculations

OECD QSAR Toolbox v.3.3. Step-by-step example of how to categorize an inventory by mechanistic behaviour of the chemicals which it consists

Databases Exam HT2016 Solution

GS Analysis of Microarray Data

Ratio of Polynomials Fit Many Variables

COMP 633: Parallel Computing Fall 2018 Written Assignment 1: Sample Solutions

Geodatabase An Introduction

Package rnmf. February 20, 2015

Math 98 - Introduction to MATLAB Programming. Spring Lecture 3

Local stageout update

CEE 618 Scientific Parallel Computing (Lecture 7): OpenMP (con td) and Matrix Multiplication

RESERVE DESIGN INTRODUCTION. Objectives. In collaboration with Wendy K. Gram. Set up a spreadsheet model of a nature reserve with two different

GTVD : A RATS procedure to estimate Smooth Transition Regressions with Panel Data

TECDIS and TELchart ECS Weather Overlay Guide

Introduction to ArcGIS Server Development

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

COMPUTER SCIENCE TRIPOS

Collaborative Forecasts Implementation Guide

Town of Taos Request for Proposal Historic Preservation GIS Geodatabase Project April 2007

On Two Class-Constrained Versions of the Multiple Knapsack Problem

MLMED. User Guide. Nicholas J. Rockwood The Ohio State University Beta Version May, 2017

JOB TITLE: CURRENT CLASSIFICATION/GRID POSITION # GIS Coordinator AD Grid Level 6(c) # 420

Better Living Through Statistics Monitoring Doesn't (Have To) Suck

Lecture 8. Root finding II

Counting Strategies: Inclusion/Exclusion, Categories

MULTIPLE CHOICE QUESTIONS DECISION SCIENCE

Module 5: CPU Scheduling

Linear Referencing Systems (LRS) Support for Municipal Asset Management Systems

Introduction to Hartree-Fock calculations in Spartan

CSE613: Parallel Programming, Spring 2012 Date: May 11. Final Exam. ( 11:15 AM 1:45 PM : 150 Minutes )

Lineage implementation in PostgreSQL

GS Analysis of Microarray Data

GS Analysis of Microarray Data

Chapter 6: CPU Scheduling

Course Announcements. Bacon is due next Monday. Next lab is about drawing UIs. Today s lecture will help thinking about your DB interface.

City of Hermosa Beach Beach Access and Parking Study. Submitted by. 600 Wilshire Blvd., Suite 1050 Los Angeles, CA

ww.padasalai.net

The File Geodatabase API. Craig Gillgrass Lance Shipman

22.4. Numerical Determination of Eigenvalues and Eigenvectors. Introduction. Prerequisites. Learning Outcomes

Image Compression Using the Haar Wavelet Transform

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

Sequential: Vector of Bits

Graphical User Interfaces for Emittance and Correlation Plot. Henrik Loos

New Approaches to the Development of GC/MS Selected Ion Monitoring Acquisition and Quantitation Methods Technique/Technology

Description of the ED library Basic Atoms

Quantum Searching. Robert-Jan Slager and Thomas Beuman. 24 november 2009

Geodatabase Essentials Part One - Intro to the Geodatabase. Jonathan Murphy Colin Zwicker

CODYCLOSE VERSION 4 FOR THE HEWLETT PACKARD HP49G+ AND THE HP50G SERIES CALCULATOR NOVEMBER 2007 CODYCLOSE NOVEMBER 2007 VERSION 4

Transcription:

T E C H N I C A L N O T E GFC_DEFRAG: FREE SPACE DEFRAGMENTATION UTILITY PACKAGE Prepared By David Kurtz, Go-Faster Consultancy Ltd. Technical Note Version 1.01 Tuesday 5 February 2013 (E-mail: david.kurtz@go-faster.co.uk, telephone +44-7771-760660) File: gfc_defrag.docx, 5 February 2013 Contents Introduction... 2 GFC_DEFRAG package... 3 HIGH_BLOCK_SEGMENTS... 4 TRIM_FREE_SPACE... 8 G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 1

T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X 05 F E B R U A R Y 2013 Introduction This document discusses some ideas for reducing the physical size of a database by defragmenting free space such that it effectively moves to the end of a data file from which it can be removed by resizing the data file. This will be necessary after purge, archive and compression activities that occur during archiving. These are separate to the archiving processes because they do not logically affect any data in the database. Rather archiving affords the DBA team the opportunity to conduct these additional actions. Although table compression will reduce the size of table segments, it will leave large amounts of free space in the middle of a data file 1. In order to reduce the overall database size, we need to be able move that free space to end of the data file and trim it off by resizing the data file. This document also explains the use of the GFC_DEFRAG package has been provided to assist with these operations. The HIGH_BLOCK_SEGMENTS program can be used to shuffle free space to the ends of data files where it can then be trimmed with the TRIM_FREE_SPACE program. 1 A favourite analogy for this is that of a swiss cheese with holes. The holes take up space in the cheese. We could reduce the overall size of the cheese, by filling the holes up with cheese taken from the outside. This is neither possible nor desirable with a real physical piece of Emmental, but it is with a data file! G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 2 G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L

` 05 F E B R U A R Y 2013 T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X GFC_DEFRAG package This package contains programs that dynamically generate and execute DDL to move segments appropriate tables and set store options as defined in the meta-data for the GFC_PSPART package. The packge is owned by SYS to deliberately override any permission issues and to ensure that only a user with SYSDBA permission can execute it. The package contains the following sub-programs: HIGH_BLOCK_SEGMENTS (see page 4) Instrumentation Each program in the package uses DBMS_APPLICATION_INFO to set the module and action. These values can be used to track the progress of the package in Oracle Enterprise Manager etc. Module is set to the name of the package followed by the name of the program. For example, while the HIGH_BLOCK_SEGMENTS package is running it would be set to GFC_DEFRAG.HIGH_BLOCK_SEGMENTS. Action is initially set to the list of parameters passed to the program. As the programs move on to rebuilding segments the action is updated to the name of the segment. G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 3

T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X 05 F E B R U A R Y 2013 HIGH_BLOCK_SE GMENTS This procedure rebuilds tables, lob segments and index segments in an order such that objects at the end of a data file are moved nearer the bottom of a tablespace thus resulting in all the free space in a data file moving to the end of the data file where it can be trimmed off with the TRIM_FREE_SPACE program in this package. Syntax PROCEDURE high_block_segments (p_tablespace VARCHAR2 DEFAULT '%',p_file_id NUMBER DEFAULT NULL,p_relfileno NUMBER DEFAULT NULL,p_updateind,p_statsjob,p_resize,p_max_parts,p_testmode BOOLEAN DEFAULT TRUE BOOLEAN DEFAULT TRUE BOOLEAN DEFAULT TRUE INTEGER DEFAULT NULL BOOLEAN DEFAULT FALSE); Parameters Parameter p_tablespace p_file_id p_relfileno p_updateind p_statsjob p_resize p_max_parts p_testmode Description Name of tablespace to process. File ID to process. If null all files will be considerd. Relative file ID to process. If null assume p_relfileno is the same value as p_file_id. If both p_relfileno and p_file_id are null then files will be considered. If this parameter is true the ALTER TABLE MOVE PARTITION command includes the UPDATE INDEXES command. Otherwise indexes or index partitions will be invalidated. The default value of the parameter is TRUE. If this parameter is true a job will be submitted to the database job scheduler to collect statistics on the table partition and its indexes. The default value is TRUE. If this parameter is true the package resizes the data file to the previous maximum block occupied by the segment that it has just rebuilt. The default value is TRUE. If specified, the number of partitions processed by the program will be limited to the value of this parameter. The default value is null, in which case there is no limit. If this parameter is TRUE then the package will not submit the DDL that it generates to the database, it will only be printed through dbms_output. G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 4 G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L

` 05 F E B R U A R Y 2013 T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X The driving query, initially based on the query in the DBA_EXTENTS view, determines the maximum block ID in each segment. Rows are retrieved in descending order of maximum block ID within each tablespace and data file. Rows are not retrieved by the query if the volume of free space below the maximum block ID of the segment in the same data file, or in any other data file is smaller than the segment. Having rebuilt the object it trims the data file down to the now vacated maximum block ID. Despsite this, the procedure will usually leave some free space that has to be separately trimmed. Parallelism of rebuild is limited to the number extents in the segment being rebuilt by explicitly specifying the degree of parallelism on the DDL. This prevents additional extents being created thus expanding the object. If the number of extents is greater or equal to the default parallelism (the product of the Oracle initialisation parameters cpu_count and parallel_threads_per_cpu) the degree of parallelism is not specified. If there is only one extent parallelism is explicitly disabled. The algorithm works well for single data files tablespaces. However, in some cases can arise. If the tablespace consists of multiple data files it is difficult to predict the space allocation. An object might have extents in other data files, and Oracle may put all the extents in the rebuilt objects into the current data file. This can result in an error when the package tries to trim the free space to the maximum block ID in the current object. In this case the error is not trapped and package will terminate. However, this is a reasonable behaviour because the data file has grown rather than shrunk and there is no point continuing. ORA-03297: file contains used data beyond requested RESIZE value ORA-06512: at "SYS.GFC_DEFRAG", line o When this error occurs on a tablespace with multiple data files, try processing all the data files before returning to the one that failed. If you persistently get this error suppress the resize by setting the p_resize parameter to FALSE and see if a subsequent TRIM_FREE_SPACE reclaims the space. If a table contains a BLOB or CLOB, then rebuilding it might also rebuild the lob segment and lob index. This may consume more free space than expected causing the same error when it comes to trim off the free space. The program is driven by a single read-consistent query. The actual space allocation of the database as a number of objects are rebuilt will progressively diverge from the estimated allocation assumed by the package. Therefore, it will be necessary to work iteratively. It is my understanding that in a multi-datafile tablespace, Oracle will a new extent in the lowest possible block ID available in any of the datafiles. Recommendation: Work datafile by datafile, perhaps starting with the data files that have the most free space. If the process runs to success on a datafile it is worth running it again to check that there is no more space to be reclaimed. If the process does generate ORA-3297 on a multi-datafile tablespace then move on to a different datafile and come back to this one. To permit parallel rebuild of indexes during table rebuilds, the PSFT_DDL_LOCK trigger should be temporarily disabled. G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 5

T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X 05 F E B R U A R Y 2013 The following query reports the data files with the most free space and they highest free block ID. SET LINES 70 TTITLE 'Top 20 Data Files by Free Space' COLUMN ranking1 HEADING '#' FORMAT 999 COLUMN Mb HEADING 'Total Free MB' FORMAT 99999.9 COLUMN max_free_mb HEADING 'Max Free MB' FORMAT 99999.9 COLUMN max_free_block HEADING 'Max Free Block' FORMAT 9999999 COLUMN largest_free_mb HEADING 'Largest Free MB' FORMAT 99999.9 COLUMN file_id HEADING 'File ID' FORMAT 9999 COLUMN num_free HEADING 'Num Free Spaces' FORMAT 9999 COLUMN tablespace_name HEADING 'Tablespace Name' FORMAT a14 WITH x as (SELECT tablespace_name, file_id, COUNT(*) num_free, SUM(bytes)/1024/1024 Mb, MAX(bytes)/1024/1024 largest_free_mb, MAX(block_id)*8/1024 max_free_mb, MAX(block_id) max_free_block FROM dba_free_space GROUP BY tablespace_name, file_id ), y as ( SELECT ROW_NUMBER() OVER (ORDER BY mb desc) as ranking1, x.* from x) SELECT * FROM y WHERE ranking1 <= 20 ORDER BY ranking1 / TTITLE OFF G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 6 G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L

` 05 F E B R U A R Y 2013 T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X These are the data files with the most free space, and where this program will have the greatest saving. Sun Jul 15 Top 20 Data Files by Free Space page Num Total Max Tablespace File Free Free Free # Name ID Spaces MB MB ---- ------------ ----- ------ -------- -------- 1 PSIMAGE 461 15 22985.2 23115.0 2 PSINDEX 459 199 18374.8 28542.9 3 PSIMAGE 505 12 17943.4 18131.7 4 TL2011M01TAB 410 269 17057.0 19035.1 5 PTAMSG 92 9 16963.2 16967.0 6 TL2010M08TAB 400 299 16577.0 18628.1 7 TL2011M07TAB 422 225 16345.0 18262.1 8 TL2010M12TAB 408 204 15878.0 17584.1 9 TL2011M04TAB 416 199 15865.0 17502.1 10 TL2010M09TAB 402 179 15543.0 17193.1 11 TL2010M07TAB 398 8 14587.0 15907.1 12 TL2011M05TAB 418 280 12821.0 14700.1 13 TL2011M10TAB 428 270 12524.0 14460.1 14 TL2011M02TAB 412 143 12075.0 13656.1 15 TL2010M11TAB 406 204 11979.0 13667.1 16 TL2011M11TAB 430 151 11759.0 13133.1 17 TL2011M06TAB 420 151 11748.0 13132.1 18 USERS 4 178 11471.1 32170.9 19 PSIMAGE 495 17 11096.9 11227.8 20 TLAPP 117 170 10041.8 11718.1 Therefore it would make sense to work down this list of datafile. execute GFC_DEFRAG.high_block_segments(p_tablespace=>'PSIMAGE',p_file_id=>461); execute GFC_DEFRAG.high_block_segments(p_tablespace=>'PSINDEX',p_file_id=>459); execute GFC_DEFRAG.high_block_segments(p_tablespace=>'TL2011M01TAB'); G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 7

T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X 05 F E B R U A R Y 2013 TRIM_FREE_SPACE This procedure trims free space at the ends of data files to reduce the size of the database. It is quite slow to scan all the used blocks in a data blocks. This is also why the DBA_EXTENTS view performs so slowly in 10g. However, it is relatively easy to scan the free space map using the DBA_FREE_SPACE view. This procedure works through the entries in DBA_FREE_SPACE for selected data files in descending block ID order checking whether the end of the free extent matches the end of the file or the start of the previous free extent and resizes the data file as it goes. Note: DBA_FREE_SPACE reports free space in 4Gb chunks (in an 8K tablespace). This makes it difficult to trim free space with a purely SQL approach. However, it is easy to test with PL/SQL. Simply dropping objects does not reduce the size of the RMAN backup because the blocks are still formatted and contain an SCN. Syntax PROCEDURE trim_free_space (p_tablespace VARCHAR2 DEFAULT '%',p_file_id NUMBER DEFAULT NULL,p_testmode BOOLEAN DEFAULT FALSE); Parameters Parameter p_tablespace p_file_id p_testmode Description Name of tablespace to process. File ID to process. If null all files will be considerd. If this parameter is TRUE then the package will not submit the DDL that it generates to the database, it will only be printed through dbms_output. Sample Output This shows the procedure processing file 120 which is part the WAAPP tablespace. It is 128 blocks, or 1024Mb in size. There is a free space extent of 120 blocks from block 9 to block 128. So we could trim tablespace down to 8 blocks. Except that the minimum extent size is 64Kb so the minimum size of the tablespace is twice that. 00:47:32 18.07.2012:Tablespace: WAAPP, file: 120, 128 blocks, 120 user blocks, 1024KB 00:47:32 18.07.2012:Free space 1: 120 @ block id: 9-128, next free block id: 00:47:32 18.07.2012:ALTER DATABASE DATAFILE '+DATA/xxxxxx1a/datafile/waapp.1203.785636623' RESIZE 128K G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 8 G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L

` 05 F E B R U A R Y 2013 T E C H N I C A L N O T E - G F C _ D E F R A G. D O C X In this example there are two contiguous free space extents. The first from 507913 to 525000 is adjacent to the end of data file 450 and then a second from 47369 to 507912. So we can resize the data file to 378952K. The next free space is much lower down the data file at 26889 to 39176 and is therefore not contingous so processing of this data stops at this point. 07:16:08 18.07.2012:Tablespace: PSIMAGE, file: 450, 525001 blocks, 524992 user blocks, 4200008KB 07:16:08 18.07.2012:Free space 1: 17088 @ block id: 507913-525000, next free block id: 07:16:08 18.07.2012:ALTER DATABASE DATAFILE '+DATA/xxxxxx1a/datafile/psimage.861.785589779' RESIZE 4063304K 07:16:11 18.07.2012:Free space 2: 460544 @ block id: 47369-507912, next free block id: 507913 07:16:11 18.07.2012:ALTER DATABASE DATAFILE '+DATA/xxxxxx1a/datafile/psimage.861.785589779' RESIZE 378952K 07:16:13 18.07.2012:Free space 3: 12288 @ block id: 26889-39176, next free block id: 47369 G O - F A S T E R C O N S U L T A N C Y L TD. - C O N F I D E N T I A L G F C _ D E F R A G : F R E E S P A C E D E F R A G M E N T A T I O N U T I L I T Y P A C K A G E 9