/System/Library/LaunchDaemons/com.apple.servermgrd.plist Is Missing - Causing postgres to not start properly

Solution 1:

"Invalid or missing service identifier" seems to mean that your plist file has not got or has misspelled a section like

<key>Label</key>
<string>com.foo.bar</string>

Note "Label" must start with upper case L.

Solution 2:

Starting with OS X Server version 4.0 it seems like Apple doesn't want us to use the built-in PostgreSQL:

The Postgres database used by OS X Server is only intended for use with service data used by the system. Avoid adding custom content to this database. If you’d like to run Postgres on your OS X Server, you should download and install your own instance.

But there is still a way to use it. Use the following commands in Terminal:

sudo mkdir -p /Library/Server/PostgreSQL/Config
sudo chown -R _postgres:_postgres /Library/Server/PostgreSQL
sudo -u _postgres vim /Library/Server/PostgreSQL/Config/org.postgresql.postgres.plist

then copy, paste and save this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ProgramArguments</key>
    <array>
        <string>-D</string>
        <string>/Library/Server/PostgreSQL/Data</string>
        <string>-c</string>
        <string>listen_addresses=127.0.0.1,::1</string>
        <string>-c</string>
        <string>log_connections=on</string>
        <string>-c</string>
        <string>log_directory=/Library/Logs/PostgreSQL</string>
        <string>-c</string>
        <string>log_filename=PostgreSQL.log</string>
        <string>-c</string>
        <string>log_line_prefix=%t </string>
        <string>-c</string>
        <string>log_lock_waits=on</string>
        <string>-c</string>
        <string>log_statement=ddl</string>
        <string>-c</string>
        <string>logging_collector=on</string>
        <string>-c</string>
        <string>unix_socket_directories=/private/var/pgsql_socket</string>
        <string>-c</string>
        <string>unix_socket_group=_postgres</string>
        <string>-c</string>
        <string>unix_socket_permissions=0770</string>
    </array>
</dict>
</plist>

Also edit

sudo vim /System/Library/LaunchDaemons/org.postgresql.postgres.plist

then copy and paste this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <true/>
    <key>Label</key>
    <string>org.postgresql.postgres</string>
    <key>UserName</key>
    <string>_postgres</string>
    <key>GroupName</key>
    <string>_postgres</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Applications/Server.app/Contents/ServerRoot/usr/bin/postgres</string>
        <string>--apple-configuration</string>
        <string>/Library/Server/PostgreSQL/Config/org.postgresql.postgres.plist</string>
    </array>
    <key>OnDemand</key>
    <false/>
    <key>StandardErrorPath</key>
    <string>/Library/Logs/PostgreSQL/PostgreSQL.log</string>
    <key>StandardOutPath</key>
    <string>/Library/Logs/PostgreSQL/PostgreSQL.log</string>
</dict>
</plist>

To install do

sudo launchctl load -w /System/Library/LaunchDaemons/org.postgresql.postgres.plist
sudo -u _postgres psql postgres

and Postgres will greet you with

psql (9.3.5)
Type "help" for help.
postgres=#