Thursday, June 14, 2012

PG::Error (FATAL: role "your_local_username" does not exist)

If you get the following error in Rails/ActiveRecord with pg/PostgreSQL:
Connecting to database specified by database.yml

PG::Error (FATAL:  role "your_local_username" does not exist
):
 activerecord (3.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:1206:in `initialize'
 activerecord (3.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:1206:in `new'
 activerecord (3.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:1206:in `connect'
 activerecord (3.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize'
 activerecord (3.2.6) lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
...
it could be that the user you specified doesn't exist.

But, the other possibility is that the property in database.yml for username is wrong. Instead of "user", use "username" in database.yml. Both may work for you depending on how you are setup, but "username" is correct, at least as of activerecord 3.2.6. This is confusing because there is conflicting info out there for setup. Thanks to Tommy for tracking this down!

No comments: