X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D751552C86 for ; Thu, 14 Jul 2005 21:28:21 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40748-03 for ; Fri, 15 Jul 2005 00:28:18 +0000 (GMT) Received: from mr2.surnet.cl (smtp2.surnet.cl [216.155.73.163]) by svr1.postgresql.org (Postfix) with ESMTP id F2C1852C82 for ; Thu, 14 Jul 2005 21:28:17 -0300 (ADT) Received: from smtp2.surnet.cl (216.155.73.169) by mr2.surnet.cl (7.0.031.3) id 4259ADFA01596C03; Thu, 14 Jul 2005 20:28:00 -0400 Received: from smtp1.surnet.cl (smtp1.surnet.cl []) by mr2.surnet.cl ([216.155.73.169]); Fri, 15 Jul 2005 00:27:59 +0000 Received: from cluster.surnet.cl (216.155.73.164) by smtp1.surnet.cl (7.0.031.3) id 42587C6E010862FF; Thu, 14 Jul 2005 20:27:39 -0400 Received: from alvh.no-ip.org (200.85.218.66) by cluster.surnet.cl (7.0.043) (authenticated as alvherre@surnet.cl) id 42B3EF60003CD464; Thu, 14 Jul 2005 20:28:16 -0400 Received: by alvh.no-ip.org (Postfix, from userid 1000) id 0D53DC370EE; Thu, 14 Jul 2005 20:28:24 -0400 (CLT) Date: Thu, 14 Jul 2005 20:28:24 -0400 From: Alvaro Herrera To: Alison Winters Cc: pgsql-performance@postgresql.org Subject: Re: lots of updates on small table Message-ID: <20050715002824.GA23728@alvh.no-ip.org> References: <42D5F34E.nail9QE1195IE@pluto.mirrabooka.com> <20050714162114.GA19778@alvh.no-ip.org> <42D6F854.nail3K81VIICH@pluto.mirrabooka.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <42D6F854.nail3K81VIICH@pluto.mirrabooka.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.384 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, FORGED_RCVD_HELO, RCVD_IN_NJABL_PROXY X-Spam-Level: * X-Archive-Number: 200507/199 X-Sequence-Number: 13440 On Fri, Jul 15, 2005 at 09:42:12AM +1000, Alison Winters wrote: > > > Our application requires a number of processes to select and update rows > > > from a very small (<10 rows) Postgres table on a regular and frequent > > > basis. These processes often run for weeks at a time, but over the > > > space of a few days we find that updates start getting painfully slow. > > > We are running a full vacuum/analyze and reindex on the table every day, > > Full vacuum, eh? I wonder if what you really need is very frequent > > non-full vacuum. Say, once in 15 minutes (exact rate depending on dead > > tuple rate.) > > > Is there a difference between vacuum and vacuum full? Yes. Vacuum full is more aggresive in compacting the table. Though it really works the same in the presence of long-running transactions: tuples just can't be removed. > The most recent output was this: > > INFO: --Relation public.plc_fldio-- > INFO: Pages 1221: Changed 3, reaped 256, Empty 0, New 0; Tup 108137: Vac 4176, Keep/VTL 108133/108133, UnUsed 19, MinLen 84, MaxLen 84; Re-using: Free/Avail. Space 445176/371836; EndEmpty/Avail. Pages 0/256. > CPU 0.04s/0.14u sec elapsed 0.18 sec. > INFO: Index plcpage_idx: Pages 315; Tuples 108137: Deleted 4176. > CPU 0.03s/0.04u sec elapsed 0.14 sec. > INFO: Rel plc_fldio: Pages: 1221 --> 1221; Tuple(s) moved: 0. > CPU 0.03s/0.04u sec elapsed 0.36 sec. > INFO: Analyzing public.plc_fldio Hmm, so it seems your hourly vacuum is enough. I think the bloat theory can be trashed. Unless I'm reading this output wrong; I don't remember the details of this vacuum output. > We'll up it to every 15 minutes, but i don't know if that'll help > because even with the current vacuuming the updates are still getting > slower and slower over the course of several days. What really puzzles > me is why restarting the processes fixes it. I wonder if the problem may be plan caching. I didn't pay full attention to the description of your problem, so I don't remember if it could be an issue, but it's something to consider. > Does PostgreSQL keep some kind of backlog of transactions all for one > database connection? No. There could be a problem if you had very long transactions, but apparently this isn't your problem. > Isn't it normal to have processes that keep a single database > connection open for days at a time? I guess it depends on exactly what you do with it. I know of at least one case where an app keeps a connection open for months, without a problem. (It's been running for four or five years, and monthly "uptime" for that particular daemon is not unheard of.) -- Alvaro Herrera () "Everybody understands Mickey Mouse. Few understand Hermann Hesse. Hardly anybody understands Einstein. And nobody understands Emperor Norton."