On Friday, October 28, 2016 at 1:49:42 PM UTC-7, [email protected] wrote:
>
> It is currently possible to define the cursor name used for a Postgres 
> dataset using the `Sequel::Postgres::Dataset#use_cursor` method. This is 
> handy for preventing duplicate cursors in an iteration, however I'm not 
> sure why this would be necessary.
>
> I would think that the Postgresql Cursors should always be unique. I've 
> been having issues with parallel background processes throwing 
> `Sequel::DatabaseError: 
> PG::DuplicateCursor: ERROR: cursor "sequel_cursor" already exists` errors 
> on iterations, which I've resolved by using dynamic cursor names based on 
> timestamps, i.e.
>
>         cursor_name = "sequel_cursor_%s" % DateTime.now.strftime(
> "%Y%m%d_%H%M%S_%L")
>         User.use_cursor(cursor_name: cursor_name).paged_each do |user|
>         ...
>
>
>
> I'm probably missing something, but why not make cursor names unique by 
> default to prevent collisions? Is there a specific reason to use the `
> sequel_cursor` name for all cursors? If not, I'd be happy to submit a 
> patch but figured I'd ask first :)
>

Having a static name is simpler to implement and faster if you don't need 
to nest cursor use (and few people do).  It's almost always possible to 
avoid nested cursor use, and alternative approaches can be easier to 
understand.

Can you provide a simple, self contained example showing the problems you 
are experiencing?  PostgreSQL cursor names are per-connection, so the only 
time you should be getting that error is if you are nesting cursor use or 
you have multiple threads/processes operating on the same connection (a 
serious error you should fix in your background job handling code).

This is not to say I'm completely against dynamic cursor names, I'm open to 
feedback from other users of #with_cursor to see what they think, and would 
consider changing the current behavior. If we did switch to dynamic cursor 
names, I would prefer a per-connection counter instead of your approach 
(which has a race condition if multiple cursors are created in the same 
millisecond). 

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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to