OSX 10.5 Leopard

From Robertjd

Jump to: navigation, search

List Users

Netinfo is gone. Now use the directory service utility to get a full list of system accounts:

dscl . -list /Users UniqueID

Prevent .DS_Store file creation on network volumes

In terminal:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

From: http://www.macosxhints.com/article.php?story=2005070300463515

Install PostgreSQL from Macports

Grab the client and server with this, check macports.org if you want a version other than 8.3:

sudo port install postgresql83 postgresql83-server

You will then be told to do the following, which you should:

sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'

Let's break that down, it

  • 1.) creates a directory for a default database to live in
  • 2.) changes ownership and group of that directory to the user postgres
  • 3.) using sudo, executes the initdb command as the user postgres

initdb will run and tell you this useful information for starting postgres using your databse:

Success. You can now start the database server using:

    /opt/local/lib/postgresql83/bin/postgres -D /opt/local/var/db/postgresql83/defaultdb
    /opt/local/lib/postgresql83/bin/pg_ctl -D /opt/local/var/db/postgresql83/defaultdb -l logfile start

Perfect, let's try it. In the following terminal examples, note that I am currently running as my user, robert:

robert:~$ /opt/local/lib/postgresql83/bin/postgres -D /opt/local/var/db/postgresql83/defaultdb
postgres cannot access the server configuration file "/opt/local/var/db/postgresql83/defaultdb/postgresql.conf": Permission denied

Permission denied?? That is because we are trying to run it as a user other than postrgres, which owns this db. So lets run that again as the postgres user:

robert:~$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/postgres -D /opt/local/var/db/postgresql83/defaultdb'
LOG:  database system was shut down at 2009-05-07 16:21:06 EDT
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections

Much better. The postgres daemon will stay open in that window, leave that open and open another terminal window to do the next steps. Now we will try to connect, using psql:

robert:~$ /opt/local/lib/postgresql83/bin/psql
psql: FATAL:  database "robert" does not exist

Eh? With initdb we created a database cluser, not an actual database. We still need to create a databse. With the command above, I did not specify a database to connect to after the psql command, so it tired to connect to "robert". Let's create a new database, I'll call mine test:

robert:~$ /opt/local/lib/postgresql83/bin/createdb test
createdb: could not connect to database postgres: FATAL:  role "robert" does not exist

Really? Yes. We said that postgres is the user for our defaultdb, so again we have to run this as the postgres user:

robert:~$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/createdb test'

If everything goes fine, nothing will be output. Now we will try psql again,

robert:~$ /opt/local/lib/postgresql83/bin/psql test
psql: FATAL:  role "robert" does not exist

Again?? Yes, you'll have to run as postgres. You might be getting annoyed by having to sudo su everything. So let's set a password for the postgres account and then switch to that user:

robert:~$ sudo dscl . -passwd /Users/postgres mynewpostgrespass
robert:~$ su postgres

Notice how our prompt now says postgres$ instead of robert. I am now in the terminal as postgres, not robert. Now let's try to connect again:

postgres:/Users/robert$ /opt/local/lib/postgresql83/bin/psql test
Welcome to psql 8.3.5, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
      \h for help with SQL commands
      \? for help with psql commands
      \g or terminate with semicolon to execute query
      \q to quit


We're in! You are on your own from here in regards to using postgres. Go back to the terminal that you started the daemon in and do Control-C to quit the daemon:

robert:~$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/postgres -D /opt/local/var/db/postgresql83/defaultdb'LOG:  database system was shut down at 2009-05-07 16:21:06 EDT
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections
FATAL:  database "robert" does not exist
FATAL:  database "default" does not exist
FATAL:  role "robert" does not exist
FATAL:  role "robert" does not exist
^CLOG:  received fast shutdown request
LOG:  aborting any active transactions
robert:~$ FATAL:  terminating connection due to administrator command
LOG:  autovacuum launcher shutting down
LOG:  shutting down
LOG:  database system is shut down

Note how the errors that we got in our other terminal when trying to connect are also sent to standard output by the postgres daemon.

To get postgres to run at startup, run this command:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
Personal tools