The first thing we must do is fix up the "postgres" user's system settings. After installation you won't be able to "su" to the "postgres" user because that user's shell conveniently points at "/dev/null". MacOSX's user account management GUI only allows editing of desktop "login" accounts (those with uid > 500 ). We will therefore have to recruit MacOSX's dscl commandline tool for this job. You can learn more about dscl here.
Open a terminal window and type:
> read /Users/postgres
AppleMetaNodeLocation: /Local/Default
AuthenticationHint:
NFSHomeDirectory: /var/empty
Password: *
PrimaryGroupID: 252
RealName:
PostgreSQL Database Server
RecordName: postgres
RecordType: dsRecTypeStandard:Users
UniqueID: 252
UserShell: /dev/null
You will notice that several of the account settings are awry. Specifically we must fix "UserShell" and "NFSHomeDirectory".
Before we can fix the NFSHomeDirectory of the user, let's create a convenient symbolic link :
$sudo ln -s /sw/var/postgres-xx /sw/var/pgsql
Now once more we run the "dscl" tool, and use the "create" command to update the "postgres" user's home directory:
$sudo dscl .
> create /Users/postgres NFSHomeDirectory /sw/var/pgsql
> read /Users/postgres
AppleMetaNodeLocation: /Local/Default
AuthenticationHint:
NFSHomeDirectory: /sw/var/pgsql
Password: *
PrimaryGroupID: 252
RealName:
PostgreSQL Database Server
RecordName: postgres
RecordType: dsRecTypeStandard:Users
UniqueID: 252
UserShell: /dev/null
>
We do the same for the postgres user's shell :
> create /Users/postgres UserShell /bin/bash
> read /Users/postgres
AppleMetaNodeLocation: /Local/Default
AuthenticationHint:
NFSHomeDirectory: /sw/var/pgsql
Password: *
PrimaryGroupID: 252
RealName:
PostgreSQL Database Server
RecordName: postgres
RecordType: dsRecTypeStandard:Users
UniqueID: 252
UserShell: /bin/bash
>
We now "su" to the postgres user and initialize our database. IMPORTANT: Don't do this step if you have existing data in "/sw/var/pgsql/data" or you will LOSE ALL YOUR DATA!
$/sw/bin/initdb -D /sw/var/pgsql/data -E utf8
Once this is done you can start your PostgreSQL instance with
$/sw/bin/pg_ctl -D /sw/var/pgsql/data start
You will have to manually stop/start your PostgreSQL instance every time. If you want to start your service automatically at boot or login time, you might want to create a StartupItem. You can learn more about MacOSX StartupItems here:
Read more...
