PostgreSQL Test Database DNE for rake, does exist for psql

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.

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
[email protected]

Marnen Laibow-Koser wrote:

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

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

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.

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
[email protected]

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
[email protected]

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.

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”