Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id C92931EB83EA for ; Thu, 23 Feb 2012 16:57:38 -0400 (AST) Received: from li339-205.members.linode.com ([96.126.114.205] helo=squeakycode.net) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S0fjM-0004Xu-0p for pgsql-performance@postgresql.org; Thu, 23 Feb 2012 20:57:37 +0000 Received: from [192.168.10.84] (97-64-237-59.client.mchsi.com [97.64.237.59]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: andy) by squeakycode.net (Postfix) with ESMTPSA id 41D5917B1F; Thu, 23 Feb 2012 15:57:23 -0500 (EST) Message-ID: <4F46A839.6040605@squeakycode.net> Date: Thu, 23 Feb 2012 14:57:29 -0600 From: Andy Colson User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: Alessandro Gagliardi CC: Steve Crawford , Thom Brown , pgsql-performance@postgresql.org Subject: Re: set autovacuum=off References: <4F4658CB.3030505@squeakycode.net> <4F467EDF.5090708@pinpointresearch.com> <4F468E5B.2070009@squeakycode.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/187 X-Sequence-Number: 46359 On 2/23/2012 2:40 PM, Alessandro Gagliardi wrote: > > checkpoint_segments can help insert speed, what do you have that set to? > > 40. Checking > http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server it looks > like setting that as high as 256 would not necessarily be unreasonable. > What do you think? I'd say go slow. Try a little bit and see if it helps. I don't actually have high insert rate problems, so I don't actually know from experience. > > Also how you insert can make things faster too. (insert vs prepared > vs COPY) > > I'm doing this all with INSERT. Is COPY that much faster? I don't know > anything about prepared. If you can batch multiple records then COPY is the fastest method. (Of course your triggers might be the cause for the slowness and not insert speed). Depending on the language you are using to insert records, you can prepare a query and only send the arguments vs sending the entire sql statement every time. In pseudo-perl code I'd: my $q = $db->prepare('insert into table(col1, vol2) values ($1, $2)'); $q->execute('one', 'two'); $q->execute('three', 'four'); $q->execute('five', 'six'); This is faster because the "insert..." is only sent over the wire and parsed once. Then only the arguments are sent for each execute. Speed wise, I think it'll go: 1) slowest: individual insert statements 2) prepared statements 3) fastest: COPY Again.. assuming the triggers are not the bottleneck. Have you run an insert by hand with 'EXPLAIN ANALYZE'? -Andy > > Have you read up on synchronous_commit? > > Only a tiny bit. A couple people suggested disabling it since my > database is being hosted on AWS so I did that. It seems a bit risky but > perhaps worth it. > I would think they are running on battery backed IO, with boxes on UPS, so I'd guess its pretty safe. It would also depend on your commit size. If you are batching a million records into one commit, you might loose all of them. -Andy