This is a pretty simple process, but one that I thought I would document because I ran into a few gotchas along the way.
I originally installed OS X using the one click installer from EnterpriseDB. Unfortunately, the installer hung while attempting to finish the installation process and they only thing to do was to roll back the install. I attempted to build from macports, but that proved to be a huge pain in my ass and reminded me a little bit too much of using Linux, so I scrapped that idea as well. I started browsing the EnterpriseDB installation notes and came across an unattended install. Since my installation failed trying to launch the final interactive stage of the installation, I said to myself “Self, I bet we should try this.”
- Download PostgreSQL from EnterpriseDB http://www.enterprisedb.com/products/pgdownload.do#osx
- Mount the OS X disk image file
- In the Terminal, change to the directory where the image file was mounted:
cd /Volumes/PostgreSQL\ 8.4.2-1/ - Start the unattended installation
sudo ./postgresql-8.4.2-1-osx.app/Contents/MacOS/installbuilder.sh
--mode unattended - Once the installation has finished, add the following line to your .profile:
source /Library/PostgreSQL/8.4/pg_env.sh
If you’ve never created your .profile you can do the following in a terminal window:touch ~/.profile
This will create the file if it doesn’t exist and will only change the last modification date if it does.open /Applications/TextEdit.app .profile
This opens your .profile in the TextEdit application
- Save and close your .profile
- Create a new database user.
createuser [YOUR NAME HERE] --pwprompt --username=postgres - When you’re prompted for the “Password:”, use “postgres”. This is the default password for the postgres superuser. Because you’ve just created another superuser, you’ll never have to touch this account again, but you should probably look up some fantastic documentation and learn how to change the password.
There you have it: how to set up and install PostgreSQL on OS X. If you want to continue forward and install a Ruby library to interact with PostgreSQL, just type
sudo gem install postgres-pr to install the pure Ruby version PostgreSQL driver. If you want to install one of the C-based drivers, you’ll need to mess around with macports.
Note: EnterpriseDB make and distribute a binary version of PostgreSQL for a variety of platforms. In addition, they provide paid support and also offer a variety of enterprise features. They have in no way paid me for this post.
Related Posts:
PostgreSQL Tutorial – Creating Your First Database
PostgreSQL Tutorial – Creating the Pagila Schema
PostgreSQL Tutorial – Referring to Other Tables
PostgreSQL Tutorial – Inserting Data


Comments
Thanks for the info. Did you increase your shared memory settings in sysctl.conf like the readme file says to do? I’m wondering what if any downside there is to following that advice.
Thanks,
Sharon
suggested sysctl.conf settings for a MacBook Pro with 2G of RAM:
kern.sysv.shmmax=1610612736
kern.sysv.shmall=393216
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.maxprocperuid=512
kern.maxproc=2048
I switched up my sysctl settings. The defaults that PostgreSQL sets are incredibly conservative and from the looks of them, they haven’t been revisited in at least 5 years. Changing those settings up will affect every program, so there’s an outside chance that you’ll increase shared memory space for everyone and more programs will use more memory. With 8GB of RAM, I didn’t find these settings to be problematic.
Thanks for you information. Enterprise DB should include this into faq.
HAHA, thanks sir. I’m glad you found it helpful. I didn’t run into the same problems with the most recent PostgreSQL installer from EnterpriseDB (I’m running PostgreSQL 9.1.0), but I ran into some other conflicts because of OS X Lion’s installation of the PostgreSQL client tools. I would guess that has been fixed, but I haven’t updated my PostgreSQL binaries to match up with the newest patch level.
I keep getting errors like this after installing postgresql on lion:
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/tmp/.s.PGSQL.5432″?
Any help?
Any advice would depend on the way you’ve installed PostgreSQL. I had a few problems on Lion using the EnterpriseDB installer. I solved that through EnterpriseDB’s forums.
From the error you’re seeing, PostgreSQL isn’t running. I have no idea why, you can check in the logs, but the location depends on how you’ve installed PostgreSQL.
Thanks so much, i’ve tried everything today to get ‘gem pg’ to install on my OSX 10.6
finally a working solution!
Trackbacks
2 pings so far. Trackbacks are closed.