Re: [psycopg] Changing set_session implementation

Поиск
Список
Период
Сортировка
От Daniele Varrazzo
Тема Re: [psycopg] Changing set_session implementation
Дата
Msg-id CA+mi_8a3+DJyx-SLdL34M57Ahs2s6dHF+mn5UrZGjQkFDZ-+jg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [psycopg] Changing set_session implementation  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Ответы Re: [psycopg] Changing set_session implementation
Re: [psycopg] Changing set_session implementation
Список psycopg
Hi Karsten, sorry for the late reply,

no, `conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)` is not a no-op:

    In [1]: import psycopg2

    In [2]: psycopg2.__version__
    Out[2]: '2.7.3 (dt dec pq3 ext lo64)'

    In [3]: cnn = psycopg2.connect('')

    In [4]: cnn.autocommit
    Out[4]: False

    In [5]: cnn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)

    In [6]: cnn.autocommit
    Out[6]: True

but if your connection was already autocommit then sure it will not do anything.

If you want to be absolutely sure about what the adapter does I
suggest you to enable statements log on the server and check what
statements are produced by psycopg. If you find any behaviour
inconsistent with what documented please let us know.

Hope this helps

-- Daniele


On Mon, Jul 31, 2017 at 11:51 AM, Karsten Hilbert
<Karsten.Hilbert@gmx.net> wrote:
> Hopefully I just hit summer vacation -- or else do I need to
> provide more information to get an answer on the below ?
>
> Thanks,
> Karsten
>
> On Thu, Jul 27, 2017 at 04:17:33PM +0200, Karsten Hilbert wrote:
>
>> On Sat, Feb 04, 2017 at 04:33:13PM +0000, Daniele Varrazzo wrote:
>>
>> > I've changed the set_session/set_isolation_level/autocommit connection
>> > methods and properties to use better the BEGIN parameters
>> ...
>> > Conversely:
>> >
>> >     conn.set_session(readonly=True, autocommit=True)
>>
>> Does this mean that
>>
>>       conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
>>
>> is now a no-op as observed by the following log snippet or
>> just diverted to set_session(autocommit=True) ?
>>
>>
>> code:
>>
>>       _log.debug('conn state now: %s', gmPG2.capture_conn_state(self.conn))
>>       _log.debug('setting isolation level to autocommit - should be redundant ?')
>>       self.conn.set_isolation_level(0)
>>       _log.debug('conn state now: %s', gmPG2.capture_conn_state(self.conn))
>>
>> log:
>>
>>       2017-07-27 16:03:01  DEBUG     gm.bootstrapper  MainThread (-1219281664)
(./bootstrap_gm_db_system.py::__create_db()#810): conn state now: <connection object at 0xb64eca04; dsn:
'dbname=gnumed_v21port=5432 user=postgres sslmode=prefer fallback_application_name=GNUmed client_encoding=utf8
application_name=postgres@template.db',closed: 0> 
>>                          type: <class 'psycopg2.extras.DictConnection'>
>>                      identity: 3058616836
>>                   backend PID: 2864
>>              protocol version: 3
>>                      encoding: UTF8
>>       isolation level (psyco): 3 (ISOLATION_LEVEL_SERIALIZABLE)
>>                      readonly: False
>>                    autocommit: True
>>                        closed: 0
>>             connection status: 1 (STATUS_READY)
>>            transaction status: 0 (TRANSACTION_STATUS_IDLE)
>>                    deferrable: None
>>                         async: 0
>>            executing async op: False
>>       2017-07-27 16:03:01  DEBUG     gm.bootstrapper  MainThread (-1219281664)
(./bootstrap_gm_db_system.py::__create_db()#811): setting isolation level to autocommit - should be redundant ? 
>>       2017-07-27 16:03:01  DEBUG     gm.bootstrapper  MainThread (-1219281664)
(./bootstrap_gm_db_system.py::__create_db()#813): conn state now: <connection object at 0xb64eca04; dsn:
'dbname=gnumed_v21port=5432 user=postgres sslmode=prefer fallback_application_name=GNUmed client_encoding=utf8
application_name=postgres@template.db',closed: 0> 
>>                          type: <class 'psycopg2.extras.DictConnection'>
>>                      identity: 3058616836
>>                   backend PID: 2864
>>              protocol version: 3
>>                      encoding: UTF8
>>       isolation level (psyco): 3 (ISOLATION_LEVEL_SERIALIZABLE)
>>                      readonly: False
>>                    autocommit: True
>>                        closed: 0
>>             connection status: 1 (STATUS_READY)
>>            transaction status: 0 (TRANSACTION_STATUS_IDLE)
>>                    deferrable: None
>>                         async: 0
>>            executing async op: False
>>
>>
>> Note that it doesn't actually change the isolation level
>> (which makes sense because autocommit mode is not an
>> isolation level). Should conn.isolation_level show
>> ISOLATION_LEVEL_DEFAULT in this case (meaning "use what the
>> server/db is configured for") ?  It doesn't seem to make a
>> roundtrip to the server to _get_ the default because the
>> database in question defaults to READ_COMMITED. The
>> SERIALIZABLE results from an earlier call to
>> .set_isolation_mode() in my code.
>>
>> (Also note that the connection had already been set to
>>  autocommit by "set_session(autocommit=True)" before.)
>>
>>
>> Thanks for the clarification,
>> Karsten
>> --
>> GPG key ID E4071346 @ eu.pool.sks-keyservers.net
>> E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
>>
>>
>> --
>> Sent via psycopg mailing list (psycopg@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/psycopg
>
> --
> GPG key ID E4071346 @ eu.pool.sks-keyservers.net
> E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
>
>
> --
> Sent via psycopg mailing list (psycopg@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/psycopg


В списке psycopg по дате отправления:

Предыдущее
От: "Karsten Hilbert"
Дата:
Сообщение: Re: [psycopg] psycopg2: distinguishing connect failures throughexception handling
Следующее
От: Karsten Hilbert
Дата:
Сообщение: Re: [psycopg] Changing set_session implementation