/[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

Annotation of /parse_pg_size.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Sun Aug 17 20:45:42 2003 UTC (20 years, 7 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +33 -6 lines
File MIME type: text/plain
don't count only template1 database tuples!

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     use strict;
4     use DBI;
5    
6     my $host = shift @ARGV || '';
7     $host = ";host=$host" if ($host);
8     my $user = shift @ARGV || "dpavlin";
9     my $pass = shift @ARGV || "";
10 dpavlin 1.2 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 dpavlin 1.1
29     my $sql = "SELECT sum(relpages) FROM pg_class";
30    
31 dpavlin 1.2 my $sum = 0;
32    
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 dpavlin 1.1
44 dpavlin 1.2 undef $sth;
45     $dbh->disconnect();
46 dpavlin 1.1 }
47    
48 dpavlin 1.2 print "$sum\n";

  ViewVC Help
Powered by ViewVC 1.1.26