How To  Reclaim Disk Space  in Infobright 

Transcription

  How To  Reclaim Disk Space  in Infobright 
 How To Reclaim Disk Space in Infobright “The dinosaurs became extinct because they didn't have a space program.” Larry Niven David Lutz, Director of Technical Sales Consulting, 01­Oct­09 Infobright, Inc.
47 Colborne Street, Suite 403
Toronto, Ontario M5E 1P8
Canada
www.infobright.com
www.infobright.org
How to Reclaim Disk Space Table of Contents Synopsis 3 Introduction 3 Methodology 3 Example 4 Summary 4 The Intelligent Database for Business Intelligence Copyright 2009 Infobright Inc. All Rights Reserved
Page |2
How to Reclaim Disk Space Synopsis Infobright is designed as a “load and read” analytical database and storage engine. However, after the execution of DML activities like UPDATE and DELETE (in the Enterprise Edition of Infobright), tables can become fragmented and benefit from reloading which effectively compacts the table by removing all existence of formerly deleted record(s) and their associated delete mask(s). Introduction The shell script reorg.sh does just this for you. It can be found on Infobright’s Community web site, infobright.org, here http://www.infobright.org/Downloads/Contributed‐Software/ Methodology reorg.sh exports all data from a single, given table in binary file format, available only in the Enterprise Edition of Infobright, to the file system, performs an Infobright variation of TRUNCATE on the table, reloads the table with the Infobright Loader, and then removes the export file from the file system. In its current form, reorg.sh doesn’t perform any sanity checks such as ensuring there is enough available file system space for the export or validating that the amount of data exported matches the amount of data reloaded. (COUNT(*) output is sent to STDOUT during execution for manual validation.) It also assumes, for example, that the Infobright engine is running, that the MySQL client is named mysql‐ib (from the default installation), and that there is only one of them. But it does not assume any particular location of this file. The Intelligent Database for Business Intelligence Copyright 2009 Infobright Inc. All Rights Reserved
Page |3
How to Reclaim Disk Space Example Code sample from reorg.sh #!/bin/bash
if [ $# -ne 2 ]; then
echo “Usage: $0 <database> <table>” 1>&2
exit 2
fi
MYSQL=`locate mysql-ib`
$MYSQL << EOF
—set up environment
USE ${1};
SET @bh_dataformat=‘binary’;
—export data
SELECT COUNT(*) FROM ${2};
SELECT * FROM ${2} INTO OUTFILE ‘/tmp/${2}.bin’;
—truncate table
CREATE TABLE X LIKE ${2};
DROP TABLE ${2};
CREATE TABLE ${2} LIKE X;
DROP TABLE X;
—reload table
LOAD DATA INFILE ‘/tmp/${2}.bin’ INTO TABLE ${2};
SELECT COUNT(*) FROM ${2};
—remove export file
\! rm -f /tmp/${2}.bin
\q
EOF
exit 0 Summary Use reorg.sh to reclaim disk space in environments with high levels up UPDATE and DELETE activity and after such activities. NOTE: This is a script. Use it “as is” if you are comfortable with its current form or feel free to use it as a template for your own custom reorg utility. The Intelligent Database for Business Intelligence Copyright 2009 Infobright Inc. All Rights Reserved
Page |4