# PostgreSQL Test Database DNE for rake, does exist for psql

**URL:** <https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960>\
**Category:** Rails\
**Created:** [February 5, 2010, 8:57am UTC](https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960 "2010-02-05T08:57:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveybaby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@steveybaby](https://www.ruby-forum.com/u/steveybaby)\
**Post date:** [February 5, 2010, 8:57am UTC](https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960/1 "2010-02-05T08:57:36Z")

</div>

Hello All,

I’m relatively new to Ruby and Rails. I’m working with PostgreSQL  
successfully as a development database server, and I want to use it in  
production and testing as well. My development server is called  
(myapp)\_dev. My test database server is called (myapp)\_test. Both exist  
on the same machine and both were created using the createdb PostgreSQL  
function.

I can’t connect to the test database using rake db:test:prepare. The  
message that shows up in my pgsql logfile is “FATAL: database  
(myapp)\_test does not exist”. Yet if I try to create a database with  
that name using the createdb function, this shows up in my log: “ERROR:  
(myapp)\_test already exists”.

I’m sure it’s something simple that I’m doing wrong, but I can’t figure  
out what. Any help is appreciated.

Using Ruby 1.8.7, Rails 2.3.5, PostgreSQL 8.4.2 and Mac OS X Snow  
Leopard.

---

<div class="post-metadata">

**Author:** ![steveybaby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@steveybaby](https://www.ruby-forum.com/u/steveybaby)\
**Post date:** [February 5, 2010, 9:01pm UTC](https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960/2 "2010-02-05T21:01:08Z")

</div>

Steve H. wrote:

> Hello All,
> 
> I’m relatively new to Ruby and Rails. I’m working with PostgreSQL  
> successfully as a development database server, and I want to use it in  
> production and testing as well. My development server is called  
> (myapp)\_dev. My test database server is called (myapp)\_test. Both exist  
> on the same machine and both were created using the createdb PostgreSQL  
> function.
> 
> I can’t connect to the test database using rake db:test:prepare. The  
> message that shows up in my pgsql logfile is “FATAL: database  
> (myapp)\_test does not exist”. Yet if I try to create a database with  
> that name using the createdb function, this shows up in my log: “ERROR:  
> (myapp)\_test already exists”.
> 
> I’m sure it’s something simple that I’m doing wrong, but I can’t figure  
> out what. Any help is appreciated.

Permissions issue, perhaps? And does script/dbconsole work for your  
test database?

> Using Ruby 1.8.7, Rails 2.3.5, PostgreSQL 8.4.2 and Mac OS X Snow  
> Leopard.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![steveybaby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@steveybaby](https://www.ruby-forum.com/u/steveybaby)\
**Post date:** [February 5, 2010, 9:53pm UTC](https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960/3 "2010-02-05T21:53:34Z")

</div>

> Marnen Laibow-Koser wrote:
> 
> Permissions issue, perhaps? And does script/dbconsole work for your  
> test database?
> 
> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

Thanks for the response.

Running ‘script/dbconsole test’ does put me in psql for my test  
database. I’m (OS X username) set as the owner for both my dev and test  
environment.

I thought possibly I just needed a restart of the server, but that was  
also to no avail.

---

<div class="post-metadata">

**Author:** ![steveybaby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@steveybaby](https://www.ruby-forum.com/u/steveybaby)\
**Post date:** [February 5, 2010, 11:14pm UTC](https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960/4 "2010-02-05T23:14:54Z")

</div>

Steve H. wrote:

> > Marnen Laibow-Koser wrote:
> > 
> > Permissions issue, perhaps? And does script/dbconsole work for your  
> > test database?
> > 
> > ## Best,
> > 
> > Marnen Laibow-Koser  
> > [http://www.marnen.org](http://www.marnen.org)  
> > removed\_email\_address@domain.invalid
> 
> Thanks for the response.
> 
> Running ‘script/dbconsole test’ does put me in psql for my test  
> database.

OK.

> I’m (OS X username) set as the owner for both my dev and test  
> environment.

That’s irrelevant. What is relevant is which Postgres user account  
Rails is using to connect to the DB. Does that account have the  
appropriate permissions?

> I thought possibly I just needed a restart of the server, but that was  
> also to no avail.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![steveybaby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@steveybaby](https://www.ruby-forum.com/u/steveybaby)\
**Post date:** [February 7, 2010, 1:41am UTC](https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960/5 "2010-02-07T01:41:07Z")

</div>

I guess I’ve just been paying far too much attention to the log file of  
Postgres. I think every time a test is launched, the database is dropped  
and then created. It seems to log a “database does not exist” message  
every time. I paid a bunch of attention to this because of built-in  
tests failing.

Thanks to Marnen for his efforts and patience.

---

<div class="post-metadata">

**Author:** ![steveybaby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c57346/32.png) [@steveybaby](https://www.ruby-forum.com/u/steveybaby)\
**Post date:** [February 5, 2010, 11:24pm UTC](https://www.ruby-forum.com/t/postgresql-test-database-dne-for-rake-does-exist-for-psql/182960/6 "2010-02-05T23:24:21Z")

</div>

> That’s irrelevant. What is relevant is which Postgres user account  
> Rails is using to connect to the DB. Does that account have the  
> appropriate permissions?

Postgres user account is the same name as my machine user account,  
that’s why I mentioned it. Same postgres user has created and owns both  
databases, and is a superuser.

I’ve since tried making another database and another postgres user, but  
I’m still getting the message “FATAL: database “(myapp)\_test” does not  
exist”
