~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to contrib/dbmirror/clean_pending.pl

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# clean_pending.pl
 
3
# This perl script removes entries from the pending,pendingKeys,
 
4
# pendingDeleteData tables that have already been mirrored to all hosts.
 
5
#
 
6
#
 
7
#
 
8
#    Written by Steven Singer (ssinger@navtechinc.com)
 
9
#    (c) 2001-2002 Navtech Systems Support Inc.
 
10
#    Released under the GNU Public License version 2. See COPYING.
 
11
#
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
##############################################################################
 
19
# $PostgreSQL: pgsql/contrib/dbmirror/clean_pending.pl,v 1.5 2004-09-10 04:31:06 neilc Exp $
 
20
##############################################################################
 
21
 
 
22
 
 
23
 
 
24
=head1 NAME
 
25
 
 
26
clean_pending.pl - A Perl script to remove old entries from the 
 
27
pending, pendingKeys, and pendingDeleteData tables.
 
28
 
 
29
 
 
30
=head1 SYNPOSIS
 
31
 
 
32
 
 
33
clean_pending.pl databasename
 
34
 
 
35
 
 
36
=head1 DESCRIPTION
 
37
 
 
38
 
 
39
This Perl script connects to the database specified as a command line argument
 
40
on the local system.  It uses a hard-coded username and password.
 
41
It then removes any entries from the pending, pendingDeleteData, and 
 
42
pendingKeys tables that have already been sent to all hosts in mirrorHosts.
 
43
 
 
44
 
 
45
=cut
 
46
 
 
47
BEGIN {
 
48
    # add in a global path to files
 
49
    #Ensure that Pg is in the path.
 
50
}
 
51
 
 
52
 
 
53
use strict;
 
54
use Pg;
 
55
if ($#ARGV != 0) {
 
56
   die "usage: clean_pending.pl configFile\n";
 
57
}
 
58
 
 
59
if( ! defined do $ARGV[0]) {
 
60
    die("Invalid Configuration file $ARGV[0]");
 
61
}
 
62
 
 
63
#connect to the database.
 
64
 
 
65
my $connectString = "host=$::masterHost dbname=$::masterDb user=$::masterUser password=$::masterPassword";
 
66
 
 
67
my $dbConn = Pg::connectdb($connectString);
 
68
unless($dbConn->status == PGRES_CONNECTION_OK) {
 
69
    printf("Can't connect to database\n");
 
70
    die;
 
71
}
 
72
my $result = $dbConn->exec("BEGIN");
 
73
unless($result->resultStatus == PGRES_COMMAND_OK) {
 
74
   die $dbConn->errorMessage;
 
75
}
 
76
 
 
77
 
 
78
#delete all transactions that have been sent to all mirrorhosts
 
79
#or delete everything if no mirror hosts are defined.
 
80
# Postgres takes the "SELECT COUNT(*) FROM dbmirror_MirrorHost  and makes it into
 
81
# an InitPlan.  EXPLAIN show's this.  
 
82
my $deletePendingQuery = 'DELETE FROM dbmirror_Pending WHERE (SELECT ';
 
83
$deletePendingQuery .= ' COUNT(*) FROM dbmirror_MirroredTransaction WHERE ';
 
84
$deletePendingQuery .= ' XID=dbmirror_Pending.XID) = (SELECT COUNT(*) FROM ';
 
85
$deletePendingQuery .= ' dbmirror_MirrorHost) OR (SELECT COUNT(*) FROM ';
 
86
$deletePendingQuery .= ' dbmirror_MirrorHost) = 0';
 
87
 
 
88
my $result = $dbConn->exec($deletePendingQuery);
 
89
unless ($result->resultStatus == PGRES_COMMAND_OK ) {
 
90
    printf($dbConn->errorMessage);
 
91
    die;
 
92
}
 
93
$dbConn->exec("COMMIT");
 
94
$result = $dbConn->exec('VACUUM dbmirror_Pending');
 
95
unless ($result->resultStatus == PGRES_COMMAND_OK) {
 
96
   printf($dbConn->errorMessage);
 
97
}
 
98
$result = $dbConn->exec('VACUUM dbmirror_PendingData');
 
99
unless($result->resultStatus == PGRES_COMMAND_OK) {
 
100
   printf($dbConn->errorMessage);
 
101
}
 
102
$result = $dbConn->exec('VACUUM dbmirror_MirroredTransaction');
 
103
unless($result->resultStatus == PGRES_COMMAND_OK) {
 
104
  printf($dbConn->errorMessage);
 
105
}
 
106