Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 4FC649FB54A for ; Thu, 26 Jul 2007 13:42:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 09015-06 for ; Thu, 26 Jul 2007 13:42:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id A21B09FB520 for ; Thu, 26 Jul 2007 13:42:24 -0300 (ADT) Received: MIR3-FS.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes by MIR3-FS.mir3.com; 26 Jul 2007 09:42:22 -0700 Subject: Re: how to handle very large data object efficiently From: Mark Lewis To: Xiaoyu Cc: pgsql-jdbc@postgresql.org In-Reply-To: <1185465272.247919.148280@k79g2000hse.googlegroups.com> References: <1185465272.247919.148280@k79g2000hse.googlegroups.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Thu, 26 Jul 2007 09:42:22 -0700 Message-Id: <1185468142.19184.48.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/122 X-Sequence-Number: 17296 On Thu, 2007-07-26 at 15:54 +0000, Xiaoyu wrote: > Hi, folks: > I am a new programmer to JDBC, if the question is naive, please > forgive me. > question description: > 1. store the data in a text file into database, the format of the text > file is similar to: > ...... > 218596813 235940555 4387359 3 386658 4000 4 4 > 218597197 235940333 4366832 17 388842 5000 5 5 > 218597485 235940805 4374620 8 386226 4000 4 4 > ...... > each record of the database corresponding to each line of the file, > and each element corresponding to each number. > > 2. the file is very huge, normally there are 9,000,000 lines in each > file. My current program read the file line by line and parse the line > and store the elements into the database. However, because the file is > huge, it may take days to store one file, and there are 50 similar > files need to be processed. > > 3. Can anyone give a better solution to take place "read line by > line"? Is there any method like manipulate block of data(equal several > lines) in JDBC? Many thanks Basic FAQ for large data imports: 0. Make sure Postgres is set up correctly, including a sane vacuuming policy. Depending on your workload you may want to play with the checkpoint settings, work_mem settings, auto-vacuum, etc. 1. Use a recent version of Postgres (8.2.4 preferably). 2. Use a few big transactions instead of many small transactions. In JDBC this means setAutoCommit(false). 3. If possible, do the import first and add any relevant constraints/indexes later. 4. Use the COPY method. This isn't supported in the official driver yet, but look through the mailing list archives and you'll find the patch to enable it. 5. Depending on your server hardware, it can be a big win to split the import across multiple threads. Try and see. If you do all of the above and have a relatively recent database server, you should be able to import simple data like above at at least several thousands of rows per second. If it takes more than 30 minutes to import one of your 9M row files, then you're doing something wrong. -- Mark Lewis