Joe Morano
Joe Morano

Reputation: 1895

Postgresql won't accept password

I just created a new app and installed the 'pg' gem, created a psql user and database, and created a database.yml file. However, the server won't accept my password, even though it's the correct one.

Here are the commands I ran to create my user and database:

Project$ sudo -i -u postgres
postgres@user-F243:~$ psql
postgres=# CREATE USER Project WITH PASSWORD 'Project' CREATEDB;
postgres=# CREATE DATABASE Project OWNER Project;

which all went through with no errors. Then I created the following database.yml file:

development:
  adapter: postgresql
  database: Project
  username: Project
  password: Project
  host: localhost
  pool: 5
  timeout: 5000

test:
  adapter: postgresql
  database: Project
  username: Project
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: Project
  username: Project
  pool: 5
  timeout: 5000

But when I start my rails server and try to load a page, I get this error:

PG::ConnectionBad
FATAL: password authentication failed for user "Project" FATAL: password authentication failed for user "Project"

Extracted source (around line #56):

#54 ### Convenience alias for PG::Connection.new.
#55    def self::connect( *args )
#56         return PG::Connection.new( *args ) #line 56
#57    end

I have tried multiple different passwords and user/database names, and I tried making the user a superuser, but I always get the same result. I've done all this a million times and it's always worked. What's going on??

Upvotes: 0

Views: 1730

Answers (2)

Tomasz Myrta
Tomasz Myrta

Reputation: 1144

postgres=# CREATE USER Project WITH PASSWORD 'Project' CREATEDB;

This code creates user 'project' instead of 'Project'. If you really want to use uppercase in user names, you have to double quote them:

postgres=# CREATE USER "Project" WITH PASSWORD 'Project' CREATEDB;

The same goes with table and column names - both creating and querying them.

Upvotes: 1

jljohnstone
jljohnstone

Reputation: 1230

Try removing host: localhost from the development: group. I've had similar problems in the past and this fixed them for me.

Upvotes: 0

Related Questions