8

Weird error. All help appreciated.

Here's my database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: app_development
  pool: 5
  username: username
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: app_test
  pool: 5
  username: username
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: app_production
  pool: 5
  username: username
  password:

When I create the databases manually and try to use them, for example rake db:test:preare I get the following error:

FATAL:  database "postgres" does not exist

When I try to drop the databases I get the following errors:

Couldn't drop app_development : #<PG::Error: FATAL:  database "postgres" does not exist
>
Couldn't drop app_test : #<PG::Error: FATAL:  database "postgres" does not exist
>
Couldn't drop app_production : #<PG::Error: FATAL:  database "postgres" does not exist

If I try to create the databases through with rake db:create:all I get the following errors:

app_development already exists
app_test already exists
app_production already exists

So it appears that my database.yml is ok. But for some reason it's looking for a database called postgres when that's not what's in my database.yml.

Any help appreciated.

EDIT:

Here is more from the trace of rake:

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"app_production", "pool"=>5, "username"=>"username", "password"=>nil}

0

3 Answers 3

5

[Mac OS X] I've never had any problem with PostGreSQL while using Linux. However, I started working with a MacBook and got the same error as you. So... Probably this is not the solution you were expecting for, but this one app solved all my headaches. I just wanted to share it with you guys.

http://postgresapp.com/

Sign up to request clarification or add additional context in comments.

Comments

2

You've not said whether you actually have a postgres database, which is what the error is complaining about.

Presumably not, and this "rake" tool is connecting as user postgres to database postgres so it can create the new databases. Obviously it needs to connect as someone to do anything.

Do take the time to skim through the PostgreSQL manuals and understand how to enable/control logging. It'll serve you well in the long run. I'm guessing there is a debug/log setting for rake/rails too.

5 Comments

Hey, Thanks for the reply. I do have a postgres database and have been using it for rails apps for the last 6 months without any dramas. If I try my other apps using postgres everything works a treat. Not sure with this one. I'll have been looking through the rake trace but couldn't find anything
@user1432031: Richard doesn't mean "a postgres database" but "a database named postgres" - which is usually created as part of the installation of the database server.
Hey, that seems to have worked. I added a database postgres and now on first look I don't have any issues with my other rails databases. My other rails databases have worked before without this extra database. Do you guys have any idea why this might be the case?
@user1432031: as I said: by default a postgres database is created during installation. So I guess you other installs did do that and the new install didn't (for whatever reason)
The postgres service db is a relatively new invention from somewhere around the 8.0 era. If the OP is using a really old pg version it might not come with a postgres db.
0

I'm using Mac OS X, I had the same problem with python and sqlalchemy. Just like Flavio suggested, check postgresapp and check How to connect section.

from sqlalchemy import create_engine
engine = create_engine('postgresql://localhost/[YOUR_DATABASE_NAME]')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.