/[rserv]/bin/MasterInit
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 /bin/MasterInit

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Wed Dec 20 17:22:35 2000 UTC (23 years, 5 months ago) by dpavlin
Branch: MAIN
Branch point for: DbP
Initial revision

1 dpavlin 1.1 # -*- perl -*-
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     use Pg;
10     use Getopt::Long;
11    
12     $| = 1;
13    
14     $result = GetOptions("debug!", "verbose!", "help",
15     "host=s", "user=s", "password=s");
16    
17     my $debug = $opt_debug || 0;
18     my $verbose = $opt_verbose || 0;
19    
20     if (defined($opt_help) || (scalar(@ARGV) < 1)) {
21     print "Usage: $0 --host=name --user=name --password=string masterdb\n";
22     exit ((scalar(@ARGV) < 1)? 1:0);
23     }
24    
25     my $master = $ARGV[0] || "master";
26    
27     my $minfo = "dbname=$master";
28     $minfo = "$minfo host=$opt_host" if (defined($opt_host));
29     $minfo = "$minfo user=$opt_user" if (defined($opt_user));
30     $minfo = "$minfo password=$opt_password" if (defined($opt_password));
31    
32     sub RollbackAndQuit {
33     $conn = shift @_;
34    
35     print STDERR "Error in query: ", $conn->errorMessage;
36     $conn->exec("ROLLBACK");
37     exit (-1);
38     }
39    
40     my $conn = Pg::connectdb($minfo);
41     if ($conn->status != PGRES_CONNECTION_OK) {
42     print STDERR "Failed opening $minfo\n";
43     exit 1;
44     }
45    
46     my $result = $conn->exec("BEGIN");
47     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
48    
49     $result = $conn->exec("set transaction isolation level serializable");
50     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
51    
52     # List of slave servers
53     $result = $conn->exec("create table _RSERV_SERVERS_" .
54     " (server serial, host text, post int4, dbase text)");
55     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
56    
57     # List of replicated tables
58     $result = $conn->exec("create table _RSERV_TABLES_" .
59     " (tname name, cname name, reloid oid, key int4)");
60     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
61    
62     # Bookkeeping log for row replication
63     $result = $conn->exec("create table _RSERV_LOG_" .
64     " (reloid oid, logid int4, logtime timestamp, deleted int4, key text)");
65     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
66    
67     # This is to speedup lookup of deleted tuples
68     $result = $conn->exec("create index _RSERV_LOG_INDX_DLT_ID_ on _RSERV_LOG_ (deleted, logid)");
69     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
70    
71     # This is to speedup cleanup
72     $result = $conn->exec("create index _RSERV_LOG_INDX_TM_ID_ on _RSERV_LOG_ (logtime, logid)");
73     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
74    
75     # This is to speedup trigger and lookup of updated tuples
76     $result = $conn->exec("create index _RSERV_LOG_INDX_REL_KEY_ on _RSERV_LOG_ (reloid, key)");
77     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
78    
79     # Sync point for each slave server
80     $result = $conn->exec("create table _RSERV_SYNC_" .
81     " (server int4, syncid int4, synctime timestamp" .
82     ", status int4, minid int4, maxid int4, active text)");
83     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
84    
85     $result = $conn->exec("create index _RSERV_SYNC_INDX_SRV_ID_ on _RSERV_SYNC_ (server, syncid)");
86     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
87    
88     # Sync point reference numbers
89     $result = $conn->exec("create sequence _rserv_sync_seq_");
90     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
91    
92     $result = $conn->exec("CREATE FUNCTION _rserv_log_() RETURNS opaque" .
93     " AS '_OBJWD_/rserv_DLSUFFIX_' LANGUAGE 'c'");
94     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
95    
96     $result = $conn->exec("CREATE FUNCTION _rserv_sync_(int4) RETURNS int4" .
97     " AS '_OBJWD_/rserv_DLSUFFIX_' LANGUAGE 'c'");
98     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
99    
100     $result = $conn->exec("CREATE FUNCTION _rserv_debug_(int4) RETURNS int4" .
101     " AS '_OBJWD_/rserv_DLSUFFIX_' LANGUAGE 'c'");
102     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
103    
104     $result = $conn->exec("COMMIT");
105     RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
106    
107     exit (0);

  ViewVC Help
Powered by ViewVC 1.1.26