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

Contents of /bin/MasterRemove

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Sun Nov 2 10:31:44 2003 UTC (20 years, 5 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +6 -0 lines
another code clean-up

1 #!/usr/bin/perl -w
2 # MasterInit
3 # Vadim Mikheev, (c) 2000, PostgreSQL Inc.
4
5 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
6 & eval 'exec perl -S $0 $argv:q'
7 if 0 ;
8
9 BEGIN {
10 my $basedir = $0; $basedir =~ s#/[^/]+$##;
11 unshift(@INC, "$basedir/../share");
12 }
13
14 use strict;
15 use Pg;
16 use Getopt::Long;
17 use RServ;
18
19 $| = 1;
20
21 my ($debug,$verbose) = (0,0);
22 my ($help,$masterhost,$masterport,$masteruser,$masterpassword);
23
24 my $result = GetOptions(
25 "debug!" => \$debug, "verbose!" => \$verbose, "help" => \$help,
26 "masterhost=s" => \$masterhost, "masterport=i" => \$masterport,
27 "masteruser=s" => \$masteruser, "masterpassword=s" => \$masterpassword,
28 );
29
30 if (defined($help) || (scalar(@ARGV) < 1)) {
31 print "Usage: $0 [options] masterdb
32 Options:
33 --masterhost=hostname --masterport=port
34 --masteruser=username --masterpassword=string
35 ";
36 exit ((scalar(@ARGV) < 1)? 1:0);
37 }
38
39 my $master = $ARGV[0] || "master";
40
41 my $minfo = MkInfo($master,$masterhost,$masterport,$masteruser,$masterpassword);
42
43 sub RollbackAndQuit {
44 my $conn = shift @_;
45
46 print STDERR "Error in query: ", $conn->errorMessage;
47 $conn->exec("ROLLBACK");
48 exit (-1);
49 }
50
51 my $conn = Pg::connectdb($minfo);
52 if ($conn->status != PGRES_CONNECTION_OK) {
53 print STDERR "Failed opening $minfo\n";
54 exit 1;
55 }
56
57 $result = $conn->exec("BEGIN");
58 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
59
60 $result = $conn->exec("set transaction isolation level serializable");
61 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
62
63 # List of slave servers
64 $result = $conn->exec("drop table _RSERV_SERVERS_");
65 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
66
67 $result = $conn->exec("DROP SEQUENCE _RSERV_SERVERS__SERVER_SEQ");
68 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
69
70 # List of replicated tables
71 #$result = $conn->exec("DROP RULE _rserv_deltrig_");
72 #RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
73
74 $result = $conn->exec("drop table _RSERV_TABLES_");
75 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
76
77 $result = $conn->exec("SELECT pgc.relname FROM pg_trigger pgt, pg_class pgc WHERE tgname='_rserv_trigger_t_' AND pgt.tgrelid=pgc.oid");
78 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_TUPLES_OK);
79 while (my @row = $result->fetchrow) {
80 my $res = $conn->exec("DROP TRIGGER _RSERV_TRIGGER_T_ ON \"$row[0]\"");
81 RollbackAndQuit($conn) if ($res->resultStatus ne PGRES_COMMAND_OK);
82 }
83
84 # Drop Human Log
85 $result = $conn->exec("DROP VIEW _RSERV_HUMAN_LOG_");
86 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
87
88 # Bookkeeping log for row replication
89 $result = $conn->exec("drop table _RSERV_LOG_");
90 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
91
92 # This is to speedup lookup of deleted tuples
93 ## should be done automatically
94 #$result = $conn->exec("drop index _RSERV_LOG_INDX_DLT_ID_");
95 #RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
96
97 # This is to speedup cleanup
98 ## should be done automatically
99 #$result = $conn->exec("drop index _RSERV_LOG_INDX_TM_ID_");
100 #RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
101
102 # This is to speedup trigger and lookup of updated tuples
103 ## should be done automatically
104 #$result = $conn->exec("drop index _RSERV_LOG_INDX_REL_KEY_");
105 #RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
106
107 # Sync point for each slave server
108 $result = $conn->exec("drop table _RSERV_SYNC_");
109 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
110
111 ## should be done automatically
112 #$result = $conn->exec("drop index _RSERV_SYNC_INDX_SRV_ID_");
113 #RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
114
115 # Sync point reference numbers
116 $result = $conn->exec("drop sequence _RSERV_SYNC_SEQ_");
117 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
118
119 $result = $conn->exec("DROP FUNCTION _rserv_log_()");
120 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
121
122 $result = $conn->exec("DROP FUNCTION _rserv_sync_(int4)");
123 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
124
125 $result = $conn->exec("DROP FUNCTION _rserv_debug_(int4)");
126 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
127
128 $result = $conn->exec("COMMIT");
129 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
130
131 exit (0);

  ViewVC Help
Powered by ViewVC 1.1.26