Skip to content
Snippets Groups Projects
Commit 2ade804b authored by Martin Pitt's avatar Martin Pitt
Browse files

* t/090_multicluster.t: Check that explicit port specification with

  -p/--port/$PGPORT selects the right cluster in the case of multiple
  existing clusters where none runs on the default port. This reproduces
  #517527.
* pg_wrapper: Default to latest version if -p, --port, or $PGPORT is
  specified, multiple clusters are available, and none is running on the
  default port 5432. (Closes: #517527)
parent 163c91bb
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,13 @@ postgresql-common (97) UNRELEASED; urgency=low
configuration file pg_ctl.conf, or as additional CLI arguments to
pg_ctlcluster. Add tests in t/085_pg_ctl.conf.t. Thanks to Cyril Bouthors
<cyril@bouthors.org> for the patch! (Closes: #492843)
* t/090_multicluster.t: Check that explicit port specification with
-p/--port/$PGPORT selects the right cluster in the case of multiple
existing clusters where none runs on the default port. This reproduces
#517527.
* pg_wrapper: Default to latest version if -p, --port, or $PGPORT is
specified, multiple clusters are available, and none is running on the
default port 5432. (Closes: #517527)
-- Martin Pitt <mpitt@debian.org> Sat, 28 Feb 2009 13:45:13 +0100
......
......@@ -21,8 +21,11 @@ if (defined $ENV{'PGCLUSTER'}) {
error 'No cluster specified with $PGCLUSTER' unless $cluster;
}
# Check for --cluster argument and filter it out
# Check for --cluster argument and filter it out, and check if --port is specified
my $port_specified = exists $ENV{'PGPORT'};
for (my $i = 0; $i <= $#ARGV; ++$i) {
last if $ARGV[$i] eq '--';
if ($ARGV[$i] eq '--cluster') {
error '--cluster option needs an argument (<version>/<cluster>)' if ($i >= $#ARGV);
......@@ -34,6 +37,8 @@ for (my $i = 0; $i <= $#ARGV; ++$i) {
splice @ARGV, $i, 2;
last;
}
$port_specified = 1 if $ARGV[$i] eq '--port' || $ARGV[$i] =~ /^-\w*p\w*$/;
}
# Determine $version, $cluster, $db, $port from map files
......@@ -63,6 +68,13 @@ $ENV{'PGPORT'} = $port if $port && !$ENV{'PGPORT'};
$ENV{'PGDATABASE'} = $db if $db && !$ENV{'PGDATABASE'};
$ENV{'PGHOST'} = $host if $host;
# if we only have a port, but no version here, use the latest version
# TODO: this could be improved by better argument parsing and mapping back the
# port to a cluster version/name
if (!$version and $port_specified) {
$version = get_newest_version;
}
unless ($version) {
if (get_versions) {
error 'No existing local cluster is suitable as a default target. Please see man pg_wrapper(1) how to specify one.';
......
......@@ -9,7 +9,7 @@ use Socket;
use lib '/usr/share/postgresql-common';
use PgCommon;
use Test::More tests => 117;
use Test::More tests => 127;
# Replace all md5 and password authentication methods with 'trust' in given
# pg_hba.conf file.
......@@ -268,6 +268,23 @@ like_program_out 'postgres', 'pg_lsclusters -h | sort -k3', 0, qr/.*5434.*5435.*
like_program_out 'postgres', "psql -l", 1,
qr/no.*default.*man pg_wrapper/i,
'proper pg_wrapper error message if no cluster is suitable as target';
like_program_out 'postgres', "psql -Atl --cluster $new1", 0,
qr/test\|postgres\|/,
'--cluster selects appropriate cluster';
like_program_out 'postgres', "psql -Atl -p 5434", 0,
qr/test\|postgres\|/,
'-p selects appropriate cluster';
like_program_out 'postgres', "psql -Atlp 5434", 0,
qr/test\|postgres\|/,
'-Atlp selects appropriate cluster';
like_program_out 'postgres', "psql -Atl --port 5434", 0,
qr/test\|postgres\|/,
'--port selects appropriate cluster';
like_program_out 'postgres', "env PGPORT=5434 psql -Atl", 0,
qr/test\|postgres\|/,
'$PGPORT selects appropriate cluster';
# but specifying -p explicitly should work
# restore original user_clusters
if (-f '/etc/postgresql-common/user_clusters.psqltestsuite') {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment