ERROR: Failed to build gem native extension on Mavericks
Also make sure that you've upgraded Xcode to re-install command line tools on Mavericks. In terminal type:
xcode-select --install
Then follow the prompts.
For me it worked when I did:
brew install postgresql
this worked for me with Mavericks and the Postgresapp:
gem install pg -v '0.17.0' -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config