64-bit Postgres and Rails on Snow Leopard
- 2 comments
- tagged with postgres, ruby, snow leopard, 64-bit, rails
Dependencies
Install the GEOS and PROJ frameworks from here
Postgres
Download and Compile
http://ftp2.au.postgresql.org/pub/postgresql/source/v8.4.1/postgresql-8.4.1.tar.bz2 | tar xjf -cd postgresql-8.4.1./configuremake && sudo make install
The files are now all installed in the right places, onwards to making them usable!
Create a postgres User and Group
This is adjusted from the instructions in the comments here).
# Find unused Group ID and User ID:export GROUPID=`sudo dscl . -list /Groups PrimaryGroupID | ruby -e 'puts STDIN.read.scan(/\d+/m).map{|i|i.to_i}.uniq.sort.last.succ'`export USERID=`sudo dscl . -list /Users UniqueID | ruby -e 'puts STDIN.read.scan(/\d+/m).map{|i|i.to_i}.uniq.sort.last.succ'`# Create group:sudo dscl . -create /Groups/_postgressudo dscl . -create /Groups/_postgres PrimaryGroupID $GROUPIDsudo dscl . -append /Groups/_postgres RecordName postgres# Create user:sudo dscl . -create /Users/_postgressudo dscl . -create /Users/_postgres UniqueID $USERIDsudo dscl . -create /Users/_postgres PrimaryGroupID $GROUPIDsudo dscl . -create /Users/_postgres UserShell /bin/bashsudo dscl . -create /Users/_postgres RealName "PostgreSQL Server"sudo dscl . -create /Users/_postgres NFSHomeDirectory /usr/local/pgsqlsudo dscl . -append /Users/_postgres RecordName postgres
That’s the clean way of making a user (so it doesn’t show up in your Accounts preference pane, etc.
Clean up
sudo touch /var/log/psql.logsudo mkdir /usr/local/pgsql/datasudo chown -R postgres:postgres /usr/local/pgsql/data /var/log/psql.log# Put Postgres in your pathexport $PATH="/usr/local/pgsql/bin:$PATH"sudo sh -c 'echo /usr/local/pgsql/bin > /etc/paths.d/pgsql'
Thanks to Apple we have a nice way of setting the PATH across the entire system so every app should now know how to find the Postgres binaries and the data directory is now set up to store the database files — now, we just need to create them.
Initialise the Database
# Become the postgres usersudo su - postgres# If this throws next commant throws an error about shared memory,# try putting "these lines":http://gist.github.com/224815 into# /etc/sysctl.conf, rebooting, and trying again:initdb -D /usr/local/pgsql/data -E UTF8# Start the databasepostgres -D /usr/local/pgsql/data >/var/log/psql.log 2>&1 &# Create a test database and check you can connect to itcreatedb testpsql test# Just create a superuser for general dev taskscreateuser postgres# we don't want to be the postgres user anymoreexit
Your done with the Postgres setup now!
PostGIS
curl http://postgis.refractions.net/download/postgis-1.3.7SVN.tar.gz | tar xzf -cd postgis-1.3.7SVN./configure --with-geosconfig=/Library/Frameworks/GEOS.framework/unix/bin/geos-config --with-projdir=/Library/Frameworks/PROJ.framework/unixmake && sudo make install
Phew! That one was easy.
Postgres Ruby Gem
This is the part that everyone cares about the most. If this works your Rails apps should start working like a charm.
sudo env ARCHFLAGS='-arch x86_64' gem install pg
