/[cricket]/parse_pg_size.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /parse_pg_size.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Sun Aug 10 11:55:06 2003 UTC revision 1.2 by dpavlin, Sun Aug 17 20:45:42 2003 UTC
# Line 7  my $host = shift @ARGV || ''; Line 7  my $host = shift @ARGV || '';
7  $host = ";host=$host" if ($host);  $host = ";host=$host" if ($host);
8  my $user = shift @ARGV || "dpavlin";  my $user = shift @ARGV || "dpavlin";
9  my $pass = shift @ARGV || "";  my $pass = shift @ARGV || "";
10    my $db = shift @ARGV;
11    
12    my @db_names;
13    
14    if ($db) {
15            push @db_names,$db;
16    } else {
17            my $sql = "select datname from pg_database where datname not like 'template%'";
18            my $dbh = DBI->connect("DBI:Pg:dbname=template1$host",$user,$pass) || die $DBI::errstr;
19            my $sth=$dbh->prepare($sql);
20    
21            $sth->execute() || die;
22            while (my ($dbname) = $sth->fetchrow_array()) {
23                    push @db_names,$dbname;
24            }
25            undef $sth;
26            $dbh->disconnect();
27    }
28    
29  my $sql = "SELECT sum(relpages) FROM pg_class";  my $sql = "SELECT sum(relpages) FROM pg_class";
30    
31  my $dbh = DBI->connect("DBI:Pg:dbname=template1$host",$user,$pass) || die $DBI::errstr;  my $sum = 0;
32  my $sth=$dbh->prepare($sql);  
33    foreach my $dbname (@db_names) {
34    
35            my $dbh = DBI->connect("DBI:Pg:dbname=$dbname$host",$user,$pass) || next;
36            my $sth=$dbh->prepare($sql);
37    
38            if ($sth->execute()) {
39                    my ($tuples) = $sth->fetchrow_array();
40    #               print STDERR "$dbname: $tuples\n";
41                    $sum += $tuples;
42            }
43    
44  if ($sth->execute()) {          undef $sth;
45          print join("\n",$sth->fetchrow_array()),"\n";          $dbh->disconnect();
46  }  }
47    
48  undef $sth;  print "$sum\n";
 $dbh->disconnect();  

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.26