--- parse_pg_size.pl 2003/08/10 11:55:06 1.1 +++ parse_pg_size.pl 2003/08/17 20:45:42 1.2 @@ -7,15 +7,42 @@ $host = ";host=$host" if ($host); my $user = shift @ARGV || "dpavlin"; my $pass = shift @ARGV || ""; +my $db = shift @ARGV; + +my @db_names; + +if ($db) { + push @db_names,$db; +} else { + my $sql = "select datname from pg_database where datname not like 'template%'"; + my $dbh = DBI->connect("DBI:Pg:dbname=template1$host",$user,$pass) || die $DBI::errstr; + my $sth=$dbh->prepare($sql); + + $sth->execute() || die; + while (my ($dbname) = $sth->fetchrow_array()) { + push @db_names,$dbname; + } + undef $sth; + $dbh->disconnect(); +} my $sql = "SELECT sum(relpages) FROM pg_class"; -my $dbh = DBI->connect("DBI:Pg:dbname=template1$host",$user,$pass) || die $DBI::errstr; -my $sth=$dbh->prepare($sql); +my $sum = 0; + +foreach my $dbname (@db_names) { + + my $dbh = DBI->connect("DBI:Pg:dbname=$dbname$host",$user,$pass) || next; + my $sth=$dbh->prepare($sql); + + if ($sth->execute()) { + my ($tuples) = $sth->fetchrow_array(); +# print STDERR "$dbname: $tuples\n"; + $sum += $tuples; + } -if ($sth->execute()) { - print join("\n",$sth->fetchrow_array()),"\n"; + undef $sth; + $dbh->disconnect(); } -undef $sth; -$dbh->disconnect(); +print "$sum\n";