Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id BBAE7B5DBC8 for ; Thu, 3 Nov 2011 13:18:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 71873-10 for ; Thu, 3 Nov 2011 16:18:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from elizabeth.gransy.com (ns2.gransy.com [89.187.132.100]) by mail.postgresql.org (Postfix) with ESMTP id 45F3AB5DBC4 for ; Thu, 3 Nov 2011 13:18:01 -0300 (ADT) Received: from sq.gransy.com (localhost [127.0.0.1]) by elizabeth.gransy.com (Postfix) with ESMTP id 9E9F115E4113; Thu, 3 Nov 2011 17:18:00 +0100 (CET) Received: from 85.162.201.188 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Thu, 3 Nov 2011 17:18:00 +0100 Message-ID: In-Reply-To: References: Date: Thu, 3 Nov 2011 17:18:00 +0100 Subject: Re: Optimization required for multiple insertions in PostgreSQL From: "Tomas Vondra" To: "siva palanisamy" Cc: pgsql-performance@postgresql.org, "Siva Palanisamy" User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201111/56 X-Sequence-Number: 45567 On 3 Listopad 2011, 16:52, siva palanisamy wrote: > I basically have 3 tables. One being the core table and the other 2 depend > on the 1st. I have the requirement to add upto 70000 records in the > tables. > I do have constraints (primary & foreign keys, index, unique etc) set for > the tables. I can't go for bulk import (using COPY command) as there is no > standard .csv file in requirement, and the mapping is explicitly required > plus few validations are externally applied in a C based programming file. > Each record details (upto 70000) will be passed from .pgc (an ECPG based C > Programming file) to postgresql file. It takes less time for the 1st few > records and the performance is turning bad to the latter records! The > result is very sad that it takes days to cover upto 20000! What are the > performance measures could I step in into this? Please guide me As Kevin already pointed out, this overall and very vague description is not sufficient. We need to know at least this for starters - version of PostgreSQL - environment (what OS, what hardware - CPU, RAM, drives) - basic PostgreSQL config values (shared buffers, checkpoint segments) - structure of the tables, indexes etc. - output of vmstat/iostat collected when the inserts are slow And BTW the fact that you're not using a standard .csv file does not mean you can't use COPY. You can either transform the file to CSV or create it on the fly. Tomas