Commit 46671cbf authored by Martin Pitt's avatar Martin Pitt

* debian/supported-versions:

* pg_createcluster: Add option -p/--port to set the cluster port.
  Closes: #359249
* t/030_errors.t: Check that pg_createcluster's --port option validates the
  port number (invalid number, already used port).
* t/090_multicluster.t: Check that pg_createcluster's --port option works.
parent 91ca26c9
postgresql-common (49) unstable; urgency=low
* debian/supported-versions:
* debian/supported-versions:
- Do not fail the package installation if an unknown LSB release is
encountered; merely print a warning and assume just the latest
PostgreSQL version is supported.
- Fix Ubuntu Dapper release version (6.04 -> 6.06).
(https://launchpad.net/bugs/36921)
* pg_createcluster: Add option -p/--port to set the cluster port.
Closes: #359249
* t/030_errors.t: Check that pg_createcluster's --port option validates the
port number (invalid number, already used port).
* t/090_multicluster.t: Check that pg_createcluster's --port option works.
-- Martin Pitt <mpitt@debian.org> Tue, 28 Mar 2006 09:11:20 +0200
-- Martin Pitt <mpitt@debian.org> Tue, 28 Mar 2006 20:28:20 +0200
postgresql-common (48) unstable; urgency=low
......
......@@ -182,7 +182,8 @@ my $startconf = 'auto';
exit 1 unless GetOptions ('u|user=s' => \$owneruid, 'g|group=s' => \$ownergid,
's|socketdir=s' => \$socketdir, 'd|datadir=s' => \$datadir,
'start' => \$start, 'e|encoding=s' => \$encoding,
'l|logfile=s' => \$custom_logfile, 'start-conf=s' => \$startconf);
'l|logfile=s' => \$custom_logfile, 'start-conf=s' => \$startconf,
'p|port=i' => \$port);
# check validity of locale
unless (setlocale (LC_ALL, "")) {
......@@ -202,6 +203,7 @@ Options:
-l <dir> path to desired log file (default:
/var/log/postgresql/postgresql-<version>-<cluster>.log)
-e <encoding> Default encoding (default: derived from locale)
-p <port> port number (default: next free port starting from 5432)
--start start the cluster after creating it
--start-conf auto|manual|disabled
Set automatic startup behaviour in start.conf (default: 'auto')
......@@ -245,13 +247,26 @@ error 'cluster configuration already exists'
if -e "$confdir/postgresql.conf" || -e "$confdir/pg_hba.conf" ||
-e "$confdir/pgdata";
if (defined $port) {
error 'port must be a positive integer between 1024 and 65535'
unless $port =~ /^\d+/ && $port >= 1024 && $port <= 65535;
foreach $v (get_versions) {
foreach $c (get_version_clusters $v) {
error "port $port is already used by cluster $v/$c"
if (get_cluster_port $v, $c) == $port;
}
}
} else {
$port = next_free_port;
}
# create configuration directory
error 'could not create data directory' if system ('install', '-d', $confdir);
symlink $datadir, $pgdata;
chown $owneruid, $ownergid, $pgdata;
$port = next_free_port;
$newcluster = 0;
if (-f "$pgdata/PG_VERSION") {
......@@ -283,10 +298,6 @@ move_conffile "$datadir/postgresql.conf", $confdir, $owneruid, $ownergid, "644";
# add access for database superuser
setup_pg_hba if $newcluster;
# configure port
print "Configuring postgresql.conf to use port $port...\n";
set_cluster_port $version, $cluster, $port;
# configure socket directory
$orig_euid = $>;
$> = $owneruid;
......@@ -304,6 +315,9 @@ in postgresql.conf to a more secure directory.
set_cluster_socketdir $version, $cluster, $socketdir if $socketdir;
$> = $orig_euid;
print "Configuring postgresql.conf to use port $port...\n";
set_cluster_port $version, $cluster, $port;
# create log file
system 'mkdir', '-m', '0755', '-p', '/var/log/postgresql' and
error "could not create log directory";
......@@ -475,6 +489,13 @@ default is derived from the locale, or SQL_ASCII if that does not work. The
character sets supported by the PostgreSQL server are described in the
documentation.
=item B<-p> I<port>, B<--port> I<port>
Select the port the new cluster listens on (for the Unix socket and the TCP
port); this must be a number between 1024 and 65535, since PostgreSQL does not
run as root and thus needs an unprivileged port number. By default the next
free port starting from 5432 is assigned.
=item B<--start>
Immediately start a server for the cluster after creating it (i. e. call
......
......@@ -4,7 +4,7 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => 44;
use Test::More tests => 51;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -28,6 +28,21 @@ sub create_foo_pid {
ok ((system "pg_createcluster --socketdir '$socketdir' $version main >/dev/null") == 0,
"pg_createcluster --socketdir");
is ((get_cluster_port $version, 'main'), 5432, 'Port of created cluster is 5432');
# attempt to create clusters with an invalid port
like_program_out 0, "pg_createcluster $version test -p foo", 1,
qr/invalid.*number expected/,
'pg_createcluster -p checks that port option is numeric';
like_program_out 0, "pg_createcluster $version test -p 42", 1,
qr/must be a positive integer between/,
'pg_createcluster -p checks valid port range';
# attempt to create a cluster with an already used port
like_program_out 0, "pg_createcluster $version test -p 5432", 1,
qr/port 5432 is already used/,
'pg_createcluster -p checks that port is already used';
# chown cluster to an invalid user to test error
(system "chown -R 99 /var/lib/postgresql/$version/main") == 0 or die "chown failed: $!";
is ((system "pg_ctlcluster $version main start 2>/dev/null"), 256,
......
......@@ -10,14 +10,14 @@ use Test::More tests => 59;
# create fake socket at 5433 to verify that this port is skipped
socket (SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "socket: $!";
bind (SOCK, sockaddr_in(5434, INADDR_ANY)) || die "bind: $! ";
bind (SOCK, sockaddr_in(5433, INADDR_ANY)) || die "bind: $! ";
# create clusters
is ((system "pg_createcluster $MAJORS[0] old --start >/dev/null"), 0, "pg_createcluster $MAJORS[0] old");
is ((system "pg_createcluster $MAJORS[-1] new1 --start >/dev/null"), 0, "pg_createcluster $MAJORS[-1] new1");
is ((system "pg_createcluster $MAJORS[-1] new2 --start >/dev/null"), 0, "pg_createcluster $MAJORS[-1] new2");
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/.*5432.*5433.*5435.*/s,
'clusters have the correct ports, skipping used 5434';
is ((system "pg_createcluster $MAJORS[-1] new2 --start -p 5440 >/dev/null"), 0, "pg_createcluster $MAJORS[-1] new2");
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/.*5432.*5434.*5440.*/s,
'clusters have the correct ports, skipping used 5433';
my $old = "$MAJORS[0]/old";
my $new1 = "$MAJORS[-1]/new1";
......@@ -69,8 +69,8 @@ like_program_out 'postgres', "psql -l", 1,
delete $ENV{'PGCLUSTER'};
# check that PGPORT works
$ENV{'PGPORT'} = '5433';
is_program_out 'postgres', 'psql -Atc "show port" template1', 0, "5433\n",
$ENV{'PGPORT'} = '5434';
is_program_out 'postgres', 'psql -Atc "show port" template1', 0, "5434\n",
'PGPORT selection (1)';
$ENV{'PGPORT'} = '5432';
is_program_out 'postgres', 'psql -Atc "show port" template1', 0, "5432\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment