Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B212465012B for ; Wed, 30 Jul 2008 13:49:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 91034-06 for ; Wed, 30 Jul 2008 13:49:31 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from s402.sureserver.com (s402.sureserver.com [216.35.197.71]) by postgresql.org (Postfix) with ESMTP id ED3B8650175 for ; Wed, 30 Jul 2008 13:49:28 -0300 (ADT) Received: (qmail 17445 invoked by uid 504); 30 Jul 2008 16:49:26 -0000 Received: from unknown (HELO ?97.0.177.44?) (mailing?lists@70.102.219.22) by ns1.s402.sureserver.com with ESMTPA; 30 Jul 2008 16:49:26 -0000 Subject: Re: Database size Vs performance degradation From: Mark Roberts To: Matthew Wakeling Cc: pgsql-performance@postgresql.org In-Reply-To: References: <35FABCF85D99464FB00BC5123DC2A70A051D0FB8@s228130hz1ew09.apptix-01.savvis.net> <276541.4189.qm@web25805.mail.ukl.yahoo.com> <35FABCF85D99464FB00BC5123DC2A70A051D11E1@s228130hz1ew09.apptix-01.savvis.net> <48908988.7020204@emolecules.com> Content-Type: text/plain Date: Wed, 30 Jul 2008 09:49:38 -0700 Message-Id: <1217436578.6288.44.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/251 X-Sequence-Number: 30851 On Wed, 2008-07-30 at 17:16 +0100, Matthew Wakeling wrote: > > I believe this SQL snippet could cause data loss, because there is a > period during which writes can be made to the old table that will not > be > copied to the new table. It could indeed cause data loss. > On a side note, I would be interested to know what happens with locks > when > renaming tables. For example, if we were to alter the above SQL, and > add a > "LOCK TABLE old_table IN ACCESS EXCLUSIVE" line, would this fix the > problem? What I mean is, if the application tries to run "INSERT INTO > old_table ...", and blocks on the lock, when the old_table is > dropped, > will it resume trying to insert into the dropped table and fail, or > will > it redirect its attentions to the new table that has been renamed > into > place? Yes, that would resolve the issue. It would also block the application's writes for however long the process takes (this could be unacceptable). > Also, if a lock is taken on a table, and the table is renamed, does > the > lock follow the table, or does it stay attached to the table name? The lock will follow the table itself (rather than the table name). > Anyway, surely it's much safer to just run VACUUM manually? Generally, you would think so. The problem comes from Vacuum blocking the application process' writes. -Mark