title: How to connect to Postgres database through Ruby's pg gem (outside of Rails)
body: <p>I've been using Postgres without issue within Rails and have also been running <code>psql</code> without issue. However, I'm running into a problem trying to connect to the database with the <code>pg</code> gem.</p>
  
  <p>The following code:</p>
  
  <pre><code>PG.connect
  </code></pre>
  
  <p>generates the error/output:</p>
  
  <pre><code>PG::ConnectionBad: 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"?
  </code></pre>
  
  <p>The result is the same whether I specify various <code>dbname:</code> values or not or just let this default.</p>
  
  <p>When I click on the little elephant icon at the top of my screen, it says "Running on port 5432" and, as I said, I can connect with <code>psql</code> without a problem.</p>
  
  <p>I found the very similar <a href="https://stackoverflow.com/questions/18685649/cannot-connect-to-postgres-pg-database-from-my-ruby-script-using-gem-pgthis">cannot connect to Postgres (pg) database from my Ruby Script using gem &quot;pg&quot;(This is not rails, just pure ruby)</a>, but the answer simply said Rails works fine.</p>
  
  <p>Any guidance would be appreciated. (Note: I realize I haven't entered any name/password info, but I don't have to enter than when I run <code>psql</code> and I gather it's not getting to the point of authentication).</p>