Package: postgresql-common
Version: 94
Severity: Serious

pg_ctlcluster conflicts with instances with the same configured port, but different listen_addresses and unix_socket_directory:

$ grep port db*/postgresql*
db2/postgresql.conf:port = 5432
db/postgresql.conf:port = 5432

$ grep listen_addresses db*/postgresql*
db2/postgresql.conf:listen_addresses = '192.168.0.111'
db/postgresql.conf:listen_addresses = 'localhost'

$ grep unix_socket_directory db*/postgresql*
db2/postgresql.conf:unix_socket_directory = '/var/run/postgresql/8.3/db2'
db/postgresql.conf:unix_socket_directory = '/var/run/postgresql/8.3/db'

The culprit seems to be cluster_port_running(), called by pg_ctlcluster in the subroutine start(), to make sure the specified unix socket is not accidently used by another running instance:

[...]
   # check conflicting port
   foreach my $v (get_versions) {
       foreach my $c (get_version_clusters $v) {
error("Port conflict: cluster $v/$c is already running on port " . $info{'port'}) if cluster_port_running $v, $c, $info{'port'};
       }
   }
[...]

This makes it impossible to use several instances on different listen_addresses with the same port number. It seems to me the whole check is far too harsh anyways: it might be sufficient to check against the current unix socket directory only. If the connect() to this unix socket succeeds, then there is another instance using this unix socket already. I propose the following patch to fix the behavior of pg_ctlcluster:

diff --git a/pg_ctlcluster b/pg_ctlcluster
index 531e6b2..335e4f4 100755
--- a/pg_ctlcluster
+++ b/pg_ctlcluster
@@ -244,11 +244,12 @@ sub start {
    start_check_pid_file;

    # check conflicting port
-    foreach my $v (get_versions) {
-        foreach my $c (get_version_clusters $v) {
- error("Port conflict: cluster $v/$c is already running on port " . - $info{'port'}) if cluster_port_running $v, $c, $info{'port'};
-        }
+    if (cluster_port_running $version, $cluster, $info{'port'}) {
+
+ my $sockdir = PgCommon::get_conf_value $version, $cluster, 'postgresql.conf',
+                                              'unix_socket_directory';
+ error("Port conflict: another instance is already running on ".$sockdir." with port ".$info{'port'});
+
    }

    # get locale used by initdb

--
Regards

Bernd Helmle




--
To UNSUBSCRIBE, email to debian-bugs-rc-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to