Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 6DF122E00E2 for ; Mon, 17 Dec 2007 13:54:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 80573-05 for ; Mon, 17 Dec 2007 13:53:45 -0400 (AST) Received: from fmailhost01.isp.att.net (fmailhost01.isp.att.net [204.127.217.101]) by postgresql.org (Postfix) with ESMTP id D316D2E2D7A for ; Mon, 17 Dec 2007 13:53:54 -0400 (AST) Received: from [127.0.0.1] (adsl-153-8-204.gsp.bellsouth.net[70.153.8.204]) by isp.att.net (frfwmhc01) with ESMTP id <20071217175352H0100mlvpge>; Mon, 17 Dec 2007 17:53:52 +0000 X-Originating-IP: [70.153.8.204] Message-ID: <4766B7AC.8080303@reedyriver.com> Date: Mon, 17 Dec 2007 12:53:48 -0500 From: "H. Hall" User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: okparanoid@free.fr CC: pgsql-performance@postgresql.org Subject: Re: update 600000 rows References: <1197677482.47631baa4052a@imp.free.fr> In-Reply-To: <1197677482.47631baa4052a@imp.free.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/259 X-Sequence-Number: 28075 Note: I am resending this because the first never appeared after 40hrs. HH okparanoid@free.fr wrote: > Hello > > i have a python script to update 600000 rows to one table from a csv file in my > postgres database and it takes me 5 hours to do the transaction... > > I'm on debian etch with 8.1 postgres server on a 64 bits quad bi opteron. > > I have desactived all index except the primary key who is not updated since it's > the reference column of the update too. > > When i run this script the server is not used by any other user. > > First when i run htop i see that the memory used is never more than 150 MB. > I don't understand in this case why setting shmall and shmmax kernel's > parameters to 16 GB of memory (the server has 32 GB) increase the rapidity of > the transaction a lot compared to a shmall and shmax in (only) 2 GB ?! > > The script is run with only one transaction and pause by moment to let the time > to postgres to write data to disk. > > If the data were writed at the end of the transaction will be the perfomance > better ? i wan't that in production data regulary writed to disk to prevent > loosinf of data but it there any interest to write temporary data in disk in a > middle of a transaction ??? > > I'm completely noob to postgres and database configuration and help are > welcome. > > thank You will get a huge improvement in time if you use batch updates instead of updating a row at a time. See: http://www.postgresql.org/docs/8.2/interactive/populate.html and http://www.postgresql.org/docs/8.2/interactive/sql-begin.html You will also get a big improvement if you can turn fsync off during the update. See: http://www.postgresql.org/docs/8.2/interactive/runtime-config-wal.html You also need to vacuum the table after doing that many updates since pg does a delete and insert on each update, there will be a lot of holes. Cheers HH