Daniel Higginbotham
2010-Apr-06 16:19 UTC
how does Rails / Apache handle database connections?
Hi all, I''m trying to figure out how Rails handles database connections. The business problem is: * My users have access to multiple, structurally identical schemas * So, for each request, Rails needs to be able to talk to a different schema * It''s essential that users not pull data from the wrong schema A couple more rules: * During the request, the schema used will not change * All the schemas can be accessed from one database server using one set of login credentials The solution I''m contemplating is to execute a "use" statement for each request, so that all subsequent queries use the correct table. My questions are: * How many database connections does each Rails process create? * Does this vary by adapter? (I''m using MS SQL Server) * Does apache pool database connections in any way? * Are database connections independent of Rails processes on apache? Thanks! Daniel -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Apr-06 17:52 UTC
Re: how does Rails / Apache handle database connections?
On Apr 6, 5:19 pm, Daniel Higginbotham <dan...-4cOk6EWy6wjNj93mkU9IYrqjc7CnNF17@public.gmane.org> wrote:> Hi all, > > I''m trying to figure out how Rails handles database connections. The > business problem is: > * My users have access to multiple, structurally identical schemas > * So, for each request, Rails needs to be able to talk to a different > schema > * It''s essential that users not pull data from the wrong schema > > A couple more rules: > * During the request, the schema used will not change > * All the schemas can be accessed from one database server using one > set of login credentials > > The solution I''m contemplating is to execute a "use" statement for > each request, so that all subsequent queries use the correct table. > > My questions are: > * How many database connections does each Rails process create? > * Does this vary by adapter? (I''m using MS SQL Server) > * Does apache pool database connections in any way? > * Are database connections independent of Rails processes on apache? >Each rails process has a pool of connections (by default up to 5). I believe you can add a hook that runs after a connection is checked out (eg to set the current database). This layer of abstraction is independent of the various adapters. If you are using a multithreaded environment (of which the only one of note are the jruby ones, which your questions about apache imply you are not using) then you might have to be extra specially careful Apache doesn''t come into this at all. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Daniel Higginbotham
2010-Apr-07 11:20 UTC
Re: how does Rails / Apache handle database connections?
This helped - thank you! On Apr 6, 1:52 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 6, 5:19 pm, Daniel Higginbotham > > > > > > <dan...-4cOk6EWy6wjNj93mkU9IYrqjc7CnNF17@public.gmane.org> wrote: > > Hi all, > > > I''m trying to figure out how Rails handles database connections. The > > business problem is: > > * My users have access to multiple, structurally identical schemas > > * So, for each request, Rails needs to be able to talk to a different > > schema > > * It''s essential that users not pull data from the wrong schema > > > A couple more rules: > > * During the request, the schema used will not change > > * All the schemas can be accessed from one database server using one > > set of login credentials > > > The solution I''m contemplating is to execute a "use" statement for > > each request, so that all subsequent queries use the correct table. > > > My questions are: > > * How many database connections does each Rails process create? > > * Does this vary by adapter? (I''m using MS SQL Server) > > * Does apache pool database connections in any way? > > * Are database connections independent of Rails processes on apache? > > Each rails process has a pool of connections (by default up to 5). I > believe you can add a hook that runs after a connection is checked > out (eg to set the current database). This layer of abstraction is > independent of the various adapters. If you are using a multithreaded > environment (of which the only one of note are the jruby ones, which > your questions about apache imply you are not using) then you might > have to be extra specially careful > > Apache doesn''t come into this at all. > > Fred-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.