|
47 | 47 | exit 1;
|
48 | 48 | }
|
49 | 49 |
|
50 |
| -my $script_version="0.0.11"; |
| 50 | +my $script_version="0.0.12"; |
51 | 51 | my $script_name="postgresqltuner.pl";
|
52 | 52 | my $min_s=60;
|
53 | 53 | my $hour_s=60*$min_s;
|
|
62 | 62 | my $pgpassfile=$ENV{HOME}.'/.pgpass';
|
63 | 63 | my $help=0;
|
64 | 64 | my $work_mem_per_connection_percent=150;
|
| 65 | +my @Ssh_opts=('BatchMode=yes'); |
65 | 66 | GetOptions (
|
66 | 67 | "host=s" => \$host,
|
67 | 68 | "user=s" => \$username,
|
|
73 | 74 | "port=i" => \$port,
|
74 | 75 | "help" => \$help,
|
75 | 76 | "wmp=i" => \$work_mem_per_connection_percent,
|
| 77 | + "sshopt=s" => \@Ssh_opts |
76 | 78 | ) or usage(1);
|
77 | 79 |
|
78 | 80 | print "$script_name version $script_version\n";
|
79 | 81 | if ($help) {
|
80 | 82 | usage(0);
|
81 | 83 | }
|
82 | 84 |
|
| 85 | +# ssh options |
| 86 | +my $ssh_opts=''; |
| 87 | +foreach my $ssh_opt (@Ssh_opts) { |
| 88 | + $ssh_opts.=' -o '.$ssh_opt; |
| 89 | +} |
| 90 | + |
83 | 91 | # host
|
84 | 92 | if (!defined($host)) {
|
85 | 93 | if (defined($ENV{PGHOST})) {
|
|
141 | 149 | }
|
142 | 150 | close(PGPASS);
|
143 | 151 | }
|
| 152 | + |
| 153 | + # default |
| 154 | + if (!defined($password)) { |
| 155 | + $password=''; |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +if (!defined($host)) { |
| 160 | + print STDERR "Missing host\n"; |
| 161 | + print STDERR "\tset \$PGHOST environnement variable\n"; |
| 162 | + print STDERR "or\tadd --host option\n"; |
| 163 | + usage(1); |
| 164 | +} |
| 165 | + |
| 166 | +if (!defined($username)) { |
| 167 | + print STDERR "Missing username\n"; |
| 168 | + print STDERR "\tset \$PGUSER environnement variable\n"; |
| 169 | + print STDERR "or\tadd --user option\n"; |
| 170 | + usage(1); |
144 | 171 | }
|
145 | 172 |
|
146 |
| -usage(1) if (!defined($host) or !defined($username) or !defined($password)); |
| 173 | +if (!defined($password)) { |
| 174 | + print STDERR "Missing password\n"; |
| 175 | + print STDERR "\tconfigure ~/.pgpass\n"; |
| 176 | + print STDERR "or\tset \$PGPASSWORD environnement variable\n"; |
| 177 | + print STDERR "or\tadd --password option\n"; |
| 178 | + usage(1); |
| 179 | +} |
147 | 180 |
|
148 | 181 | sub usage {
|
149 | 182 | my $return=shift;
|
150 | 183 | print STDERR "usage: $script_name --host [ hostname | /var/run/postgresql ] [--user username] [--password password] [--database database] [--port port] [--wmp 150]\n";
|
| 184 | + print STDERR "\t[--sshopt=Name=Value]...\n"; |
151 | 185 | print STDERR "If available connection informations can be read from \$PGHOST, \$PGPORT, \$PGDATABASE, \$PGUSER, \$PGPASSWORD\n";
|
152 | 186 | print STDERR "For security reasons, prefer usage of password in ~/.pgpass\n";
|
153 | 187 | print STDERR "\thost:port:database:username:password\n";
|
154 | 188 | print STDERR " --wmp: average number of work_mem buffers per connection in percent (default 150)\n";
|
| 189 | + print STDERR " --sshopt: pass options to ssh (example --sshopt=Port=2200)\n"; |
155 | 190 | exit $return;
|
156 | 191 | }
|
157 | 192 |
|
@@ -189,7 +224,7 @@ sub usage {
|
189 | 224 | } elsif ($host =~ /^127\.[0-9]+\.[0-9]+\.[0-9]+$/) {
|
190 | 225 | $os_cmd_prefix='';
|
191 | 226 | } elsif ($host =~ /^[a-zA-Z0-9.-]+$/) {
|
192 |
| - $os_cmd_prefix="ssh -o BatchMode=yes $host "; |
| 227 | + $os_cmd_prefix="ssh $ssh_opts $host "; |
193 | 228 | } else {
|
194 | 229 | die("Invalid host $host");
|
195 | 230 | }
|
|
0 commit comments