| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Pgtools::Config_diff; |
|
2
|
1
|
|
|
1
|
|
41781
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
336
|
use Pgtools; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
1
|
|
|
1
|
|
295
|
use Pgtools::Conf; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Pgtools::Connection; |
|
8
|
|
|
|
|
|
|
use List::MoreUtils qw(uniq); |
|
9
|
|
|
|
|
|
|
use parent qw(Class::Accessor); |
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(argv)); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub exec { |
|
13
|
|
|
|
|
|
|
my $self = shift; |
|
14
|
|
|
|
|
|
|
my $default = { |
|
15
|
|
|
|
|
|
|
"host" => "localhost", |
|
16
|
|
|
|
|
|
|
"port" => "5432", |
|
17
|
|
|
|
|
|
|
"user" => "postgres", |
|
18
|
|
|
|
|
|
|
"password" => "", |
|
19
|
|
|
|
|
|
|
"database" => "postgres" |
|
20
|
|
|
|
|
|
|
}; |
|
21
|
|
|
|
|
|
|
my @dbs, my @confs; |
|
22
|
|
|
|
|
|
|
my $db_cnt = scalar(@{$self->argv}); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
for(my $i=0; $i<$db_cnt; $i++) { |
|
25
|
|
|
|
|
|
|
my $db = Pgtools::Connection->new($default); |
|
26
|
|
|
|
|
|
|
$db->set_args($self->argv->[$i]); |
|
27
|
|
|
|
|
|
|
$db->create_connection(); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $c = get_db_config($self, $db); |
|
30
|
|
|
|
|
|
|
my $v = get_db_version($self, $db); |
|
31
|
|
|
|
|
|
|
my $obj = { |
|
32
|
|
|
|
|
|
|
"version" => $v, |
|
33
|
|
|
|
|
|
|
"items" => $c |
|
34
|
|
|
|
|
|
|
}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
push(@dbs, $db); |
|
37
|
|
|
|
|
|
|
push(@confs, Pgtools::Conf->new($obj)); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$db->dbh->disconnect; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $is_different = &check_version(\@confs); |
|
43
|
|
|
|
|
|
|
&warn_difference() if $is_different == 1;; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $diff_keys = &get_different_keys(\@confs); |
|
46
|
|
|
|
|
|
|
if(scalar(@$diff_keys) == 0) { |
|
47
|
|
|
|
|
|
|
print "There is no differenct settings.\n" ; |
|
48
|
|
|
|
|
|
|
return; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
&print_difference(\@confs, \@dbs, $diff_keys); |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub check_version { |
|
54
|
|
|
|
|
|
|
my $confs = shift @_; |
|
55
|
|
|
|
|
|
|
my $version = @$confs[0]->version; |
|
56
|
|
|
|
|
|
|
for(my $i=1; $i<scalar(@_); $i++) { |
|
57
|
|
|
|
|
|
|
if($version ne @$confs[$i]->version) { |
|
58
|
|
|
|
|
|
|
return 1; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
return 0; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub warn_difference { |
|
65
|
|
|
|
|
|
|
print "************************\n"; |
|
66
|
|
|
|
|
|
|
print " Different Version !! \n"; |
|
67
|
|
|
|
|
|
|
print "************************\n"; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_different_keys { |
|
71
|
|
|
|
|
|
|
my $confs = shift @_; |
|
72
|
|
|
|
|
|
|
my $db_cnt = scalar(@$confs); |
|
73
|
|
|
|
|
|
|
my $tmp, my $tmp_item; |
|
74
|
|
|
|
|
|
|
my @keys, my @diff_keys; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
for(my $i=0; $i<$db_cnt; $i++) { |
|
77
|
|
|
|
|
|
|
$tmp = @$confs[$i]->items; |
|
78
|
|
|
|
|
|
|
push(@keys, keys(%$tmp)); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
@keys = uniq(@keys); |
|
81
|
|
|
|
|
|
|
@keys = sort(@keys); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
for my $key (@keys) { |
|
84
|
|
|
|
|
|
|
for(my $i=0; $i<$db_cnt; $i++) { |
|
85
|
|
|
|
|
|
|
if(!defined @$confs[$i]->items->{$key}){ |
|
86
|
|
|
|
|
|
|
@$confs[$i]->items->{$key} = ""; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$tmp_item = @$confs[0]->items->{$key}; |
|
91
|
|
|
|
|
|
|
for(my $i=1; $i<$db_cnt; $i++) { |
|
92
|
|
|
|
|
|
|
if($tmp_item ne @$confs[$i]->items->{$key}) { |
|
93
|
|
|
|
|
|
|
push(@diff_keys, $key); |
|
94
|
|
|
|
|
|
|
last; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
return \@diff_keys; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub print_difference { |
|
102
|
|
|
|
|
|
|
my ($confs, $dbs, $diff_keys) = @_; |
|
103
|
|
|
|
|
|
|
my $db_cnt = scalar(@$confs); |
|
104
|
|
|
|
|
|
|
my $key_cnt = scalar(@$diff_keys); |
|
105
|
|
|
|
|
|
|
printf("<Setting Name> "); |
|
106
|
|
|
|
|
|
|
for(my $j=0; $j<$db_cnt; $j++) { |
|
107
|
|
|
|
|
|
|
printf("%-24s", @$dbs[$j]->host); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
printf("\n--------------------"); |
|
110
|
|
|
|
|
|
|
for(my $j=0; $j<$db_cnt; $j++) { |
|
111
|
|
|
|
|
|
|
printf("------------------------"); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
printf("\n"); |
|
114
|
|
|
|
|
|
|
for(my $i=0; $i<$key_cnt; $i++) { |
|
115
|
|
|
|
|
|
|
my $key = @$diff_keys[$i]; |
|
116
|
|
|
|
|
|
|
printf("%-24s ", $key); |
|
117
|
|
|
|
|
|
|
for(my $j=0; $j<$db_cnt; $j++) { |
|
118
|
|
|
|
|
|
|
printf("%-23s ", @$confs[$j]->items->{$key}); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
printf("\n"); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub get_db_config { |
|
125
|
|
|
|
|
|
|
my ($self, $db) = @_; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $sth = $db->dbh->prepare("SELECT name, setting FROM pg_settings"); |
|
128
|
|
|
|
|
|
|
$sth->execute(); |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $items = {}; |
|
131
|
|
|
|
|
|
|
while (my $hash_ref = $sth->fetchrow_hashref) { |
|
132
|
|
|
|
|
|
|
my %row = %$hash_ref; |
|
133
|
|
|
|
|
|
|
$items = {%{$items}, $row{name} => $row{setting}}; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
$sth->finish; |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return $items; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub get_db_version { |
|
141
|
|
|
|
|
|
|
my ($self, $db) = @_; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $sth = $db->dbh->prepare("SELECT version()"); |
|
144
|
|
|
|
|
|
|
$sth->execute(); |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my $ref = $sth->fetchrow_arrayref; |
|
147
|
|
|
|
|
|
|
my @v = split(/ /, @$ref[0], -1); |
|
148
|
|
|
|
|
|
|
$sth->finish; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
return $v[1]; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
|
155
|
|
|
|
|
|
|
|