diff options
author | Tom Lane | 2017-11-17 17:46:52 +0000 |
---|---|---|
committer | Tom Lane | 2017-11-17 17:46:52 +0000 |
commit | ac3b9626812b1dd1482ec201711f26af733800f9 (patch) | |
tree | 72073a23800bb13c737493ec80a028bcc0ba58d5 | |
parent | e87d4965bd39e4d0d56346c1bbe9361d3eb9ff0a (diff) |
Provide modern examples of how to auto-start Postgres on macOS.
The scripts in contrib/start-scripts/osx don't work at all on macOS
10.10 (Yosemite) or later, because they depend on SystemStarter which
Apple deprecated long ago and removed in 10.10. Add a new subdirectory
contrib/start-scripts/macos with scripts that use the newer launchd
infrastructure.
Since this problem is independent of which Postgres version you're using,
back-patch to all supported branches.
Discussion: https://postgr.es/m/[email protected]
-rw-r--r-- | contrib/start-scripts/macos/README | 24 | ||||
-rw-r--r-- | contrib/start-scripts/macos/org.postgresql.postgres.plist | 17 | ||||
-rw-r--r-- | contrib/start-scripts/macos/postgres-wrapper.sh | 25 | ||||
-rw-r--r-- | contrib/start-scripts/osx/README | 5 |
4 files changed, 71 insertions, 0 deletions
diff --git a/contrib/start-scripts/macos/README b/contrib/start-scripts/macos/README new file mode 100644 index 00000000000..c4f2d9a270c --- /dev/null +++ b/contrib/start-scripts/macos/README @@ -0,0 +1,24 @@ +To make macOS automatically launch your PostgreSQL server at system start, +do the following: + +1. Edit the postgres-wrapper.sh script and adjust the file path +variables at its start to reflect where you have installed Postgres, +if that's not /usr/local/pgsql. + +2. Copy the modified postgres-wrapper.sh script into some suitable +installation directory. It can be, but doesn't have to be, where +you keep the Postgres executables themselves. + +3. Edit the org.postgresql.postgres.plist file and adjust its path +for postgres-wrapper.sh to match what you did in step 2. Also, +if you plan to run the Postgres server under some user name other +than "postgres", adjust the UserName parameter value for that. + +4. Copy the modified org.postgresql.postgres.plist file into +/Library/LaunchDaemons/. You must do this as root: + sudo cp org.postgresql.postgres.plist /Library/LaunchDaemons +because the file will be ignored if it is not root-owned. + +At this point a reboot should launch the server. But if you want +to test it without rebooting, you can do + sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist diff --git a/contrib/start-scripts/macos/org.postgresql.postgres.plist b/contrib/start-scripts/macos/org.postgresql.postgres.plist new file mode 100644 index 00000000000..fdbd74f27d4 --- /dev/null +++ b/contrib/start-scripts/macos/org.postgresql.postgres.plist @@ -0,0 +1,17 @@ +<?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>Label</key> + <string>org.postgresql.postgres</string> + <key>ProgramArguments</key> + <array> + <string>/bin/sh</string> + <string>/usr/local/pgsql/bin/postgres-wrapper.sh</string> + </array> + <key>UserName</key> + <string>postgres</string> + <key>KeepAlive</key> + <true/> +</dict> +</plist> diff --git a/contrib/start-scripts/macos/postgres-wrapper.sh b/contrib/start-scripts/macos/postgres-wrapper.sh new file mode 100644 index 00000000000..3a4ebdaf0fb --- /dev/null +++ b/contrib/start-scripts/macos/postgres-wrapper.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# PostgreSQL server start script (launched by org.postgresql.postgres.plist) + +# edit these as needed: + +# directory containing postgres executable: +PGBINDIR="/usr/local/pgsql/bin" +# data directory: +PGDATA="/usr/local/pgsql/data" +# file to receive postmaster's initial log messages: +PGLOGFILE="${PGDATA}/pgstart.log" + +# (it's recommendable to enable the Postgres logging_collector feature +# so that PGLOGFILE doesn't grow without bound) + + +# set umask to ensure PGLOGFILE is not created world-readable +umask 077 + +# wait for networking to be up (else server may not bind to desired ports) +/usr/sbin/ipconfig waitall + +# and launch the server +exec "$PGBINDIR"/postgres -D "$PGDATA" >>"$PGLOGFILE" 2>&1 diff --git a/contrib/start-scripts/osx/README b/contrib/start-scripts/osx/README index 97e299f7da6..9faf5a4a1c1 100644 --- a/contrib/start-scripts/osx/README +++ b/contrib/start-scripts/osx/README @@ -1,3 +1,8 @@ +The scripts in this directory are for use with Apple's SystemStarter +infrastructure, which is deprecated since macOS 10.4 and is gone entirely +as of 10.10. You should use the scripts in ../macos instead, unless +you are using a macOS release too old to have launchd. + To install execute the following: sudo /bin/sh ./install.sh |