1

Just start with rails and Linux a few days a go... I want to deploy to heroku and one of there best practice is to user postgresql in local environment too anyway... I followed one of there tutorials and created a sample application

the pg gem installed. bundle install works ok. rake db:migrate works and created the table for my application. but... when i try to run my rails page it gives this error:

ActiveRecord::ConnectionNotEstablished

This is the end of the full trace:

> activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
activerecord (3.2.3) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.3) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__4423031206660944571__call__1711406629982304701__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'

i am using pgadmin 3 to see my db. i created a user named schaller which is the same as my user in Ubuntu

my database.yml file:

development:
  adapter: postgresql
  database: rails
  encoding: unicode
  username: schaller
  password: password123
  host: localhost
  pool: 5

what else can i check in order for rails to connect to postgres?

edit:

error when starting the rails server in netbeans on webrick

Started GET "/gangs/" for 127.0.0.1 at 2012-09-13 23:12:31 +0300 ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished): activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_pool.rb:398:in retrieve_connection' activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:168:inretrieve_connection' activerecord (3.2.3) lib/active_record/connection_adapters/abstract /connection_specification.rb:142:in connection' activerecord (3.2.3) lib/active_record/query_cache.rb:67:inrescue in call' ...

edit the main stuff in my gem file:

gem 'rails', '3.2.3'
gem 'pg'
gem 'thin'

edit: adding logs for the postgresql connections

[local]
2012-09-15 18:05:35 IDT LOG:  connection received: host=127.0.0.1 port=44038
2012-09-15 18:05:35 IDT LOG:  connection authorized: user=schaller database=postgres
2012-09-15 18:05:35 IDT LOG:  connection received: host=127.0.0.1 port=44039
2012-09-15 18:05:35 IDT LOG:  connection authorized: user=schaller database=rails
2012-09-15 18:07:26 IDT LOG:  connection received: host=127.0.0.1 port=44048
2012-09-15 18:07:26 IDT LOG:  connection authorized: user=schaller database=rails

anyway i see logs being written when i connect with pgadmin 3 and when i run the command, 'rake db:migrate' but not when i run my rails app...

thanks

4
  • How are you starting up your Rails server? Are there any errors when it starts up? Commented Sep 13, 2012 at 22:26
  • i start it through netbeans. it starts webrick. it starts with the same errors. ill edit my question and put it there Commented Sep 14, 2012 at 6:20
  • 1
    what's in your Gemfile? what adapter you are using? Commented Sep 14, 2012 at 6:33
  • i added the main stuff in my gem file. the others are defaults.. what do you mean what adapter?.. sorry new to rails Commented Sep 15, 2012 at 14:52

3 Answers 3

1

OK so its been a few days.. i read all answers and comments again because i really needed a solution anyway! the comment left by @Muhammad Sannan did the trick. i am new to rails so i didn't know what an adapter is.. but after a quick google search i ran this command:

gem install activerecord-postgresql-adapter

and that did the trick :)

everything is working now. i just don't understand how db:migrate worked without this adapter..

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

Comments

0

I think the problem is with your database.yml. You missed production section which is as I think the mode you are using on heroku. Simply add

production:
  adapter: postgresql
  database: rails
  encoding: unicode
  username: schaller
  password: password123
  host: localhost
  pool: 5

to your database.yml on heroku

2 Comments

i have the production section. im not yet deploying. i am trying to make this work on my local machine. this is why i only shared the development section of the database file
and just so you will knoe. heroku overwrites your database file when you deploy.. and they put there own file.
0

Well, if you can see the db in pgadmin you know the basic connection details are correct. If you've not tinkered in pgadmin, it's unlikely that the port number or other details have changed either.

So - we need to find out what's going on. First step is to turn connection logging on in PostgreSQL and see whether rails is actually connecting. Set log_connections on and restart PG then see what happens. If you don't see anything in the logs, but do from pgadmin then rails isn't seeing the right connection settings.

http://www.postgresql.org/docs/current/static/runtime-config-logging.html#GUC-LOG-CONNECTIONS

3 Comments

ok i did that. i can't find where the log is at.. the directory is set to: pg_log but where is it?.. while trying these stuff i noticed something weird. when i go to databases in pgadmin my rails database has a little red "X" on it. i click it i see the database and the X is gone. but... when i press the server and then refresh the X is back. like the connection isn't staying open. don't know if it happened before i started with the logging
All standard packages on linux will be logging somewhere under /var/log/
ok thanks. i edited my question with the logs. when i run the rails application there is nothing written to the logs. but if i run rake db:migrate or open the pgadmin 3 there are entries of login in the logs where are all good. but no log is written when i try to run my app

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.