0

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??

3
  • Can you try lower-case user name? Using upper-case user names in PostgresSQL is tricky. You didn't quote name and actually created user "project" instead of "Project". Commented Jul 14, 2017 at 19:04
  • @TomaszMyrta Wooow, yeah that was it. Thanks. Never would have guessed case would matter. Commented Jul 14, 2017 at 20:21
  • What is the authentication method assigned for that user in the pg_hba.conf file? Commented Jul 14, 2017 at 22:53

2 Answers 2

1
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.

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

2 Comments

That's crazy, I would've thought they'd include something about case if it was that finicky. Thanks!
You can find more in documentation - SQL Syntax/Lexical Structure/Identifiers and Key Words.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.