X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A69A152A9F for ; Thu, 3 Mar 2005 00:17:08 +0000 (GMT) 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 46470-02 for ; Thu, 3 Mar 2005 00:17:02 +0000 (GMT) Received: from MM01SNLNTO.son.sandia.gov (mm01snlnto.sandia.gov [132.175.109.20]) by svr1.postgresql.org (Postfix) with ESMTP id AC46A52A54 for ; Thu, 3 Mar 2005 00:16:58 +0000 (GMT) Received: from 132.175.109.4 by mm02snlnto.son.sandia.gov with ESMTP ( Tumbleweed MMS SMTP Relay 01 (MMS v5.6.3)); Wed, 02 Mar 2005 17:16:52 -0700 X-Server-Uuid: 914ACFB1-8EBC-470E-882B-54A00EED9786 Received: from ES22SNLNT.srn.sandia.gov (ec03snlnt.sandia.gov [134.253.164.158] (may be forged)) by mailgate2.sandia.gov ( 8.12.11/8.12.11) with ESMTP id j230Gma8016236 for ; Wed, 2 Mar 2005 17:16:51 -0700 (MST) Received: from 134.252.13.164 ([134.252.13.164]) by ES22SNLNT.srn.sandia.gov ([134.253.164.160]) with Microsoft Exchange Server HTTP-DAV ; Thu, 3 Mar 2005 00:16:49 +0000 Received: from boomerang by ES22SNLNT.srn.sandia.gov; 03 Mar 2005 00:15: 21 +0000 Subject: Building a database from a flat file From: "Casey T. Deccio" To: pgsql-sql@postgresql.org Organization: Sandia National Laboratories Date: Wed, 02 Mar 2005 16:15:21 -0800 Message-ID: <1109808921.12430.75.camel@boomerang.ran.sandia.gov> MIME-Version: 1.0 X-Mailer: Evolution 2.0.3 X-PMX-Version: 4.7.0.111621, Antispam-Engine: 2.0.1.0, Antispam-Data: 2005.3.2.16 X-WSS-ID: 6E3888FE1JG1133296-01-01 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.404 tagged_above=0 required=5 tests=AWL, RCVD_NUMERIC_HELO X-Spam-Level: * X-Archive-Number: 200503/32 X-Sequence-Number: 20511 A database I am currently using is built and updated periodically from a flat csv file (The situation is rather unfortunate, but that's all I have right now). The schema I use is more complex than the flat file, so I follow a process to populate the tables with the data from the file. First I slurp the whole file into one temporary table, whose columns correspond to the columns in the file. Then I DELETE all the existing rows from the tables in the schema and perform a series of queries on that table to INSERT and UPDATE rows in the tables that are in the schema. Then I DELETE the data from the temporary table. I do it this way, rather than trying to synchronize it, because of the inconsistencies and redundancies in the flat file. There is more than one problem with this, but the largest is that I would like to perform this whole database rebuild within one transaction, so other processes that need to access the database can do so without noticing the disturbance. However, performing this set of events (besides populating the temporary table) within a single transaction takes a long time--over an hour in some cases. What are some suggestions to help improve performance with replacing one set of data in a schema with another? Casey