Re: Idle in transaction - Mailing list pgsql-general
From | Craig Ringer |
---|---|
Subject | Re: Idle in transaction |
Date | |
Msg-id | 1247856908.9349.227.camel@ayaki Whole thread Raw |
In response to | Re: Idle in transaction ("Sharma, Sid" <ssharma@bjs.com>) |
Responses |
Re: Idle in transaction
|
List | pgsql-general |
On Fri, 2009-07-17 at 12:09 -0400, Sharma, Sid wrote: > I'm sure it is outdated. When I suggested a new application I should > have said a new module within an existing application. In other words, > the db pre-exists. We are rewriting our entire application(s) and moving > our database to DB2 and Oracle starting pretty soon. So postgres is end > of life here and so there is no stomach or interest to upgrade. But you're developing new code targeted to Pg? > > That's bad. It means your client program is starting a transaction > and > > leaving it running without doing anything with it. This is an issue > with > > the way the client is programmed, or with the client drivers, not with > > the server. The server is doing what it's told. > > > > The reason this is bad is that PG can't properly complete maintenance > if > > there are transactions that are left open constantly. Eventually your > > DB will fill up the entire disk with old data that can't be cleaned > up. > > The module/application is read-only and so only does SELECTs. That doesn't matter if any _other_ module is performing UPDATEs (or inserts and deletes) to the tables your module operates on. Your module's open transactions may still prevent PostgreSQL from reclaiming space, because it needs to keep the old versions of tuples around. (I'm struggling, right now, to explain why this is so - if this is so - for READ COMMITTED transactions, though it certainly is for SERIALIZABLE transactions. For READ COMMITTED the transaction's own uncommitted changes can't be discarded vacuumed, but these are presumably read-only transactions anyway - and they don't need to be able to see any old tuples other than any they may have inserted/modified. Will open READ COMMITTED transactions actually impair VACUUM? VACUUM FULL or CLUSTER, sure, but plain VACUUM?) Your uncommitted transactions will also make it very hard to make schema changes such as adding or altering columns to your tables. If your module is the only one active on these tables, and it's only doing read activity, then it doesn't really matter very much that the transactions are left open. It's kind of ugly, though. > So there is no imminent danger then of catastrophic failure such as > memory full or disk full or cpu spikes or db slowness given my > application only does queries? I'm trying to figure out whether I should > chill this weekend on the beach or kiss that good-bye and work this > issue? :-) > I am setting auto-commit to on, so shouldn't a commit be issued once the > select executes (or a rollback on a sql exception)? Yes, it should. Are you certain your app is using autocommit across the board, though, and that something else (say, your connection pooler) isn't "helping" you by turning it back off again? If you turn autocommit back off and issue a rollback before handing the connection back to the connection pooler, does the issue go away? Personally I prefer to explicitly manage transactions anyway. Most Java code/libraries seem to expect autocommit to be off, it makes it easier to guarantee that read-only code is exactly that (by issuing a rollback when finished), and for read/write queries I like to know for certain when data has been committed to the database. -- Craig Ringer
pgsql-general by date: