Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81622
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.013 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'board.': 0.05; 'explicitly': 0.05; 'postgresql': 0.07; 'happens.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'behave': 0.16; 're-read': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'statement.': 0.16; 'select': 0.22; 'this?': 0.23; 'specifies': 0.24; 'fairly': 0.24; 'holds': 0.26; 'header:X-Complaints-To:1': 0.27; 'statement': 0.30; 'issuing': 0.31; 'anyone': 0.31; 'open': 0.33; 'running': 0.33; 'table': 0.34; 'problem': 0.35; 'connection': 0.35; 'problem.': 0.35; 'transaction': 0.35; 'something': 0.35; 'but': 0.35; 'shows': 0.36; 'application': 0.37; 'list': 0.37; 'being': 0.38; 'server': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'mailing': 0.39; 'received:org': 0.40; 'even': 0.60; 'simple': 0.61; 'further': 0.61; 'back': 0.62; 'between': 0.67; 'close': 0.67; 'frank': 0.68; 'default': 0.69; 'grew': 0.84; 'same,': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | "Frank Millman" <frank@chagford.com> |
| Subject | Db transactions and locking |
| Date | Thu, 27 Nov 2014 12:24:39 +0200 |
| X-Gmane-NNTP-Posting-Host | 197.89.14.52 |
| X-MSMail-Priority | Normal |
| X-Newsreader | Microsoft Outlook Express 6.00.3790.4657 |
| X-RFC2646 | Format=Flowed; Original |
| X-MimeOLE | Produced By Microsoft MimeOLE V6.00.3790.4913 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16363.1417083886.18130.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1417083886 news.xs4all.nl 2945 [2001:888:2000:d::a6]:37502 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:81622 |
Show key headers only | View raw
Hi all I just learned something about database transactions, locking, and DB-API 2.0. I wondered why a PostgreSQL statement was hanging. On investigation, it was waiting to acquire a lock. On further investigation, the lock was held by a simple SELECT statement. This surprised me. I got a clue from a message on the PostgreSQL mailing list - "PostgreSQL by default commits between each statement unless you explicitly start a transaction." All Python database adaptors that I have used start a transaction when you open a cursor. I have just re-read DB-API 2.0, and I cannot see anything that specifies this behaviour, but AFAICT this is what happens. I started to monitor the locks that PostgreSQL holds while I was running my application, and sure enough, the lock table grew and grew, even though I was only issuing SELECTs. I use a connection pool, so I never actually close the connections. If I did I am fairly sure the locks would be released. I changed my application to call conn.commit() every time I return a connection back to the pool, and PostgreSQL shows all the locks being released straight away, so I think this has solved the problem. I don't know if Sql Server and sqlite3 behave the same, but I don't think it can do any harm, so I let it apply across the board. Can anyone see any problem with this? Frank Millman
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Db transactions and locking "Frank Millman" <frank@chagford.com> - 2014-11-27 12:24 +0200
csiph-web