Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id AF34A2E0131 for ; Sat, 26 Jan 2008 09:39:29 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 63635-10 for ; Sat, 26 Jan 2008 09:39:09 -0400 (AST) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.182]) by postgresql.org (Postfix) with ESMTP id BF5032E0103 for ; Sat, 26 Jan 2008 09:39:25 -0400 (AST) Received: by wa-out-1112.google.com with SMTP id m38so1874186waf.5 for ; Sat, 26 Jan 2008 05:39:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=nc3+Pb8o1CYyUspwYpkmJdeOfqN75loEHF3Q8roBNY0=; b=Ehn+oysqAXqTPr6jy4Vn1PbVvGW3KyQaYciZ41hhXwAwo63Ch0wpEuHezUjfGJO+PLsnQsE3LMcuWyOHpw+GxqujuPvWav6fLsw68G66wWZZ4VfMTghHKp0Pqisjg73H8G7d63yJ/SnPEJGNYAmLlY6OvjY062HjAYyqRiYj9iU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=RBpvN+q6XuCorGBVxGFWA7dfo0BWsv8CEJ86yMbmwVx/gctcNNCUdBM/51ykEbWocTkTWZyLPZDzCUEpNL2un/dZkjMyx7pLOBV3DtyIUOL1pf40/6n94IWreEHg/dRBcyHnMBnfRvIQ2RiI2iDgsH8m4pFykq4Zgt6VWDmyga0= Received: by 10.114.181.1 with SMTP id d1mr3747675waf.10.1201354762851; Sat, 26 Jan 2008 05:39:22 -0800 (PST) Received: by 10.114.133.5 with HTTP; Sat, 26 Jan 2008 05:39:22 -0800 (PST) Message-ID: Date: Sat, 26 Jan 2008 07:39:22 -0600 From: "Scott Marlowe" To: growse Subject: Re: How do I bulk insert to a table without affecting read performance on that table? Cc: pgsql-performance@postgresql.org In-Reply-To: <15107074.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <15099164.post@talk.nabble.com> <15107074.post@talk.nabble.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/244 X-Sequence-Number: 28483 On Jan 26, 2008 5:42 AM, growse wrote: > > > > Scott Marlowe-2 wrote: > > > > On Jan 25, 2008 5:27 PM, growse wrote: > >> > >> Hi, > >> > >> I've got a pg database, and a batch process that generates some metadata > >> to > >> be inserted into one of the tables. Every 15 minutes or so, the batch > >> script > >> re-calculates the meta data (600,000 rows), dumps it to file, and then > >> does > >> a TRUNCATE table followed by a COPY to import that file into the table. > >> > >> The problem is, that whilst this process is happening, other queries > >> against > >> this table time out. I've tried to copy into a temp table before doing an > >> "INSERT INTO table (SELECT * FROM temp)", but the second statement still > >> takes a lot of time and causes a loss of performance. > > > > Can you import to another table then > > > > begin; > > alter table realtable rename to garbage; > > alter table loadtable rename to realtable; > > commit; > > > > ? > > This is a possibility. My question on this is that would an ALTER TABLE real > RENAME TO garbage be faster than a DROP TABLE real? I don't know. They're both pretty fast. I'd do a test, with parallel contention on the table and see.