I just spent a couple of days trying to figure out why I couldn't start
two servers on the same port, even though I was configuring separate
listen_address values.  I kept gettting errors about shmget failing with
"could not create shared memory segment: Invalid argument".

I finally noticed that the shared memory key mentioned in the error when 
starting the second server was the same as what the first server was
 using, which appeared to be generated based off of the port number.

Sure enough when I changed the port, it used a different shared memory
key and started right up.  After searching around on the web a bit
I found some pages that suggested running under different userids
might be necessary.  So, I tried that, and changed the port back to the
standard 5432, and it started up.

Anyway, everything seems to be working fine, but I figured this info
should be a bit easier to find, so here's a couple patches to the
documentation to mention how this works.

eric
--- doc/src/sgml/config.sgml.orig       2008-10-18 00:08:50.000000000 -0500
+++ doc/src/sgml/config.sgml    2008-10-18 00:10:58.000000000 -0500
@@ -337,6 +337,12 @@
         same port number is used for all IP addresses the server listens on.
         This parameter can only be set at server start.
        </para>
+       <para>
+        This setting also determines the key used for the shared memory
+        segment.  Because of that, two servers can not be started on the
+        same port, even if they have different listen_addresses, unless
+        they are also running under two different userids.
+       </para>
       </listitem>
      </varlistentry>
 
--- doc/src/sgml/runtime.sgml.orig      2008-10-18 00:05:37.000000000 -0500
+++ doc/src/sgml/runtime.sgml   2008-10-18 00:08:37.000000000 -0500
@@ -401,6 +401,15 @@
     </para>
 
     <para>
+    You can also get this error if you try to start two servers on the
+    same machine, on the same port, even if you specify different
+    listen_address values.  In order for that configuration to work,
+    you'll need to run the servers under different userids, which will
+    cause <productname>PostgreSQL</productname> to use different
+    shared memory keys.
+       </para>
+
+    <para>
      An error like
 <screen>
 FATAL:  could not create semaphores: No space left on device
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to