title: rake db:create using PostgreSQL ---- fe_sendauth: no password supplied
body: <p>New to all this so please be patient. Basically I was trying to follow <a href="https://gorails.com/setup/ubuntu/14.04" rel="nofollow">this</a> to get Rails set up on my Linux Lite machine. After installing PostgreSQL I went ahead to create a database role, as per the tutorial instructions, like this</p>
  
  <pre><code>sudo -u postgres createuser tjjjwxzq -s
  </code></pre>
  
  <p>But I didn't follow up with creating a password with this role, as the tutorial made it seem like it was an optional thing. I specified the development environment username in my <code>database.yml</code> file:</p>
  
  <pre><code>development:
    &lt;&lt;: *default
    database: myapp_development
  
    # The specified database role being used to connect to postgres.
    # To create additional roles in postgres see `$ createuser --help`.
    # When left blank, postgres will use the default role. This is
    # the same name as the operating system user that initialized the database.
    username: tjjjwxzq
  
    # The password associated with the postgres role (username).
    #password:
  
    # Connect on a TCP socket. Omitted by default since the client uses a
    # domain socket that doesn't need configuration. Windows does not have
    # domain sockets, so uncomment these lines.
    #host: localhost
  </code></pre>
  
  <p>(<strong>Edit:</strong> I uncommented <code>host:localhost</code>)</p>
  
  <p>I also changed the <code>pg_hba.conf</code> file to authenticate with the role I created:</p>
  
  <pre><code># Database administrative login by Unix domain socket
  local   all             postgres                                peer
  
  # TYPE  DATABASE        USER            ADDRESS                 METHOD
  
  # settings for tjjjwxzq user
  local   all             tjjjwxzq                                     trust
  
  # "local" is for Unix domain socket connections only
  local   all             all                                     md5
  # IPv4 local connections:
  host    all             all             127.0.0.1/32            md5
  # IPv6 local connections:
  host    all             all             ::1/128                 md5
  </code></pre>
  
  <p>As you can see I set the authentication method for the <code>tjjjwxzq</code> user to <code>trust</code>, because I didn't create a password and I don't want to have to supply one. But when I run, in my Rails project directory</p>
  
  <pre><code>rake db:create
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>fe_sendauth: no password supplied
  ...
  Couldn't create database for {"adapter"=&gt;"postgresql", "encoding"=&gt;"unicode", "pool"=&gt;5, "database"=&gt;"myapp_test"}
  </code></pre>
  
  <p>I am completely new to PostgreSQL and Rails, and I have been googling around for a solution for hours now. Changing the <code>pg_hba.conf</code> file seemed promising, but it hasn't worked for me. I suspect I could get pass this by specifying a password for the <code>tjjjwxzq</code> role I created, but I want to understand why my setup now is not working. Any help is much appreciated.</p>
  
  <p><strong>EDIT:</strong>
  Okay, I've realized I've made a dumb mistake. <code>rake db:create</code> does work for creating <code>myapp_development</code> (the specified development database) I've checked the log file, and the latest logs were:</p>
  
  <pre><code>2015-04-01 07:04:28 SGT [2342-1] tjjjwxzq@postgres ERROR:  database "myapp_development" already exists
  2015-04-01 07:04:28 SGT [2342-2] tjjjwxzq@postgres STATEMENT:  CREATE DATABASE "myapp_development" ENCODING = 'unicode'
  </code></pre>
  
  <p>Now I realize that in the output for <code>rake db:create</code>, the last line displays</p>
  
  <pre><code>Couldn't create database for {"adapter"=&gt;"postgresql", encoding"=&gt;"unicode", "pool"=&gt;5, "database"=&gt;"myapp_test"}
  </code></pre>
  
  <p>So the problem was actually with my test database, and looking at my <code>database.yml</code> file, I see:</p>
  
  <pre><code>default: &amp;default
    adapter: postgresql
    encoding: unicode
    # For details on connection pooling, see rails configuration guide
    # http://guides.rubyonrails.org/configuring.html#database-pooling
    pool: 5
  
  # Warning: The database defined as "test" will be erased and
  # re-generated from your development database when you run "rake".
  # Do not set this db to the same as development or production.
  test:
    &lt;&lt;: *default
    database: myapp_test
  </code></pre>
  
  <p>So there is no <code>username</code> field. Thanks for your help so far, but now my questions would be: 1) is it okay for <code>myapp_test</code> to not be created successfully, or should I set its user to <code>tjjjwxzq</code> as well? And 2) where can a newb like me read up more about this to get a better understanding (but nothing overwhelmingly technical, for now) of what is going on and the need for the <code>development</code>, <code>test</code> and <code>production</code> configs and environments? Rails docs? </p>