title: Rails: rake db:create:all fails to connect to PostgreSQL database
body: <p>I am trying to create a Rails app that uses PostgreSQL. Here is a description of what I did.</p>
  
  <hr>
  
  <p><strong>PostgreSQL setup:</strong><br>
  I installed PostgreSQL 9.1.3 via the <a href="https://launchpad.net/~pitti/+archive/postgresql" rel="noreferrer">ppa:pitti/postgresql</a> maintained by Martin Pitt. There was PostgreSQL  8.4 installed before; I am not sure if it is still installed or gone.</p>
  
  <ul>
  <li>I added a database user with superuser rights to the database that has the same name as my Ubuntu account.</li>
  <li>I start the database daemon with <code>sudo service postgresql start</code>.</li>
  <li>I installed <a href="http://pgadmin.org" rel="noreferrer">pgadmin3, Version 1.14.0 Beta 1</a> via <a href="https://launchpad.net/~rhonda/+archive/pgadmin3" rel="noreferrer">ppa:rhonda/pgadmin3</a> maintained by Gerfried Fuchs.</li>
  <li>I can connect via pgadmin3 using my user account and password and port 5433.</li>
  </ul>
  
  <p>My postgres configuration in <em>pg_hba.conf</em> is as follows (removed comments for readability).</p>
  
  <pre><code>[...]
  local   all             postgres                                peer
  local   all             all                                     peer
  host    all             all             127.0.0.1/32            md5
  host    all             all             ::1/128                 md5
  </code></pre>
  
  <hr>
  
  <p><strong>Rails setup:</strong><br>
  Now I want to create a Rails application that uses PostgreSQL.</p>
  
  <ul>
  <li>I installed Ruby 1.9.3-p125 via RVM.</li>
  <li>I installed Rails 3.2.3 into the Gemset ruby-1.9.3-p125@global.</li>
  <li>I created a .rvmrc and Gemset for the application.</li>
  <li>I created a Rails application via <code>rails new my_test_app -d postgresql</code>.</li>
  <li>I configured the <code>user</code> name and <code>password</code> in <em>config/database.yml</em> for <em>development</em> and <em>test</em> and removed <em>production</em>.</li>
  <li>I configured <code>host: localhost</code> and <code>port: 5433</code> in <em>config/database.yml</em>.</li>
  </ul>
  
  <p>Here is the content of my <em>config/database.yml</em> (removed comments for readability).</p>
  
  <pre><code>development:
    adapter: postgresql
    encoding: unicode
    database: my_test_app_development
    pool: 5
    username: johndoe
    password: password    
    host: localhost
    port: 5433
  
  test:
    adapter: postgresql
    encoding: unicode
    database: my_test_app_test
    pool: 5
    username: johndoe
    password: password
  </code></pre>
  
  <hr>
  
  <p><strong>Problem:</strong><br>
  However, when I run <code>bundle exec rake db:create:all</code> I receive the following error message.</p>
  
  <pre><code>could not connect to server: No such file or directory
  Is the server running locally and accepting connections on Unix domain socket
  "/var/run/postgresql/.s.PGSQL.5432"?
  [...]
  Couldn't create database for {"adapter"=&gt;"postgresql", "encoding"=&gt;"unicode",
  "database"=&gt;"my_test_app_test", "pool"=&gt;5, "username"=&gt;"johndoe",
  "password"=&gt;"password"}
  </code></pre>
  
  <hr>
  
  <p><strong>Question:</strong><br>
  Why is the port different to the one I use when I successfully connect via pgadmin3?</p>