I Cannot Access PostgreSQL At Times After Server App Upgrade

Solution 1:

There is a bug in the update process, where it doesn't migrate the previous databases because of an updated config option that prevents postgresql from launching.

Here are the steps to resolve it:

  1. Stop the postgres service:

    sudo su
    serveradmin stop postgres
    
  2. Update the configuration field:

    vim /Library/Server/PostgreSQL/Config/org.postgresql.postgres.plist
    

    replace unix_socket_directory with unix_socket_directories then save & exit

  3. Move the PostgreSQL data folder:

    mv /Library/Server/PostgreSQL/Data /Library/Server/PostgreSQL/DataOld
    
  4. Recreate the standard PostgreSQL Data folder and initialise a blank database:

    sudo -u _postgres /Applications/Server.app/Contents/ServerRoot/usr/bin/initdb /Library/Server/PostgreSQL/Data -E utf8 --lc-collate=C --lc-ctype=C
    
  5. Update the data in the blank database with data from the DataOld folder:

    sudo -u _postgres /Applications/Server.app/Contents/ServerRoot/usr/bin/pg_upgrade -b /Applications/Server.app/Contents/ServerRoot/usr/libexec/postgresql9.2 -B /Applications/Server.app/Contents/ServerRoot/usr/bin -d /Library/Server/PostgreSQL/DataOld -D /Library/Server/PostgreSQL/Data
    
  6. Restart the PostgreSQL service:

    launchctl load -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/org.postgresql.postgres.plist
    serveradmin start postgres
    

source: http://www.macambulance.co.uk/os-x-server-3-2-1-update-breaks-postgresql/