Jeremy,
Note, I am not saying it is a sequel issue :) but that side effect of non
lazy connection was an issue for us recently because we rely on that sequel
"feature". We are clearly going to work around the problem on our end.
Thanks for pointing out that lazy connection is not an actual feature but
rather implementation detail and can change in the future. In this case
this thread would be sufficient documentation if somebody else run into
similar situation.
Thanks,
-Alex
On Friday, February 1, 2013 3:04:06 PM UTC-6, Jeremy Evans wrote:
>
> On Friday, February 1, 2013 11:59:09 AM UTC-8, Alex Vinnik wrote:
>>
>> Hi all.
>>
>> Looks like we run into an issue with postgres adapter
>> when connection_validator extension is used. The problem is simple. DB
>> connection is NOT lazy anymore when connection_validator is activated.
>> Sequel version is 3.43.0. Consider this snippet
>>
>> #!/usr/bin/env ruby
>>
>> require "sequel"
>> require 'logging'
>>
>> logger = Logging.logger(STDOUT)
>> logger.level = :debug
>>
>> logger.info 'Starting...'
>>
>> DB = Sequel.connect(:adapter => 'postgres',
>> :username => 'whatever', :password => 'whatever'',
>> :database => 'whatever'', :host => 'localhost')
>>
>> logger.info DB.inspect
>> DB.loggers << logger
>>
>> DB.extension(:connection_validator)
>>
>> DB.loggers << logger
>> puts `sudo netstat -ntp | egrep '5432.*ESTABLISHED.*#{Process.pid}'`
>>
>> You can run it and see that DB connection gets established even no SQL is
>> fired by the app. It is certainly not a lazy connection.
>>
>> I, [2013-02-01T13:45:49.668455 #19887] INFO : Starting...
>> I, [2013-02-01T13:45:49.729210 #19887] INFO :
>> #<Sequel::Postgres::Database: {:adapter=>"postgres",
>> :username=>"transporter", :password=>"2ownTransporter",
>> :database=>"transporter", :host=>"localhost"}>
>> I, [2013-02-01T13:45:49.757414 #19887] INFO : (0.000299s) SET
>> standard_conforming_strings = ON
>> I, [2013-02-01T13:45:49.757832 #19887] INFO : (0.000280s) SET
>> client_min_messages = 'WARNING'
>> I, [2013-02-01T13:45:49.758023 #19887] INFO : (0.000129s) SET DateStyle
>> = 'ISO'
>> tcp6 0 0 ::1:48713 ::1:5432
>> ESTABLISHED 19887/ruby
>> I, [2013-02-01T13:45:49.831646 #19887] INFO : Finished...
>>
>> After some digging in the code and seems like calling server_version in
>> select_clause_methods triggers DB connection.
>>
>> https://github.com/jeremyevans/sequel/blob/master/lib/sequel/adapters/shared/postgres.rb#L1303
>> here is server_version code...
>>
>> https://github.com/jeremyevans/sequel/blob/master/lib/sequel/adapters/shared/postgres.rb#L453
>>
>> Just to compare... connecting to MS SQL does have lazy connection. I
>> totally understand rationale behind this code and the need to have PG
>> version handy in order to prepare statements but it is sort inconsistent
>> with other adapters. May be to document this PG connection_validator
>> "feature" because I don't think it easily fixable at the moment. What do
>> you think?
>>
>
> Your analysis appears to be correct, but could you explain why this is an
> issue? The point at which Sequel makes a connection is an implementation
> detail, so I'm not sure why we should document it. There are other
> database extensions that cause a connection (the pg_hstore extension, for
> example), so the connection_validator extension is not alone in this.
>
> The fact that Sequel usually creates connections lazily is itself an
> implementation detail. It's definitely possible that a connection attempt
> will automatically be made on Sequel::Database initialization in the
> future, in order to fail fast.
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.