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