Install Postgres on Mac
Postgres is increasingly viable database system. With Postgres 0.9.x or above, it introduced some amazing features where we can run complex SQL queries.
For web development, you can use any database servers like SQlite3, mySQL, and Postgres. At my work, I need to install Postgres on my MacBook Pro in order to run the web application. Homebrew has a package for postgres where it promises the installation will be breezy.
Install Postgres through the Homebrew.
brew install postgres
Once it is successfully downloaded, compiled, and installed. You will need to setup the initial database first.
initdb /usr/local/var/postgres -E utf8
Then you need to copy the postgres' plist file to LaunchAgents folder.
cp /usr/local/Cellar/postgresql/{VERSION}/org.postgresql.postgres.plist ~/Library/LaunchAgents/homebrew.mxcl.postgres.plist
Note: change {VERSION} to current postgres version.
Now, you can manually start Postgres server using OSX's launchctl.
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgres.plist
Or you can use nifty lunchy gem - a wrapper for OSX's launchctl tool.
gem install lunchy
lunchy start postgres
Create your new database.
createdb $USER
Connect to your postgres server.
psql
If you are running into an issue about unable to connect the postgres server even your postgres server is already running? I have scoured over many stackoverflow solutions, but can't find the one to work on my end. Until I found this helpful article about PATH environment.
# edit ~/.bashrc or ~/.bash_profile export PATH="/usr/local/bin:$PATH"
Bam! my createdb or psql command worked! Why? because my psql was from /usr/bin path. Homebrew installed executable commands to /usr/local/bin. We need to tell PATH to look at /usr/local/bin first before /usr/bin.
If you don't want to install and setup the postgres server. There is a Postgres Server App for Mac. It claimed that it is easiest way to run postgres on the Mac. Install and double click. That's it.
Postgres Weekly is a weekly newsletter for everyone who wants to catch up with news, technologies, and tips and tricks. Check it out!








