Open travisp opened 9 years ago
Hello, I had simuler issue where , commands and rake 'db:migrate' would not load the master db from the master shard. That was happening because they pre-load the db connection before running the command.
Solution for me was (using Rails app), adding this to 'config/initializers/octopus.rb'
if Octopus.enabled?
Octopus.config[Rails.env.to_s]['master'] = ActiveRecord::Base.connection.config
ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end
Not sure where you would do that in spring though.
Any luck with this?
I'm hitting a similar (I'm assuming) problem here:
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"clients"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
from /Users/jipiboily/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
It looks, for me, that using what @velles suggested works. Just add those lines in the config/spring.rb
.
This is what it looks like for me at this point:
Spring.after_fork do
if defined?(ActiveRecord::Base)
if Octopus.enabled?
Octopus.config[Rails.env.to_s]['master'] = ActiveRecord::Base.connection.config
ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end
ActiveRecord::Base.establish_connection
QC.default_conn_adapter = QC::ConnAdapter.new(ActiveRecord::Base.connection.raw_connection)
end
end
When running commands using spring, I'm unable to obtain a connection. Without spring everything works great. I imagine this has to do with how spring makes and holds database connections. There was a mention of this as an issue within a report about spork, but I couldn't find any open issues mentioning the problem with spring https://github.com/tchandy/octopus/issues/120