Problem
Hitting my rails app in production results in a 500 error. Checking the production log results in: gist. Checking the verbose postgresql log results in: gist (actual db creds have been replaced). The postgres logs are showing the port number increment every connection attempt despite what's specified in the database.yml file.
Environment
Server: Ubuntu 12.10 (GNU/Linux 3.5.0-17-generic i686)
Rack Server: Unicorn
Rails v: 3.2.13
Ruby v: 1.9.3p0 (really old, perhaps a problem here?)
What I've Tried
Double check database.yml:
Tried w/ and w/o host and port, checked indentation and validated yaml formatting.
production:
adapter: postgresql
database: <db_production>
username: <db_user>
password: <db_password>
host: localhost
port: 5432
Run rake, rails c, and rails db:
I can log in and successfully run all of these commands. I am having to specify the environment here, perhaps this is the issue? is the environment not getting set somehow?
bundle exec rails db production
running:
Rails.env?
results in production, but this is after explicitly logging into rails c production.
Change pg_hba.conf:
I have tried several settings I've found in other SO questions. The original settings for local were:
local all all peer
Then tried:
local all all md5
Then tried:
local all all trust
After all of these changes I made sure to either restart pg or pg_ctl reload to pickup the changes.
Log into pg outside or rails:
Even after each change to pg_hba.conf I can still login to my production database with the same creds in database.yml and see all of my data, and confirm all migrations and db creations have run.
running:
sudo -u <db_user> psql <db_production>
works as expected.
Conclusion
It's obvious to me that the problem is not with postgres but with the rails config, perhaps the environment isn't switching to production and thus it's trying to use dev db creds? which don't exist in my production yml file.
database.yml
:connection received: host=localhost port=53920
. – R Milushev Apr 25 '13 at 20:13