Auto Starting +/or Shutdown on OS X

Lists: pgsql-general
From: Ralph Smith <smithrn(at)u(dot)washington(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Auto Starting +/or Shutdown on OS X
Date: 2007-07-30 21:14:12
Message-ID: 46AE54A4.4040100@u.washington.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I'm using scripts in /Library/StartupItems/PostgreSQL

PostgreSQL starts manually just fine via
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l
/usr/local/pgsql/logfile start

PostgreSQL will not start on System restart using files in
/Library/StartupItems/PostgreSQL (See below).

If I execute the start command above just after a System start I get
pg_ctl: another server may be running; trying to start server anyway
server starting
and then it starts and runs fine.

If I shut down PG using
pg_ctl stop (no users connected)
it stops and subsequently starts using code above just fine, w/o the
warning.

---
I added the command:
date > /Users/showmefile
to appropriate portions of /Library/StartupItems/PostgreSQL/PostgreSQL
as seen below, and the script portions ARE appropriately being executed.

How come shutdown isn't clearing things up?
Or is the problem in the startup?

Thanks!
smithrn (at) u (dot) washington (dot) edu

--------------------------------------------
PostgreSQL
--------------------------------------------
#!/bin/sh

##
# PostgreSQL RDBMS Server
##

# PostgreSQL boot time startup script for Darwin/Mac OS X. To install,
change
# the "prefix", "PGDATA", "PGUSER", and "PGLOG" variables below as
# necessary. Next, create a new directory,
"/Library/StartupItems/PostgreSQL".
# Then copy this script and the accompanying "StartupParameters.plist" file
# into that directory. The name of this script file *must* be the same
as the
# directory it is in. So you'll end up with these two files:
#
# /Library/StartupItems/PostgreSQL/PostgreSQL
# /Library/StartupItems/PostgreSQL/StartupParameters.plist
#
# Next, add this line to the /etc/hostconfig file:
#
# POSTGRESQLSERVER=-YES-
#
# The startup bundle will now be ready to go. To prevent this script from
# starting PostgreSQL at system startup, simply change that line in
# /etc/hostconfig back to:
#
# POSTGRESQLSERVER=-NO-
#
# For more information on Darwin/Mac OS X startup bundles, see this article:
#
#
http://www.opensource.apple.com/projects/documentation/howto/html/SystemStarter_HOWTO.html
#
# Created by David Wheeler, 2002.

# modified by Ray Aspeitia 12-03-2003 :
# added log rotation script to db startup
# modified StartupParameters.plist "Provides" parameter to make it
easier to
# start and stop with the SystemStarter utitlity

# use the below command in order to correctly start/stop/restart PG with
log rotation script:
# SystemStarter [start|stop|restart] PostgreSQL

################################################################################
## EDIT FROM HERE
################################################################################

# Installation prefix
prefix="/usr/local/pgsql"

# Data directory
PGDATA="/usr/local/pgsql/data"

# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER="postgres"

# the logfile path and name (NEEDS to be writeable by PGUSER)
PGLOG="${PGDATA}/logs/logfile"

# do you want to rotate the log files, 1=true 0=false
ROTATELOGS=1

# logfile rotate in seconds
ROTATESEC="604800"

################################################################################
## STOP EDITING HERE
################################################################################

# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# What to use to start up the postmaster (we do NOT use pg_ctl for this,
# as it adds no value and can cause the postmaster to misrecognize a stale
# lock file)
DAEMON="$prefix/bin/postmaster"

# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"

# The apache log rotation utility
LOGUTIL="/usr/sbin/rotatelogs"

. /etc/rc.common

StartService () {
if [ "${POSTGRESQLSERVER:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting PostgreSQL database server"
if [ "${ROTATELOGS}" = "1" ]; then
# sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' |
${LOGUTIL} '${PGLOG}' ${ROTATESEC} &"
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' 2>&1 |
${LOGUTIL} '${PGLOG}' ${ROTATESEC} &"
else
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>$PGLOG 2>&1
fi
fi
date > /Users/PG_Started
}

StopService () {
ConsoleMessage "Stopping PostgreSQL database server"
sudo -u $PGUSER $PGCTL stop -D "$PGDATA" -s -m fast
date > /Users/PG_Stopped
}

RestartService () {
if [ "${POSTGRESQLSERVER:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Restarting PostgreSQL database server"
# should match StopService:
sudo -u $PGUSER $PGCTL stop -D "$PGDATA" -s -m fast
# should match StartService:
if [ "${ROTATELOGS}" = "1" ]; then
# sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' |
${LOGUTIL} '${PGLOG}' ${ROTATESEC} &"
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' 2>&1 |
${LOGUTIL} '${PGLOG}' ${ROTATESEC} &"
else
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>$PGLOG 2>&1
fi
else
StopService
fi
date > /Users/PG_Restarted
}

RunService "$1"

--------------------------------------------
StartupParameters.plist
--------------------------------------------
<?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>Description</key>
<string>PostgreSQL Database Server</string>
<key>Messages</key>
<dict>
<key>start</key>
<string>Starting PostgreSQL database server</string>
<key>stop</key>
<string>Stopping PostgreSQL database server</string>
<key>restart</key>
<string>Restarting PostgreSQL database server</string>
</dict>
<key>OrderPreference</key>
<string>Late</string>
<key>Provides</key>
<array>
<string>PostgreSQL</string>
</array>
<key>Requires</key>
<array>
<string>Disks</string>
<string>Resolver</string>
</array>
<key>Uses</key>
<array>
<string>NFS</string>
<string>NetworkTime</string>
</array>
</dict>
</plist>
--------------------------------------------


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: smithrn(at)u(dot)washington(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Auto Starting +/or Shutdown on OS X
Date: 2007-07-30 22:01:11
Message-ID: FD15A160-20C0-4F9C-BA10-7F76A5E68577@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


On Jul 30, 2007, at 16:14 , Ralph Smith wrote:

> I'm using scripts in /Library/StartupItems/PostgreSQL

I haven't used a StartupItem for PostgreSQL since launchd was
released. I haven't looked too closely at your configuration, but you
might consider using a launchd plist instead. Here's one of mine
(from /Library/LaunchDaemons/org.postgresql.postgres.v824.plist).
Note that if you use one of the plist launchd configuration editors
out there you'll probably lose the comments when you save.

Hope this helps.

Michael Glaesemann
grzm seespotcode net

<?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">
<!--
This launchd.plist file is used by the launchd process (availabie on
Mac OS X 10.4 and later) to launch and shutdown a PostgreSQL server.
The launchd.plist is used instead of a StartupItem. For detailed
descriptions
of launchd parameters and launchd, refer to to the launchd.plist,
launchd, and
launchctl manpages.

launchd.plists are commonly named in a manner similar to preference
plist files,
so for consistency (and easy identification) launchd.plists for
PostgreSQL
server instances should begin with org.postgresql.postgres. When running
multiple server instances on one machine, you may wish to distinguish
them. For
example, if one of your PostgreSQL servers is 8.0 and another 8.1,
you might
name the two launchd.plist files

org.postgresql.postgres.v80.plist
org.postgresql.postgres.v81.plist

Another alternative is to identify them by use. For example, when
running one
development server instance and a production server instance on the same
machine, you might name the two launchd.plist files

org.postgresql.postgres.dev.plist
org.postgresql.postgres.prod.plist

Note: While commments in launchd.plist files do not appear to
interfere with
launchd operation, editing and saving this file using Property List
Manager
will *not* preserve comments (including these)!

-->
<dict>
<key>Label</key>
<!-- Set the Label parameter to a unique string identifying
the job to
launchd. This is commonly set to the naem of the
launchd.plist file
without the .plist extension.
-->
<string>org.postgresql.postgres.v824</string>
<key>OnDemand</key>
<false/>
<key>Disabled</key>
<!-- Set the OnDemand parameter to <true/> to prevent the server
from
starting automatically on system start or when launched by
launchctl.
-->
<false/>
<key>ProgramArguments</key>
<!-- The elements of the ProgramArguments parameter array are
the command
line string used to start the server, exploded on white
space. No
string should contain spaces.

The first element is the absolute path to the postmaster
server
application binary, followed by the argments to be passed
to the
postmaster server application. Add, delete, and update these
parameter strings as needed for your requirements. The
example includes
setting the database data directory (PGDATA) and sets the
redirect_stderr runtime parameter.
-->
<array>
<string>/usr/local/pgsql/pgsql-8.2.4/bin/postmaster</
string>
<string>-D</string>
<string>/usr/local/pgsql/pgsql-8.2.4/data</string>
<string>-c</string>
<string>redirect_stderr=YES</string>
</array>
<key>ServiceDescription</key>
<!-- The ServiceDescription parameter is a human-readable
string to describe
the purpose of the service provided, in this case the
PostgreSQL dbms
server.
-->
<string>PostgreSQL Server v8.2.4</string>
<key>UserName</key>
<!-- Set the Username parameter string to the user who is to
owns the PostgreSQL
server process, typically "postgres".
-->
<string>postgres</string>
<key>GroupName</key>
<!-- Set the GroupName parameter to group of the user who is
to own the
PostgreSQL process, typically "postgres".
-->
<string>postgres</string>
</dict>
</plist>


From: Ralph Smith <smithrn(at)u(dot)washington(dot)edu>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Auto Starting +/or Shutdown on OS X
Date: 2007-07-31 19:27:39
Message-ID: 46AF8D2B.7010706@u.washington.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

=== INITIAL POST ====================
I'm using scripts in /Library/StartupItems/PostgreSQL

PostgreSQL starts manually just fine via
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l
/usr/local/pgsql/logfile start

PostgreSQL will not start on System restart using files in
/Library/StartupItems/PostgreSQL (no longer below).

If I execute the start command above just after a System start I get
pg_ctl: another server may be running; trying to start server anyway
server starting
and then it starts and runs fine.

If I shut down PG using
pg_ctl stop (no users connected)
it stops and subsequently starts using code above just fine, w/o the
warning.

---
I added the command:
date > /Users/showmefile
to appropriate portions of /Library/StartupItems/PostgreSQL/PostgreSQL
as seen below, and the script portions ARE appropriately being executed.

How come shutdown isn't clearing things up?
Or is the problem in the startup?

Thanks!

=== FIRST REPLY ===========================

Michael G wrote:
On Jul 30, 2007, at 16:14 , Ralph Smith wrote:

I'm using scripts in /Library/StartupItems/PostgreSQL

I haven't used a StartupItem for PostgreSQL since launchd was released.
I haven't looked too closely at your configuration, but you might
consider using a launchd plist instead. Here's one of mine (from
/Library/LaunchDaemons/org.postgresql.postgres.v824.plist). Note that if
you use one of the plist launchd configuration editors out there you'll
probably lose the comments when you save.

Hope this helps.

Michael Glaesemann
grzm seespotcode net

<?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">
<!--
This launchd.plist file is used by the launchd process (availabie on
Mac OS X 10.4 and later) to launch and shutdown a PostgreSQL server.
The launchd.plist is used instead of a StartupItem. For detailed
descriptions
of launchd parameters and launchd, refer to to the launchd.plist,
launchd, and
launchctl manpages.

launchd.plists are commonly named in a manner similar to preference
plist files,
so for consistency (and easy identification) launchd.plists for PostgreSQL
server instances should begin with org.postgresql.postgres. When running
multiple server instances on one machine, you may wish to distinguish
them. For
example, if one of your PostgreSQL servers is 8.0 and another 8.1, you
might
name the two launchd.plist files

org.postgresql.postgres.v80.plist
org.postgresql.postgres.v81.plist

Another alternative is to identify them by use. For example, when
running one
development server instance and a production server instance on the same
machine, you might name the two launchd.plist files

org.postgresql.postgres.dev.plist
org.postgresql.postgres.prod.plist

Note: While commments in launchd.plist files do not appear to interfere
with
launchd operation, editing and saving this file using Property List Manager
will *not* preserve comments (including these)!

-->
<dict>
<key>Label</key>
<!-- Set the Label parameter to a unique string identifying the
job to
launchd. This is commonly set to the naem of the
launchd.plist file
without the .plist extension.
-->
<string>org.postgresql.postgres.v824</string>
<key>OnDemand</key>
<false/>
<key>Disabled</key>
<!-- Set the OnDemand parameter to <true/> to prevent the server from
starting automatically on system start or when launched by
launchctl.
-->
<false/>
<key>ProgramArguments</key>
<!-- The elements of the ProgramArguments parameter array are the
command
line string used to start the server, exploded on white space. No
string should contain spaces.

The first element is the absolute path to the postmaster server
application binary, followed by the argments to be passed to the
postmaster server application. Add, delete, and update these
parameter strings as needed for your requirements. The example
includes
setting the database data directory (PGDATA) and sets the
redirect_stderr runtime parameter.
-->
<array>

<string>/usr/local/pgsql/pgsql-8.2.4/bin/postmaster</string>
<string>-D</string>
<string>/usr/local/pgsql/pgsql-8.2.4/data</string>
<string>-c</string>
<string>redirect_stderr=YES</string>
</array>
<key>ServiceDescription</key>
<!-- The ServiceDescription parameter is a human-readable string
to describe
the purpose of the service provided, in this case the
PostgreSQL dbms
server.
-->
<string>PostgreSQL Server v8.2.4</string>
<key>UserName</key>
<!-- Set the Username parameter string to the user who is to
owns the PostgreSQL
server process, typically "postgres".
-->
<string>postgres</string>
<key>GroupName</key>
<!-- Set the GroupName parameter to group of the user who is to
own the
PostgreSQL process, typically "postgres".
-->
<string>postgres</string>
</dict>
</plist>

=== COUNTER REPLY ===============================

Ralph Replies:
Thanks Michael.

But alas, auto-starting still doesn't work!

I renamed the file in the FORMERLY like-named DIR in
/Library/StartupItems/PostgreSQL to inactivate it.
Then I inserted your .plist text below into /Library/LaunchDaemons as
org.postgresql.postgres.v824.plist
Owner/Group root/wheel, 644 perms.

However... PostgreSQL still won't start at boot up!
In the system.log I get the errors you can see below.
Also there are my modifications to the .plist file -- to match my
install, and some debugging I added.

I'm looking at getting that debugging to log where I can find it.
Can someone help me config extended logging?
log_destination, log_directory, log_filename
Or is startup too soon for these to help me here?

Thanks,
Ralph
---------------------------------------

Jul 30 17:11:40 swampmac lookupd[90]: lookupd (version 369.5) starting -
Mon Jul 30 17:11:40 2007
Jul 30 17:11:40 swampmac configd[52]: posting notification
com.apple.system.config.network_change
Jul 30 17:11:40 swampmac lookupd[91]: lookupd (version 369.5) starting -
Mon Jul 30 17:11:40 2007
Jul 30 17:11:40 swampmac configd[52]: setting hostname to
"swampmac.eplt.washington.edu"
Jul 30 17:11:40 swampmac loginwindow[83]: Login Window Started Security
Agent
Jul 30 17:11:42 swampmac
/System/Library/CoreServices/mcxd.app/Contents/MacOS/mcxd: DSOpenNode():
dsOpenDirNode("/Active Directory/All Domains") == -14002
Jul 30 17:11:43 swampmac configd[52]: target=enable-network: disabled
Jul 30 17:11:43 swampmac launchd: org.postgresql.postgres.v824: exited
with exit code: 1
Jul 30 17:11:43 swampmac launchd: org.postgresql.postgres.v824:
respawning too quickly! throttling
Jul 30 17:11:43 swampmac launchd: org.postgresql.postgres.v824: 8 more
failures without living at least 60 seconds will cause job removal
Jul 30 17:11:43 swampmac launchd: org.postgresql.postgres.v824: will
restart in 10 seconds
Jul 30 17:11:44 swampmac VersionCueCS2Daemon[198]: warning:
VersionCueCS2Daemon not started by mach_init process (parent pid: 1)
Jul 30 17:11:45 swampmac configd[52]: AppleTalk startup complete
Jul 30 17:11:53 swampmac launchd: org.postgresql.postgres.v824: exited
with exit code: 1
Jul 30 17:11:53 swampmac launchd: org.postgresql.postgres.v824:
respawning too quickly! throttling
Jul 30 17:11:53 swampmac launchd: org.postgresql.postgres.v824: 7 more
failures without living at least 60 seconds will cause job removal
Jul 30 17:11:53 swampmac launchd: org.postgresql.postgres.v824: will
restart in 10 seconds

Modifications to the .plist file:

<string>/usr/local/pgsql/bin/postmaster</string>
<string>-D</string>
<string>/usr/local/pgsql/data</string>
<string>-l</string>
<string>/usr/local/pgsql/logfile</string>
<string>-c</string>
<string>redirect_stderr=YES</string>
<string>-c</string>
<string>log_min_message=DEBUG5</string>
<string>-c</string>
<string>log_error_verbosity=VERBOSE</string>

===============================================


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: smithrn(at)u(dot)washington(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Auto Starting +/or Shutdown on OS X
Date: 2007-07-31 23:01:41
Message-ID: 3B36B5C7-0D9A-4C13-A3D0-CEDAEC080E5F@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


On Jul 31, 2007, at 14:27 , Ralph Smith wrote:

> === INITIAL POST ====================
> I'm using scripts in /Library/StartupItems/PostgreSQL
>
> PostgreSQL starts manually just fine via
> /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/
> pgsql/logfile start

What user are you starting the server as? Is this the same user you
have specified in the StartupItem/launchd plist?

> If I execute the start command above just after a System start I get
> pg_ctl: another server may be running; trying to start server anyway
> server starting
> and then it starts and runs fine.

I'm speculating that the StartupItem is trying to start the server
but failing.

> I'm looking at getting that debugging to log where I can find it.
> Can someone help me config extended logging?
> log_destination, log_directory, log_filename

I believe you should be able to set these at startup, though I
haven't tried.

> <string>/usr/local/pgsql/bin/postmaster</string>
> <string>-D</string>
> <string>/usr/local/pgsql/data</string>
> <string>-l</string>
> <string>/usr/local/pgsql/logfile</string>
> <string>-c</string>
> <string>redirect_stderr=YES</string>
> <string>-c</string>
> <string>log_min_message=DEBUG5</string>
> <string>-c</string>
> <string>log_error_verbosity=VERBOSE</string>

Did you also change the user and group to what's appropriate for your
setup?

Michael Glaesemann
grzm seespotcode net


From: Ralph Smith <smithrn(at)u(dot)washington(dot)edu>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Auto Starting +/or Shutdown on OS X
Date: 2007-07-31 23:53:34
Message-ID: 46AFCB7E.8090106@u.washington.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Apologies for the huge post, but it's got everything relevant that I can
think of.
See below.

Michael Glaesemann wrote:
>
> On Jul 31, 2007, at 14:27 , Ralph Smith wrote:
>
>> === INITIAL POST ====================
>> I'm using scripts in /Library/StartupItems/PostgreSQL
>>
>> PostgreSQL starts manually just fine via
>> /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l
>> /usr/local/pgsql/logfile start
>
> What user are you starting the server as? Is this the same user you
> have specified in the StartupItem/launchd plist?
>
>> If I execute the start command above just after a System start I get
>> pg_ctl: another server may be running; trying to start server anyway
>> server starting
>> and then it starts and runs fine.
>
> I'm speculating that the StartupItem is trying to start the server but
> failing.
>
>> I'm looking at getting that debugging to log where I can find it.
>> Can someone help me config extended logging?
>> log_destination, log_directory, log_filename
>
> I believe you should be able to set these at startup, though I haven't
> tried.
>
>> <string>/usr/local/pgsql/bin/postmaster</string>
>> <string>-D</string>
>> <string>/usr/local/pgsql/data</string>
>> <string>-l</string>
>> <string>/usr/local/pgsql/logfile</string>
>> <string>-c</string>
>> <string>redirect_stderr=YES</string>
>> <string>-c</string>
>> <string>log_min_message=DEBUG5</string>
>> <string>-c</string>
>> <string>log_error_verbosity=VERBOSE</string>
>
> Did you also change the user and group to what's appropriate for your
> setup?
>
> Michael Glaesemann
> grzm seespotcode net
> =========================================================
Ralph here again.

The command-line start is via U/G postgres/postgres.
In /Library/LaunchDaemon/... I'm using the same names.
I've removed all references to PG in /Library/StartupItems
- - - - - - - - - - - -
- - - - - - - - - - - -
From tail of /var/log/system.log
Jul 31 16:31:04 swampmac launchd: org.postgresql.postgres.v824: exited
with exit code: 1
Jul 31 16:31:04 swampmac launchd: org.postgresql.postgres.v824:
respawning too quickly! throttling
Jul 31 16:31:04 swampmac launchd: org.postgresql.postgres.v824: 1 more
failure without living at least 60 seconds will cause job removal
Jul 31 16:31:04 swampmac launchd: org.postgresql.postgres.v824: will
restart in 10 seconds
Jul 31 16:31:14 swampmac launchd: org.postgresql.postgres.v824: exited
with exit code: 1
Jul 31 16:31:14 swampmac launchd: org.postgresql.postgres.v824:
respawning too quickly! throttling
Jul 31 16:31:14 swampmac launchd: org.postgresql.postgres.v824: too many
failures in succession
========================
========================

swampmac:/pgsql_link postgres$ ll -R /Library/LaunchDaemons/
total 8
drwxr-xr-x 3 root wheel 102 Jul 31 16:10 .
drwxrwxr-t 47 root admin 1598 Jul 19 16:58 ..
-rw-r--r-- 1 root wheel 3957 Jul 30 16:59
org.postgresql.postgres.v824.plist
========================
========================

swampmac:/pgsql_link postgres$ cat
/Library/LaunchDaemons/org.postgresql.postgres.v824.plist
<?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">
<!-- bulk of comment removed
-->

<dict>
<key>Label</key>
<!-- Set the Label parameter to a unique string identifying the
job to
launchd. This is commonly set to the naem of the
launchd.plist file
without the .plist extension.
-->
<string>org.postgresql.postgres.v824</string>
<key>OnDemand</key>
<false/>
<key>Disabled</key>
<!-- Set the OnDemand parameter to <true/> to prevent the server from
starting automatically on system start or when launched by
launchctl.
-->
<false/>
<key>ProgramArguments</key>
<!-- The elements of the ProgramArguments parameter array are the
command
line string used to start the server, exploded on white space. No
string should contain spaces.

The first element is the absolute path to the postmaster server
application binary, followed by the argments to be passed to the
postmaster server application. Add, delete, and update these
parameter strings as needed for your requirements. The example
includes
setting the database data directory (PGDATA) and sets the
redirect_stderr runtime parameter.
-->
<array>
<string>/usr/local/pgsql/bin/postmaster</string>
<string>-D</string>
<string>/usr/local/pgsql/data</string>
<string>-l</string>
<string>/usr/local/pgsql/logfile</string>
<string>-c</string>
<string>redirect_stderr=YES</string>
<string>-c</string>
<string>log_min_message=DEBUG5</string>
<string>-c</string>
<string>log_error_verbosity=VERBOSE</string>
</array>
<key>ServiceDescription</key>
<!-- The ServiceDescription parameter is a human-readable string
to describe
the purpose of the service provided, in this case the
PostgreSQL dbms
server.
-->
<string>PostgreSQL Server v8.2.4</string>
<key>UserName</key>
<!-- Set the Username parameter string to the user who is to
owns the PostgreSQL
server process, typically "postgres".
-->
<string>postgres</string>
<key>GroupName</key>
<!-- Set the GroupName parameter to group of the user who is to
own the
PostgreSQL process, typically "postgres".
-->
<string>postgres</string>
</dict>
</plist>
===========================
===========================

swampmac:/pgsql_link postgres$ more data/postgresql.conf
# -----------------------------
# PostgreSQL configuration file
# -----------------------------
#
# COMMENTS REMOVED HERE

#---------------------------------------------------------------------------
# FILE LOCATIONS
#---------------------------------------------------------------------------

# The default values of these variables are driven from the -D command line
# switch or PGDATA environment variable, represented here as ConfigDir.

#data_directory = 'ConfigDir' # use data in another directory
data_directory = '/usr/local/pgsql/data' # use data in
another directory
# (change requires restart)

#hba_file = 'ConfigDir/pg_hba.conf' # host-based
authentication file
hba_file = '/usr/local/pgsql/data/pg_hba.conf' # host-based
authentication file
# (change requires restart)
#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file
# (change requires restart)

# If external_pid_file is not explicitly set, no extra PID file is written.
#external_pid_file = '(none)' # write an extra PID file
# (change requires restart)

#---------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#---------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '127.0.0.1, addr1, addr2, addr3' # I have IP
addresses here

# what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart)
==========================
==========================

swampmac:/pgsql_link postgres$ more data/pg_hba.conf
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the
# PostgreSQL documentation for a complete description
# of this file. A short synopsis follows.
#
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access. Records take one of these forms:
#
# local DATABASE USER METHOD [OPTION]
# host DATABASE USER CIDR-ADDRESS METHOD [OPTION]
# hostssl DATABASE USER CIDR-ADDRESS METHOD [OPTION]
# hostnossl DATABASE USER CIDR-ADDRESS METHOD [OPTION]
#
# (The uppercase items must be replaced by actual values.)
#
# The first field is the connection type: "local" is a Unix-domain socket,
# "host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" is an
# SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IP socket.
#
# DATABASE can be "all", "sameuser", "samerole", a database name, or
# a comma-separated list thereof.
#
# USER can be "all", a user name, a group name prefixed with "+", or
# a comma-separated list thereof. In both the DATABASE and USER fields
# you can also write a file name prefixed with "@" to include names from
# a separate file.
#
# CIDR-ADDRESS specifies the set of hosts the record matches.
# It is made up of an IP address and a CIDR mask that is an integer
# (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that specifies
# the number of significant bits in the mask. Alternatively, you can write
# an IP address and netmask in separate columns to specify the set of hosts.
#
# METHOD can be "trust", "reject", "md5", "crypt", "password",
# "krb5", "ident", "pam" or "ldap". Note that "password" sends passwords
# in clear text; "md5" is preferred since it sends encrypted passwords.
#
# OPTION is the ident map or the name of the PAM service, depending on
METHOD.
#
# Database and user names containing spaces, commas, quotes and other
special
# characters must be quoted. Quoting one of the keywords "all",
"sameuser" or
# "samerole" makes the name lose its special character, and just match a
# database or username with that name.
#
# This file is read on server startup and when the postmaster receives
# a SIGHUP signal. If you edit the file on a running system, you have
# to SIGHUP the postmaster for the changes to take effect. You can use
# "pg_ctl reload" to do that.

# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL listen
# on a non-local interface via the listen_addresses configuration parameter,
# or via the -i or -h command line switches.
#

# CAUTION: Configuring the system for local "trust" authentication allows
# any local user to connect as any PostgreSQL user, including the database
# superuser. If you do not trust all your local users, use another
# authentication method.

# TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all trust

# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 128.208.95.6/32 trust # Swamp's PC
host all all 128.208.96.124/32 trust # swamp's
Mac (This DB Server)

# IPv6 local connections:
host all all ::1/128 trust


From: John DeSoi <desoi(at)pgedit(dot)com>
To: smithrn(at)u(dot)washington(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Auto Starting +/or Shutdown on OS X
Date: 2007-08-01 03:16:26
Message-ID: 2C0BC509-29CB-40C7-B2AA-8FB9BD44AAE7@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


On Jul 31, 2007, at 3:27 PM, Ralph Smith wrote:

> How come shutdown isn't clearing things up?
> Or is the problem in the startup?

There is a small package you can download from this page which will
install in StartupItems and handle things correctly:

http://www.entropy.ch/software/macosx/postgresql/

Direct link:

http://www2.entropy.ch/download/pgsql-startupitem-1.2.pkg.tar.gz

I have also included the script below.

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL

======

#!/bin/sh

. /etc/rc.common

##
# Start up the PostgreSQL database server on Mac OS X / Darwin
#
#
# History
# -------
#
# 2002-08-21 Marc Liyanage <liyanage(at)access(dot)ch>
# Changed startup to use pg_ctl
#
# 2002-08-19 Ed Silva <ed(at)septicus(dot)com>
# Modified startup script to conform
# to new SystemStarter format for Mac OS X 10.2
#
# 2001-04-02 Marc Liyanage <liyanage(at)access(dot)ch>
# First version
#
# 2001-12-02 Johan Henselmans <johanhenselmans(at)mac(dot)com>
# Enhanced after carefully studying the Frontbase
# startup sequence ;-)
# Now provides a stop procedure for a graceful shutdown
# and a hard kill if the clean shutdown doesn't work.
#
# 2001-12-02 Marc Liyanage <liyanage(at)access(dot)ch>
# Added localized startup messages in 7 languages
# by adapting the resources of the Apple-supplied
# "Sendmail" startup script.
#
#
# License
# -------
#
# The PostgreSQL BSD-style license applies to this file
#

StartService ()
{

if [ "${POSTGRES:=-YES-}" = "-YES-" ]; then

ConsoleMessage "Starting PostgreSQL database server"
su - postgres -c '/usr/local/bin/pg_ctl start -D /usr/local/
pgsql/data -l /usr/local/pgsql/logfile -o -i'

fi

}

StopService()
{

ConsoleMessage "Stopping PostgreSQL database services"
/usr/local/bin/pg_ctl stop -D /usr/local/pgsql/data
x=`/bin/ps axc | /usr/bin/grep postgres`
if /bin/test "$x"
then
set $x
kill -9 $x
fi

}

RestartService ()
{
StopService
StartService
}

RunService "$1"


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: smithrn(at)u(dot)washington(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Auto Starting +/or Shutdown on OS X
Date: 2007-08-07 18:49:22
Message-ID: 5F6B211B-B2D4-4D4B-84C0-EB0BA9F87E96@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


On Jul 31, 2007, at 18:53 , Ralph Smith wrote:

> Apologies for the huge post, but it's got everything relevant that
> I can think of.
> See below.

Ralph,

Did you ever get this sorted? I don't have any new ideas, but was
wondering if you had figured out a solution.

Michael Glaesemann
grzm seespotcode net