<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Data Warehouse Performance Tuning &#187; scripts</title>
	<atom:link href="http://www.atlogic.com/blog/index.php/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.atlogic.com/blog</link>
	<description>Searching for profound knowledge</description>
	<lastBuildDate>Tue, 27 Jan 2009 16:02:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>db2 list tablespaces show detail Python Script</title>
		<link>http://www.atlogic.com/blog/index.php/2009/01/27/db2-list-tablespaces-show-detail-python-script/</link>
		<comments>http://www.atlogic.com/blog/index.php/2009/01/27/db2-list-tablespaces-show-detail-python-script/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 16:02:36 +0000</pubDate>
		<dc:creator>Miguel Barrientos</dc:creator>
				<category><![CDATA[DB2]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://www.atlogic.com/blog/?p=33</guid>
		<description><![CDATA[A short time ago I needed to understand how much free space I had on each table space of a DB2 database, and I did not have access to any management tools that would have made my task easier. My only option was to run db2 list tablespaces show detail at the command line, but [...]]]></description>
			<content:encoded><![CDATA[<p>A short time ago I needed to understand how much free space I had on each table space of a DB2 database, and I did not have access to any management tools that would have made my task easier. My only option was to run <code>db2 list tablespaces show detail</code> at the command line, but the output of the command cannot be imported into Excel easily. The solution I settled on was to modify a Python script originally created to read ini files. The script is listed at the bottom of this message. To use it, pipe the output of <code>list tablespaces show detail</code> into a file. Then edit the script to read from the file. The script will output a tab-delimited list of table spaces which can be copied and pasted into Excel.</p>
<p><code>import sys<br />
import re</p>
<p>SECTION = re.compile('^\s*Tablespace ID\s*=\s*([0-9]+)\s*$')<br />
PARAM   = re.compile('^\s*(.*)\s*=\s*(.*)\s*$')<br />
COMMENT = re.compile('^\s*;.*$')</p>
<p>d = {}<br />
f = open('c:\\list_tablespaces_output.txt')<br />
for line in f:<br />
    if COMMENT.match(line): continue<br />
    m = SECTION.match(line)<br />
    if m:<br />
        section, = m.groups()<br />
        d[section.strip()] = {}<br />
    m = PARAM.match(line)<br />
    if m:<br />
        key, val = m.groups()<br />
        d[section.strip()][key.strip()] = val.strip()</p>
<p>f.close()</p>
<p>print "Name\tUsed pages\tTotal pages\tUsed pages\tFree pages\tHigh water mark (pages)\tPage size (bytes)\t% Free"<br />
for k, v  in d.items():<br />
    #print k, v<br />
    if v["Free pages"] != "Not applicable":<br />
        pctfree = float(v["Free pages"])/float(v["Total pages"])<br />
    else:<br />
        pctfree = 0</p>
<p>    print "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}".format(v["Name"]<br />
                                      ,v["Used pages"]<br />
                                      ,v["Total pages"]<br />
                                      ,v["Used pages"]<br />
                                      ,v["Free pages"]<br />
                                      ,v["High water mark (pages)"]<br />
                                      ,v["Page size (bytes)"]<br />
                                        ,pctfree)</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.atlogic.com/blog/index.php/2009/01/27/db2-list-tablespaces-show-detail-python-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
