X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7B7889DC817 for ; Thu, 29 Dec 2005 06:50:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93515-07 for ; Thu, 29 Dec 2005 06:50:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 9FCFE9DC804 for ; Thu, 29 Dec 2005 06:50:46 -0400 (AST) Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766] helo=trofast.sesse.net) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1ErvMt-0004go-KU for pgsql-performance@postgresql.org; Thu, 29 Dec 2005 11:50:47 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1ErvMv-00077b-00 for ; Thu, 29 Dec 2005 11:50:49 +0100 Date: Thu, 29 Dec 2005 11:50:49 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: How import big amounts of data? Message-ID: <20051229105049.GB27287@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <43B3B0EA.6070406@andromeiberica.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <43B3B0EA.6070406@andromeiberica.com> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200512/644 X-Sequence-Number: 16465 On Thu, Dec 29, 2005 at 10:48:26AM +0100, Arnau wrote: > Which is the best way to import data to tables? I have to import > 90000 rows into a column and doing it as inserts takes ages. Would be > faster with copy? is there any other alternative to insert/copy? There are multiple reasons why your INSERT might be slow: - Are you using multiple transactions instead of batching them in all or a few transactions? (Usually, the per-transaction cost is a lot higher than the per-row insertion cost.) - Do you have a foreign key without a matching index in the other table? (In newer versions of PostgreSQL, EXPLAIN ANALYZE can help with this; do a single insert and see where it ends up doing work. Older won't show such things, though.) - Do you have an insertion trigger taking time? (Ditto wrt. EXPLAIN ANALYZE.) COPY will be faster than INSERT regardless, though (for more than a few rows, at least). /* Steinar */ -- Homepage: http://www.sesse.net/