On 02/23/2012 10:38 AM, Alessandro Gagliardi wrote:
On Thu, Feb 23, 2012 at 10:01 AM, Steve Crawford <scrawford@xxxxxxxxxxxxxxxxxxxx> wrote:No problem and not stupid. With the manual running to hundreds of pages plus information on wikis and mailing-list histories spanning hundreds of thousands of messages sometimes knowing where to look is 90% of the battle.
You need to rethink things a bit. Databases can fail in all sorts of ways and can slow down during bursts of activity, data dumps, etc. You may need to investigate some form of intermediate buffering. Then you are not running a current version of PostgreSQL so the first step to performance enhancement is to upgrade. (As a general rule - there are occasionally specific cases where performance decreases.) How are you batching them? Into a temp table that is copied to the main table? As a bunch of insert statements within a single connection (saves probably considerable time due to eliminating multiple connection setups)? With one PREPARE and multiple EXECUTE (to save repeated planning time - I'm not sure this will buy you much for simple inserts, though)? With COPY (much faster as many records are inserted in a single statement but if one fails, all fail)? And what is the 50ms limit? Is that an average? Since you are batching, it doesn't sound like you need every statement to complete in 50ms. There is always a tradeoff between overall maximum throughput and maximum allowed latency. Yes, inserts require the indexes to be updated so they can slow down inserts and updates.
That's a huge topic ranging from hardware (CPU speed, RAM, spindle-count, disk-type, battery-backed write caching), OS (you *are* running on some sort of *nix, right?), OS tuning, PG tuning, etc. Fortunately the biggest benefit comes from some basic tuning. I recommend you abandon this thread as it presupposes a now seemingly incorrect cause of the problem and start a new one titled something like "Tuning for high insert rate" where you describe the problem you want to solve. See http://wiki.postgresql.org/wiki/Guide_to_reporting_problems for a good guide to the information that will be helpful in diagnosis. Cheers, Steve |