Setting up postgres on my mac

Trying to set up PostgresQL on my Mac. Why? I want to use a key-value pair as an entry in my database, for convenience. It’ll save me from using three or four weirdly interlocked tables. SQLite3 can’t do it.

Here’s the story:

  • I am using RubyMine. Using the pg gem, I started a new clean project and pressed some buttons on the RubyMine setup screen to configure the project with Postgres as the database.
  • Not working. Not surprising, but it was worth checking!
  • Entering psql on command line gives the following error:

psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket “/var/pgsql_socket/.s.PGSQL.5432”?

  • I know I have Postgres installed. Socket issue? Do I even know these words?
  • Search through internets.
  • Apparently “reading directions” is still an important life skill. I installed Postgres using brew because the version packed with Apple is out of date already. When you type “brew install postgresql” a cascade of text appears. Often I have found that this material is unimportant to my life. Not this time! It includes crucial instructions, like how to start your new version of postgres. Typing “postgres -D /usr/local/var/postgres” at the terminal got a mysterious process started: now the server is running locally.
  • Then I went back to RubyMine and tried to set up my stuff. Couldn’t create the databases with “rake db:create”; while I was running postgres locally I still wasn’t creating connections on the right sockets with my Rails app. Aha: here’s where adding “host: localhost” to both development and test environments in config/database.yml came in handy. Once I had specified the host for both, the databases got created. RubyMine made happy faces and my terminal window informed me that “STATEMENT: CREATE DATABASE” action was happening.
  • Now I’m in business: created a migration to enable extension hstore, created a model using hstore, and proceeding toward a more flexible data model.