Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZoW7-0002nB-L9 for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Apr 2014 21:34:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WZoW7-0001mD-4g for pgsql-hackers@arkaria.postgresql.org; Mon, 14 Apr 2014 21:34:15 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZoW6-0001ls-5J for pgsql-hackers@postgresql.org; Mon, 14 Apr 2014 21:34:14 +0000 Received: from wsip-72-214-29-243.sd.sd.cox.net ([72.214.29.243] helo=joeconway.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZoV0-0001bj-En for pgsql-hackers@postgresql.org; Mon, 14 Apr 2014 21:33:09 +0000 Received: from [192.168.4.41] (account jconway [192.168.4.41] verified) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 13930728 for pgsql-hackers@postgresql.org; Mon, 14 Apr 2014 14:34:10 -0700 Message-ID: <534C540F.4030905@joeconway.com> Date: Mon, 14 Apr 2014 14:33:03 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: "Hackers (PostgreSQL)" Subject: Excessive WAL generation and related performance issue X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.9 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have run into a situation where bulk loading a table with fairly narrow rows and two indexes causes WAL to be generated at about 20:1 or higher ratio to the actual heap data (table plus indexes). There are 560 million loaded rows which ultimately produce a table of about 50 GB and indexes consuming about 75 GB for a grand total of 125 GB table+index heap size. This generates over 3 TB of WAL. The loading progresses fairly fast at first and then drops off sharply so that the load takes 4 plus days on production hardware. Near the end of the load the heap grows very slowly -- measured in tens of MBs per hour. I have reproduced the case on a test machine like so: create table foo ( pid varchar(11) not null, sprid varchar(5) not null, cid varchar(11) not null, csdt date not null, pcind char(1) not null, cedt date, csnum int2 not null default 767, rcd char(2) not null default '99'::bpchar, rrind char(1) not null default 'K'::bpchar, its timestamp not null default now(), luts timestamp not null default now(), primary key (pid,sprid,cid,csdt,rcd) ); create index fooidx on foo(cid,pid); - -- creates 77GB file for test load copy ( select (id % 2604380)::text, (id % 30)::text, (id % 7906790)::text, now() - ((id % 8777)::text || ' days')::interval, (id % 3)::text, now() - ((id % 6351)::text || ' days')::interval, (id % 5)::int2, (id % 27)::text, (id % 2)::text, now() - ((id % 16922)::text || ' seconds')::interval, now() - ((id % 27124)::text || ' seconds')::interval from generate_series(10000000000,10000000000 + 559245675) as g(id) ) to '/home/postgres/foo.dump'; grep -E "^($|#|\s.*#?)" -v $PGDATA/postgresql.conf max_connections = 1200 superuser_reserved_connections = 30 shared_buffers = 12288MB work_mem = 8MB maintenance_work_mem = 128MB wal_level = hot_standbyhot_standby checkpoint_segments = 96 checkpoint_timeout = 10min checkpoint_completion_target = 0.7 archive_mode = on archive_command = 'cp -i %p /home/postgres/archive/%f