Skip to content

Commit ac3b962

Browse files
committed
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/31338.1510763554@sss.pgh.pa.us
1 parent e87d496 commit ac3b962

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

contrib/start-scripts/macos/README

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
To make macOS automatically launch your PostgreSQL server at system start,
2+
do the following:
3+
4+
1. Edit the postgres-wrapper.sh script and adjust the file path
5+
variables at its start to reflect where you have installed Postgres,
6+
if that's not /usr/local/pgsql.
7+
8+
2. Copy the modified postgres-wrapper.sh script into some suitable
9+
installation directory. It can be, but doesn't have to be, where
10+
you keep the Postgres executables themselves.
11+
12+
3. Edit the org.postgresql.postgres.plist file and adjust its path
13+
for postgres-wrapper.sh to match what you did in step 2. Also,
14+
if you plan to run the Postgres server under some user name other
15+
than "postgres", adjust the UserName parameter value for that.
16+
17+
4. Copy the modified org.postgresql.postgres.plist file into
18+
/Library/LaunchDaemons/. You must do this as root:
19+
sudo cp org.postgresql.postgres.plist /Library/LaunchDaemons
20+
because the file will be ignored if it is not root-owned.
21+
22+
At this point a reboot should launch the server. But if you want
23+
to test it without rebooting, you can do
24+
sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key>
6+
<string>org.postgresql.postgres</string>
7+
<key>ProgramArguments</key>
8+
<array>
9+
<string>/bin/sh</string>
10+
<string>/usr/local/pgsql/bin/postgres-wrapper.sh</string>
11+
</array>
12+
<key>UserName</key>
13+
<string>postgres</string>
14+
<key>KeepAlive</key>
15+
<true/>
16+
</dict>
17+
</plist>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
# PostgreSQL server start script (launched by org.postgresql.postgres.plist)
4+
5+
# edit these as needed:
6+
7+
# directory containing postgres executable:
8+
PGBINDIR="/usr/local/pgsql/bin"
9+
# data directory:
10+
PGDATA="/usr/local/pgsql/data"
11+
# file to receive postmaster's initial log messages:
12+
PGLOGFILE="${PGDATA}/pgstart.log"
13+
14+
# (it's recommendable to enable the Postgres logging_collector feature
15+
# so that PGLOGFILE doesn't grow without bound)
16+
17+
18+
# set umask to ensure PGLOGFILE is not created world-readable
19+
umask 077
20+
21+
# wait for networking to be up (else server may not bind to desired ports)
22+
/usr/sbin/ipconfig waitall
23+
24+
# and launch the server
25+
exec "$PGBINDIR"/postgres -D "$PGDATA" >>"$PGLOGFILE" 2>&1

contrib/start-scripts/osx/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
The scripts in this directory are for use with Apple's SystemStarter
2+
infrastructure, which is deprecated since macOS 10.4 and is gone entirely
3+
as of 10.10. You should use the scripts in ../macos instead, unless
4+
you are using a macOS release too old to have launchd.
5+
16
To install execute the following:
27

38
sudo /bin/sh ./install.sh

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy