1 comment

  • Avatar

    When PostgreSQL is included as part of a Mac installer, you may find the following error in some machines during database initialization:

    FATAL: could not create shared memory segment:
    Cannot allocate memory
    DETAIL: Failed system call was shmget(key=1,size=1499136, 03600)

    This problem is related to the fact that some OS X systems are configured with an amount of shared memory which may not be enough to run postgreSQL depending on other applications that may be installed in the machine.

    You can workaround this by modifying kernel parameters, running the following as root:

    sysctl -w kern.sysv.shmmax=33554432
    sysctl -w kern.sysv.shmmin=1
    sysctl -w kern.sysv.shmmni=256
    sysctl -w kern.sysv.shmseg=64
    sysctl -w kern.sysv.shmall=8192

    This can be made permanent adding the following lines to /etc/sysctl.conf.


    You may consider showing a more specific error message that redirects the user to a detailed description about how to fix the issue. You can do this by checking the returned error message as follows:

          <programArguments>-E UTF8 -U postgres</programArguments>
          <text>There is not enough shared memory. PostgreSQL component requires a minimum shared memory segment 
    of 32MB. Please increase "shmmax" kernel parameter in /etc/sysctl.conf) or close any other PostgreSQL 
    instances before restarting installation. Additional information can be found in the installation guide.</text>
            <compareText text="${program_exit_code}" value="0" logic="does_not_equal" />
            <compareText text="${program_stderr}" value="Cannot allocate memory" logic="contains" />
            <compareText text="${program_exit_code}" value="0" logic="does_not_equal" />

    What EnterpriseDB includes in its readme file about shared memory is shown below:

    Shared Memory

    PostgreSQL uses shared memory extensively for caching and inter-process communication. Unfortunately, the default configuration of Mac OS X does not allow suitable amounts of shared memory to be created to run the database server.

    Before running the installation, please ensure that your system is configured to allow the use of larger amounts of shared memory. Note that this does not 'reserve' any memory so it is safe to configure much higher values than you might initially need. You can do this by editting the file /etc/sysctl.conf - e.g.

    % sudo vi /etc/sysctl.conf

    On a MacBook Pro with 2GB of RAM, the author's sysctl.conf contains:


    Note that (kern.sysv.shmall * 4096) should be greater than or equal to kern.sysv.shmmax. kern.sysv.shmmax must also be a multiple of 4096.

    Once you have edited (or created) the file, reboot before continuing with the installation. If you wish to check the settings currently being used by the kernel, you can use the sysctl utility:

    % sysctl -a

    The database server can now be installed.

    For more information on PostgreSQL's use of shared memory, please see:

Please sign in to leave a comment.