43 |
--slavehost=hostname --slaveport=port |
--slavehost=hostname --slaveport=port |
44 |
--slaveuser=username --slavepassword=string |
--slaveuser=username --slavepassword=string |
45 |
--slavefile=filename |
--slavefile=filename |
46 |
--tables[s]=table[,table...] |
--table[s]=table[,table...] |
47 |
"; |
"; |
48 |
# exit ((scalar(@ARGV) < 2)? 1:0); |
# exit ((scalar(@ARGV) < 2)? 1:0); |
49 |
exit; |
exit; |
119 |
$verbose = 1 if ($debug); |
$verbose = 1 if ($debug); |
120 |
|
|
121 |
# init object for scheme in master database |
# init object for scheme in master database |
122 |
my $mscheme = new Pg::Scheme( 'dbh' => $mdbh, 'DEBUG' => 0 ) || die "can't query schema"; |
my $mscheme = new Pg::Scheme( 'dbh' => $mdbh, 'DEBUG' => 0 ) || die "can't query master schema"; |
123 |
|
my $sscheme = new Pg::Scheme( 'dbh' => $sdbh, 'DEBUG' => 0 ) || die "can't query slave schema"; |
124 |
|
|
125 |
# which tables to compare? |
# which tables to compare? |
126 |
|
|
128 |
|
|
129 |
debug "Comparing tables: ".join(", ",@tables)."\n"; |
debug "Comparing tables: ".join(", ",@tables)."\n"; |
130 |
|
|
131 |
|
# start transaction |
132 |
|
print "begin work;\n"; |
133 |
|
|
134 |
|
# disable active triggers on slave database |
135 |
|
my @triggers = $sscheme->get_activetriggers(); |
136 |
|
|
137 |
|
foreach my $tr (@triggers) { |
138 |
|
print "update pg_trigger set tgenabled = false where tgname='$tr';\n"; |
139 |
|
} |
140 |
|
|
141 |
my $cols; |
my $cols; |
142 |
my $diff_total = 0; |
my $diff_total = 0; |
143 |
|
|
145 |
|
|
146 |
my $sth; |
my $sth; |
147 |
|
|
148 |
|
print "-- schema...\n"; |
149 |
# diff schema |
# diff schema |
150 |
|
foreach my $row (@{$mscheme->pg_attribute($table)}) { |
151 |
|
# print Dumper($row); |
152 |
|
} |
153 |
|
|
154 |
|
print "-- constraints...\n"; |
155 |
|
# diff constraints |
156 |
|
foreach my $tr (@{$mscheme->triggers($table)}) { |
157 |
|
# print Dumper($tr); |
158 |
|
} |
159 |
|
print "-- triggers...\n"; |
160 |
|
# diff triggers |
161 |
|
foreach my $tr (@{$mscheme->triggers($table)}) { |
162 |
|
# print Dumper($tr); |
163 |
|
} |
164 |
|
|
165 |
# all colums (for insert) |
# all colums (for insert) |
166 |
my @cols = @{$mscheme->cols($table)}; |
my @cols = @{$mscheme->cols($table)}; |
181 |
my @cols_test; # all colums to test (without skipped) |
my @cols_test; # all colums to test (without skipped) |
182 |
|
|
183 |
foreach my $row (@{$mscheme->pg_attribute($table)}) { |
foreach my $row (@{$mscheme->pg_attribute($table)}) { |
184 |
# attname | format_type | attnotnull | atthasdef | attnum |
# attname format_type attnotnull atthasdef attnum default references |
185 |
|
|
186 |
# FIXME: do something with attributes which shouldn't be compared |
# FIXME: do something with attributes which shouldn't be compared |
187 |
# (date, time, datetime, timestamp) |
# (date, time, datetime, timestamp) |
245 |
|
|
246 |
debug_sql($msql); |
debug_sql($msql); |
247 |
|
|
248 |
my $msth = $mdbh->prepare($msql) || die; |
my $msth = $mdbh->prepare($msql) || die $mdbh->errstr; |
249 |
$msth->execute() || die; |
$msth->execute() || die $msth->errstr; |
250 |
|
|
251 |
my $ssth = $sdbh->prepare($ssql) || die; |
my $ssth = $sdbh->prepare($ssql) || die $sdbh->errstr; |
252 |
$ssth->execute() || die; |
$ssth->execute() || die $ssth->errstr; |
253 |
|
|
254 |
my $diff_row = 0; |
my $diff_row = 0; |
255 |
|
|
415 |
} |
} |
416 |
} |
} |
417 |
|
|
418 |
|
# enable triggers again on slave |
419 |
|
foreach my $tr (@triggers) { |
420 |
|
print "update pg_trigger set tgenabled = true where tgname='$tr';\n"; |
421 |
|
} |
422 |
|
# end transaction |
423 |
|
print "commit;\n"; |
424 |
|
|
425 |
$mdbh->disconnect(); |
$mdbh->disconnect(); |
426 |
$sdbh->disconnect(); |
$sdbh->disconnect(); |