title: PGError: ERROR: source database "template1" is being accessed by other users
body: <p>I'm having problems getting testing to work with Postgresql and Rails 3.</p>
  
  <p>Both development and production databases I can get to work fine, however the test database throws the following errors when I run <code>rake</code> or <code>db:test:prepare</code>, etc.</p>
  
  <blockquote>
    <p>PGError: ERROR:  source database "template1" is being accessed by other users</p>
  </blockquote>
  
  <h1>Update</h1>
  
  <p>Googling around, it seems that one should use <code>template0</code> instead of <code>template1</code> when using createdb to create a new database in Postgres. In typical “So I’ll remove the cause. But not the symptom” fashion, I found <code>vendor/rails/railities/lib/task/databases.rake</code> and changed line 109 to read:</p>
  
  <pre><code>createdb #{enc_option} \
  -U "#{abcs["test"]["username"]}" \
  -T template0 #{abcs["test"]["database"]}
  </code></pre>
  
  <p>But I don't really wanna do that, as I'm using Rails as a GEM, any one know of another work around or fix?</p>
  
  <p><strong>database.yml</strong>:</p>
  
  <pre><code>development:
    adapter: postgresql
    encoding: unicode
    database: test1234_development
    pool: 5
    username: holden
    password: postgres
  
  test:
    adapter: postgresql
    encoding: unicode
    database: test1234_test
    pool: 5
    username: holden
    password: postgres
  </code></pre>
  
  <p><strong>Full error</strong>:</p>
  
  <blockquote>
    <p>NOTICE:  database "test1234_test" does not exist, skipping<br>
    PGError: ERROR:  source database "template1" is being accessed by other users<br>
    DETAIL:  There are 1 other session(s) using the database.<br>
    : CREATE DATABASE "test1234_test" ENCODING = 'unicode'  </p>
  </blockquote>