[Zope-DB] Working with ZPsycopgDA (or any DA) - commiting

Andreas Jung lists at zopyx.com
Fri Aug 11 11:17:08 EDT 2006



--On 11. August 2006 16:56:59 +0000 krokodylek at tenbit.pl wrote:

>
> Hi :-)
>
> I'm working with a Postgresql database which I have to insert a lot of
> data to... I'm using the ZPsycopgDA database adapter, and ZSQL methods.
>
> I have noticed that though I am calling the zsql method no data gets
> really commited to the database. It all gets entered to database at the
> very end.

The DA is usually tied to the transaction system of Zope. So this behaviour 
is totally perfect and usually highly desirable.

> This behavior seems reasonable for keeping database consistent, but in my
> situation it is really not so good - I have couple houndreds megabytes of
> data and as I believe it all gets stored in memory

ZSQL methods are executed at the time they are called and immediately 
executed on the server. THat does not mean that the every ZSQL method 
causes
an automatic commit after execution (see above).

>before being sent to
> the database causing serious system lags.

You might google for "postgres autocommit mode".

> I could be wrong though - this
> is only my observation... What could be another reason for slooow inserts?

What means slow inserts? Depending on the isolation level, changes are 
visible to other apps only after a commit..that's how databases usually 
work.
>
> Either way, it would be far better for me if every "INSERT" would be
> commited immediatelly or better yet if I could force a "commit" within my
> code. Is there some way I can do it?
>

See above. You can configure autocommit mode either on the server side or 
on the client side with psycopg (check the autocommit() method of the 
connection object as returned through psycopg.connect()). You might extend 
the ZPsycopgDA sources in order to create a DB connection either with or 
without autocommit mode.

-aj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-db/attachments/20060811/f8bd8ee1/attachment.bin


More information about the Zope-DB mailing list