3

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.

10
  • I can see you are using different port than specified in your database.yml : connection received: host=localhost port=53920. Commented Apr 25, 2013 at 20:13
  • You should ask yourself a question with which env is your app starting? Commented Apr 25, 2013 at 20:19
  • @QumaraSixOneTour This is what's puzzling as well, as in my postgresql.conf the port is set explicitly to 5432. I can see in the logs that each time there's a connection attempt the port increments so setting the port to 53920 will be different the next time connection attempts are made Commented Apr 25, 2013 at 21:05
  • the port in the log files is the port the connection is coming from, in other words, the client is using outgoing port 53920 to connect to incoming port 5432. Commented Apr 25, 2013 at 21:06
  • Could you post the command you're using to start your rails server? Commented Apr 25, 2013 at 21:07

1 Answer 1

1

Did you restart you system after postgres installation?

Are you able to access postgres from pg console?

Follow below link for proper installation of postgers.

http://railskey.wordpress.com/2012/05/19/postgresql-installation-in-ubuntu-12-04/

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

3 Comments

Please sum up the steps in the URI as that link could fail to work for any number of reasons
Thanks for the reply! All servers have been rebooted since the initial installation, Unicorn, Ubuntu, and pg. I do have access to the pg console and can log into my apps db from it, this leads me to believe that the issues is not with the postgres installation.
what error you getting in console? database.yml Make sure, you wrote right user_name and passworrd. default user name will be "postgres" and password "unix root password" if your steps included my blog 7th step.

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.