title: Trouble installing postgresql on osx using homebrew
body: <p>I'm trying to install postgres on a new machine for the time. I initially ran thoughtbot's <a href="https://github.com/thoughtbot/laptop" rel="nofollow">laptop</a> script to install most of what I'd need for rails development which should have included the postgres installation. Yet when I run a <code>rake db:create</code> for the new rails app I get the following error:</p>
  
  <pre><code>Couldn't create database for {"adapter"=&gt;"postgresql", "encoding"=&gt;"utf8", "pool"=&gt;5, "timeout"=&gt;5000, "username"=&gt;"riskpool", "password"=&gt;nil, "database"=&gt;"riskpool_development"}
  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"?
  </code></pre>
  
  <p>I tried uninstalling and reinstalling postgres via homebrew like this and this is the result:</p>
  
  <pre><code>$ brew remove postgres                                                                                                                       
  Uninstalling /usr/local/Cellar/postgresql/9.4.5_2... (3021 files, 40M)
  </code></pre>
  
  <p>And reinstalling postgres</p>
  
  <pre><code>$ brew install postgres
  ==&gt; Downloading https://homebrew.bintray.com/bottles/postgresql-9.4.5_2.yosemite.bottle.tar.gz
  Already downloaded: /Library/Caches/Homebrew/postgresql-9.4.5_2.yosemite.bottle.tar.gz
  ==&gt; Pouring postgresql-9.4.5_2.yosemite.bottle.tar.gz
  Warning: The post-install step did not complete successfully
  You can try again using `brew postinstall postgresql`
  ==&gt; Caveats
  If builds of PostgreSQL 9 are failing and you have version 8.x installed,
  you may need to remove the previous version first. See:
    https://github.com/Homebrew/homebrew/issues/2510
  
  To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
    https://www.postgresql.org/docs/9.4/static/upgrading.html
  
  To load postgresql:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  Or, if you don't want/need launchctl, you can just run:
    postgres -D /usr/local/var/postgres
  
  WARNING: launchctl will fail when run under tmux.
  ==&gt; Summary
    /usr/local/Cellar/postgresql/9.4.5_2: 3021 files, 40M
  
  $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist                                                                      
  /usr/local/Cellar/postgresql/9.4.5_2/homebrew.mxcl.postgresql.plist: Operation not permitted
  </code></pre>
  
  <p>if I run the second command</p>
  
  <pre><code>$ postgres -D /usr/local/var/postgres
  FATAL:  could not open directory "pg_tblspc": No such file or directory
  </code></pre>
  
  <p>If I try to find out where postgres is installed:</p>
  
  <pre><code>$ which postgres
  /usr/local/bin/postgres
  </code></pre>
  
  <p>Someone suggested I kill an existing process id that might be interfering:</p>
  
  <pre><code>$ rm /usr/local/var/postgres/postmaster.pid                                                                                                   
  rm: /usr/local/var/postgres/postmaster.pid: No such file or directory
  </code></pre>
  
  <p>But I get the same error</p>
  
  <pre><code>psql: 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"?
  </code></pre>