#pragma ident "%Z%%M% %I% %E% SMI"
# Run this TCL script using "testfixture" in order get a report that shows
# how much disk space is used by a particular data to actually store data
# versus how much space is unused.
#
# Get the name of the database to analyze
#
puts stderr "Usage: $argv0 database-name"
exit 1
}
# Open the database
#
# Output the schema for the generated report
#
puts \
{BEGIN;
);}
# This query will be used to find the root page number for every index and
# table in the database.
#
set sql {
}
# Initialize variables used for summary statistics.
#
set total_size 0
set total_primary 0
set total_overflow 0
set total_unused_ovfl 0
# Analyze every table in the database, one at a time.
#
catch {unset pg_used}
set unused_ovfl 0
set n_overflow 0
while {$go==0} {
incr n_overflow $n
}
}
set unused_primary 0
puts -nonewline "INSERT INTO space_used VALUES('$name'"
puts ",$size,$n_primary,$n_overflow,$unused_primary,$unused_ovfl);"
incr total_size $size
incr total_primary $n_primary
incr total_overflow $n_overflow
incr total_unused_ovfl $unused_ovfl
}
# Output summary statistics:
#
puts "-- Total payload size: $total_size"
puts "-- Total pages used: $total_primary primary and $total_overflow overflow"
puts -nonewline "-- Total unused bytes on primary pages: $total_unused_primary"
if {$total_primary>0} {
} else {
puts ""
}
puts -nonewline "-- Total unused bytes on overflow pages: $total_unused_ovfl"
if {$total_overflow>0} {
} else {
puts ""
}
puts "-- Total pages on freelist: $n_free"
puts "COMMIT;"