X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 7928030E689 for ; Thu, 12 Jun 2003 16:59:43 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 04802-05 for ; Thu, 12 Jun 2003 13:59:33 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 1BAFE30E92A for ; Thu, 12 Jun 2003 13:59:32 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h5CGxUU6018153; Thu, 12 Jun 2003 12:59:30 -0400 (EDT) To: Jeff Boes Cc: pgsql-admin@postgresql.org Subject: Re: Backends "idle in transaction" In-reply-to: <1055434801.27084.26.camel@takin.private.nexcerpt.com> References: <1055434801.27084.26.camel@takin.private.nexcerpt.com> Comments: In-reply-to Jeff Boes message dated "12 Jun 2003 12:20:01 -0400" Date: Thu, 12 Jun 2003 12:59:30 -0400 Message-ID: <18152.1055437170@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200306/129 X-Sequence-Number: 9120 Jeff Boes writes: > Could I glean some info from the postmaster log? For example, I think I > know that > ReceiveSharedInvalidMessages: cache state reset > has something to do with this "idle in transaction" state. Could the > incidence of these be used as a measurement? Yeah, it could. That particular symptom is relatively harmless though. The real reason staying "idle in transaction" for long periods is evil is that it prevents VACUUM from reclaiming deleted tuples (because they are still live as far as the oldest open transaction is concerned, and VACUUM has no way to know whether that transaction will choose to look at any particular table). So what you should really be looking at is VACUUM VERBOSE output. Here is a simple example (using CVS tip, but I believe 7.3 and 7.2 act the same): regression=# create table foo (f1 serial, f2 int); NOTICE: CREATE TABLE will create implicit sequence 'foo_f1_seq' for SERIAL column 'foo.f1' CREATE TABLE regression=# insert into foo default values; INSERT 154419 1 regression=# insert into foo default values; INSERT 154420 1 regression=# insert into foo default values; INSERT 154421 1 regression=# vacuum verbose foo; INFO: --Relation public.foo-- INFO: Pages 1: Changed 1, Empty 0; Tup 3: Vac 0, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. VACUUM -- That says we have three tuples. Duh. regression=# update foo set f2 = 11; UPDATE 3 regression=# vacuum verbose foo; INFO: --Relation public.foo-- INFO: Removed 3 tuples in 1 pages. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: Pages 1: Changed 1, Empty 0; Tup 3: Vac 3, Keep 0, UnUsed 0. Total CPU 0.00s/0.00u sec elapsed 0.00 sec. VACUUM -- That says we have three live tuples left, and we reclaimed (vacuumed) -- three dead ones, namely the old versions of the updated rows. -- Now in another psql session I do -- begin; -- so that that guy is in "idle in transaction" state. -- Now repeat the experiment: regression=# update foo set f2 = 12; UPDATE 3 regression=# vacuum verbose foo; INFO: --Relation public.foo-- INFO: Pages 1: Changed 1, Empty 0; Tup 6: Vac 0, Keep 3, UnUsed 0. Total CPU 0.01s/0.00u sec elapsed 0.00 sec. VACUUM regression=# -- See the "keep 3"? VACUUM knows those tuples are committed dead, -- but it has to keep them around because my other session can still -- possibly see them. So we've failed to reclaim any space. So the short answer is you should see fewer "kept" tuples and more effective re-use of space in vacuuming, now that you're not holding transactions open. regards, tom lane