I have a basic rails3 app that I am deploying on site5. I have installed all the required gems, using bundler, and when I try to run rake db:migrate or rake db:schema:load, I get:
# rake RAILS_ENV=production db:schema:load
(in /home/xxx/rails/costfinder)
rake aborted!
Access denied for user 'root'#'localhost' (using password: YES)
My config/database.yml has:
production:
adapter: mysql2
database: xxx_costfinder_production
user: ****
password: ******
encoding: utf8
reconnect: true
pool: 5
socket: /tmp/mysql.sock
I have no idea why rails is trying to connect as root. Any suggestions? My experience is with rails2, this is my first stab at a rails3 app.
Aieeee, it's username, not user
Related
While deploying an application with Rails 3.2.17, we are getting following error.
eb-commandprocessor.log
+ su -s /bin/bash -c 'leader_only bundle exec rake db:migrate' webapp
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/var/app/ondeck/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace) (ElasticBeanstalk::ActivityFatalError)
at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:189:in `rescue in exec'
...
caused by: command failed with error code 1: /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh
Here is our database.yml configuration
production:
adapter: postgresql
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
Surprisingly we are able to start rails console and we also verified that all above environment variables return correct value.
And also able to connect via psql with following command
psql -h RDS_HOSTNAME -d RDS_DB_NAME -U RDS_USERNAME
On my side the issue was coming from the fact that I deleted my .elasticbeanstalk/optionsettings and so RACK_ENV was not defined, AWS set it by default to production which led my application to have the wrong database hostname.
I debugged that by adding echo statement in /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh to display RACK_ENV and noticed it was empty.
Update: Running
RAILS_ENV=development rake db:create
... works. But the rake commands without the RAILS_ENV prefix don't. What gives?
For some reason, I am no longer able to interact with my development database at all anymore.
I've tried rake db:create, and it makes my test database fine, but the dev one is not created at all.
I'm using the postgresapp.com, and up until just recently, it was working flawlessly. No changes to my config/database.yml file have been made recently, nor to any of my app config files.
I can connect to my test database fine with psql -h localhost redtail_test, and it uses the same connection credentials as my dev box, so I'm reasonably sure it's not a connection issue with PG--unless it's a weird one.
redtail git:master ❯ rake db:create
redtail_test already exists
redtail git:master ❯ psql -h localhost redtail
psql: FATAL: database "redtail" does not exist
Has anyone ran into this issue?
common: &common
encoding: utf8
postgres: &postgres
adapter: postgresql
user: postgres
password:
min_messages: WARNING
development: &development
<<: *common
<<: *postgres
host: localhost
database: redtail
memory: &memory
<<: *common
adapter: sqlite3
host: localhost
database: ":memory:"
test: &test
<<: *common
<<: *postgres
host: localhost
database: redtail_test
production:
adapter: postgresql
encoding: utf8
database: redtail
cucumber:
<<: *test
I have a Rails 3.2.1 project that I'm trying to run my specs on.
When I run:
rake
rake aborted! PG::Error: ERROR: invalid value for parameter
"search_path": "example" DETAIL: schema "example" does not exist :
SET search_path TO example
From what I can work out, rake db:test:prepare drops the test database and then attempts to recreate it from the schema.rb. The thing is, database.yml has the line
schema_search_path: example
so when it tries to reconnect, it fails with the above error.
I think my question is, how can I get rake db:test:prepare to setup the schema_path too?
One solution is to add a bit of code to the db:create task that creates the schema. Put this in a rake task, for exmaple 'APP_ROOT/lib/tasks/db_create_schema.rake'
namespace :db do
task :create do
config = Rails.configuration.database_configuration[Rails.env].merge!({'schema_search_path' => 'public'})
ActiveRecord::Base.establish_connection(config)
ActiveRecord::Base.connection.execute("CREATE SCHEMA schema_name")
end
end
https://gist.github.com/4280172
You should set the schema_search_path in your config/database.yml
e.g.
development:
adapter: postgresql
encoding: unicode
database: test
pool: 5
username: user
password: password
#host: localhost
#port: 5432
# Schema search path. The server defaults to $user,public
schema_search_path: example
I've a Refinery app, works great locally.
Created a bamboo stack on Heroku.
When I try to push I can see this:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Then I open it up in browser:
"We're sorry, but something went wrong."
$ heroku logs
Rendered vendor/bundle/ruby/1.9.1/gems/refinerycms-authentication-2.0.2/app/views/refinery/users/new.html.erb within refinery/layouts/login (82.3ms)
2012-03-15T14:43:25+00:00 app[web.1]: Completed 500 Internal Server Error in 1269ms
full output is here
Any help is great, thanks!
+++
Update:
Updated the stack to Cedar and made Ruby env 1.9.3
$ heroku config
DATABASE_URL => ..
GEM_PATH => vendor/bundle/ruby/1.9.1
LANG => en_US.UTF-8
PATH => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV => production
RAILS_ENV => production
RUBY_VERSION => ruby-1.9.3-p0
SHARED_DATABASE_URL => ..
$ heroku info --app mimacohuoncedar
=== mimacohuoncedar
Addons: Basic Logging, Shared Database 5MB
Database Size: (empty)
Git URL: git#heroku.com:mimacohuoncedar.git
Owner: ..
Repo Size: 9M
Slug Size: 19M
Stack: cedar
Web URL: http://mimacohuoncedar.herokuapp.com/
$ heroku logs now shows this:
this-updated
Where to go on? Thanks
Dont know if you managed to fix this but I ran into the same issue using the Cedar stack. Found this article on Heroku that seemed to do the trick for me. Ran the line in terminal and it pushed first time.
I am seeing this same error, and the accepted answer did not solve it for me;
This blog however, did the trick. The blog title refers to Rails 3.2, but I'm on 3.1 and was seeing this same error.
The blog recommended adding this line to application.rb.
config.assets.initialize_on_precompile = false
The meaning, as summarized from the article;
This option prevents the Rails environment from being loaded when the assets:precompile task is executed. Because Heroku precompiles assets before setting the database configuration, you need to set this configuration to false or you Rails application will try to connect to an unexisting database.
Added the line and pushed, everything seems good now.
That output looks suspiciously like Cedar stack and not Bamboo - give http://devcenter.heroku.com/articles/labs-user-env-compile a go. That should sort you out.
I've been trying for a good while to get Rails to talk to MySQL. I was able to install the 'mysql2' gem (v0.2.7), create a new rails app defaulting to MySQL:
rails new mytest -d mysql
and bundle install everything.
However, when I run rake db:create, it simply hangs, no errors, no anything.
Running rake db:create --trace hangs at '** Execute db:create'.
My database.yml configuration:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: mytest_development
pool: 5
username: root
password: passwordforrootuser
host: localhost
Using:
Windows 7 (64-bit)
MySQL 5.5 Server (32-bit)
Ruby 1.9.2
Really at my wit's end. Help???
Might be worth a try, if you include:
socket: /tmp/mysql.sock
My setup, normally looks like:
adapter: mysql2
encoding: utf8
reconnect: false
database: foobar_development
pool: 5
username: root
password: ***************
socket: /tmp/mysql.sock