Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtoRx-0005ar-7x for pgsql-performance@arkaria.postgresql.org; Fri, 11 Jan 2013 23:55:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TtoRw-0004V9-JP for pgsql-performance@arkaria.postgresql.org; Fri, 11 Jan 2013 23:55:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtoRu-0004Tq-KB for pgsql-performance@postgresql.org; Fri, 11 Jan 2013 23:55:46 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TtoRp-0006hm-Fx for pgsql-performance@postgresql.org; Fri, 11 Jan 2013 23:55:46 +0000 Received: by mail-wi0-f177.google.com with SMTP id hm2so184450wib.4 for ; Fri, 11 Jan 2013 15:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:content-type:subject:message-id:date:to :mime-version:x-mailer; bh=GGoLg0GKyndzRnwANKdaYp0OSeZDMUzCF3I40s/XTeo=; b=nzqggi4MuxsA0jnKTzHItEY5xkt5ytAjJEJ/7HI4PoYF+svx9/a6ACr4W8FH9sjHYU q6DmKagq3z7C/F7eDaB1Jf+RqV39J3og6fjp2HfNIokFtQB5FavO5Vw8p9Ju0VjYOvim 0/Q+04t/PsF+U8V+VS2jP0b3KaKvqrnG8sDwPy/OVGhz9QpdMhnlUQYzaiFCIVo53DWF SJa9mMTgbvS5PbgDmr2/VJP5Sqgt9cUmqY5SHuFfQZ2c5mCKiAhZSED7XKdt2iVhE+7e TInFAMGM00iDRhZ7PrG3wbTixtPoL232+aMm1K9ltnXu7Yli5ZnvQQN71Xg/ojM7WugS WM6g== X-Received: by 10.194.238.5 with SMTP id vg5mr123463372wjc.40.1357948540504; Fri, 11 Jan 2013 15:55:40 -0800 (PST) Received: from [192.168.1.77] (94.Red-79-150-53.dynamicIP.rima-tde.net. [79.150.53.94]) by mx.google.com with ESMTPS id g2sm1535540wiy.0.2013.01.11.15.55.38 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 15:55:39 -0800 (PST) From: Horst Dehmer Content-Type: multipart/alternative; boundary="Apple-Mail=_4F9BB74F-6C5C-4D43-AC77-79CADAF0D0CA" Subject: Insert performance for large transaction with multiple COPY FROM Message-Id: <78A65A52-C49D-4CA4-9A63-1F5F120BC7E7@gmail.com> Date: Sat, 12 Jan 2013 00:55:36 +0100 To: pgsql-performance@postgresql.org Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) X-Mailer: Apple Mail (2.1499) X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org --Apple-Mail=_4F9BB74F-6C5C-4D43-AC77-79CADAF0D0CA Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi! I see a massive performance drop when writing a large transaction. I'm = writing data for 33 tables with COPY FROM directly from streams in = Scala/Java. Over all tables there are 2.2M records which are unevenly = distributed from 1 record to 315k records in some tables. For comparison I ran a test where I used UNLOGGED tables, no PK/FK = constraints, nor other constraints or indexes and no triggers for all = tables. The insert rate for this scenario is well above 105k = records/second over all tables (which I think is really cool!) Turning everything on (but still with UNLOGGED tables), i.e. PK/FK, = additional indexes, some column check constraints and a trigger for each = table which basically insert one additional record to another table, the = rates dropped expectedly to around 6k to 7k records/second. Except - and that's the wall I'm hitting - for one table which yielded = just 75 records/second. The main 'problem' seem to be the FK constraints. Dropping just them = restored insert performance for this table to 6k records/s. The table in = question has a composite PK (3 columns), 3 foreign keys and a bunch of = indexes (see table obj_item_loc at the end of the mail). Compared to the = other 32 tables nothing unusual. I'd gladly supply more information if necessary. Dropping and recreating constraints/indexes is (for now) no viable = alternative, since I have to write such transaction into an already = populated database. What I'm trying to understand is, which limit it is I'm hitting here. I = need some advice how to 'profile' this situation. Configuration is more or less standard, except WAL settings (which = should not be relevant here). EnterpriseDB One Click installer. Any hint is really appreciated.=20 Thanks! -- Horst Dehmer "PostgreSQL 9.2.1 on x86_64-apple-darwin, compiled by = i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build = 5658) (LLVM build 2336.9.00), 64-bit" OS X 10.8.2 Mid-2012 MacBook Pro 16 GB, 512 GB SSD "bytea_output";"escape" "checkpoint_completion_target";"0.9" "checkpoint_segments";"32" "client_encoding";"UNICODE" "client_min_messages";"notice" "lc_collate";"en_US.UTF-8" "lc_ctype";"en_US.UTF-8" "listen_addresses";"*" "log_checkpoints";"on" "log_destination";"stderr" "log_line_prefix";"%t " "logging_collector";"on" "max_connections";"100" "max_stack_depth";"2MB" "port";"5432" "server_encoding";"UTF8" "shared_buffers";"24MB" "TimeZone";"Europe/Vienna" "wal_buffers";"768kB" /etc/sysctl.conf kern.sysv.shmmax=3D1610612736 kern.sysv.shmall=3D393216 kern.sysv.shmmin=3D1 kern.sysv.shmmni=3D256 kern.sysv.shmseg=3D64 kern.maxprocperuid=3D512 kern.maxproc=3D2048 CREATE TABLE obj_item_loc ( obj_item_id numeric(20,0) NOT NULL, loc_id numeric(20,0) NOT NULL, obj_item_loc_ix numeric(20,0) NOT NULL,=20 ver_acc_dim numeric(12,3),=20 horz_acc_dim numeric(12,3),=20 brng_angle numeric(7,4),=20 brng_acc_angle numeric(7,4),=20 brng_precision_code character varying(6),=20 incl_angle numeric(7,4),=20 incl_acc_angle numeric(7,4),=20 incl_precision_code character varying(6),=20 speed_rate numeric(8,4),=20 speed_acc_rate numeric(8,4),=20 speed_precision_code character varying(6),=20 meaning_code character varying(6),=20 rel_speed_code character varying(6),=20 rptd_id numeric(20,0) NOT NULL, creator_id numeric(20,0) NOT NULL,=20 update_seqnr numeric(15,0) NOT NULL,=20 rec_id bigint DEFAULT nextval('rec_seq'::regclass), CONSTRAINT obj_item_loc_pkey PRIMARY KEY (obj_item_id, loc_id, = obj_item_loc_ix), CONSTRAINT obj_item_loc_4fbc75641175ef1757ca310dd34e34ee_fkey FOREIGN = KEY (obj_item_id) REFERENCES obj_item (obj_item_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT obj_item_loc_7895d64f5557b1e382c36d41212a3696_fkey FOREIGN = KEY (rptd_id) REFERENCES rptd (rptd_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT obj_item_loc_8d919243f69bcc599873caca07ac9888_fkey FOREIGN = KEY (loc_id) REFERENCES loc (loc_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT obj_item_loc_brng_acc_angle_ra_check CHECK = (br_check_305(brng_acc_angle >=3D 0::numeric AND brng_acc_angle <=3D = 359.9999, 'obj_item_loc'::text, 'brng_acc_angle'::text, = brng_acc_angle::text)), CONSTRAINT obj_item_loc_brng_angle_ra_check CHECK = (br_check_305(brng_angle >=3D 0::numeric AND brng_angle <=3D 359.9999, = 'obj_item_loc'::text, 'brng_angle'::text, brng_angle::text)), CONSTRAINT obj_item_loc_brng_precision_code_check CHECK = (br_check_305(brng_precision_code::text =3D ANY (ARRAY['1000MN'::text, = '100MN'::text, '100SEC'::text, '10DEG'::text, '10MN'::text, = '10SEC'::text, 'DEGREE'::text, 'MIL'::text, 'MINUTE'::text, = 'SECOND'::text]), 'obj_item_loc'::text, 'brng_precision_code'::text, = brng_precision_code::text)), CONSTRAINT obj_item_loc_incl_acc_angle_ra_check CHECK = (br_check_305(incl_acc_angle >=3D 0::numeric AND incl_acc_angle <=3D = 359.9999, 'obj_item_loc'::text, 'incl_acc_angle'::text, = incl_acc_angle::text)), CONSTRAINT obj_item_loc_incl_angle_ra_check CHECK = (br_check_305(incl_angle >=3D 0::numeric AND incl_angle <=3D 359.9999, = 'obj_item_loc'::text, 'incl_angle'::text, incl_angle::text)), CONSTRAINT obj_item_loc_incl_precision_code_check CHECK = (br_check_305(incl_precision_code::text =3D ANY (ARRAY['1000MN'::text, = '100MN'::text, '100SEC'::text, '10DEG'::text, '10MN'::text, = '10SEC'::text, 'DEGREE'::text, 'MIL'::text, 'MINUTE'::text, = 'SECOND'::text]), 'obj_item_loc'::text, 'incl_precision_code'::text, = incl_precision_code::text)), CONSTRAINT obj_item_loc_meaning_code_check CHECK = (br_check_305(meaning_code::text =3D ANY (ARRAY['CEOFMA'::text, = 'SHAPE'::text, 'LNBRNG'::text, 'ASSCP'::text, 'COM'::text, = 'CMDDET'::text, 'SOUND'::text, 'DSPCTR'::text, 'FRMCTR'::text, = 'POSOIM'::text, 'CTRMNB'::text, 'ORGPRL'::text, 'STDPOS'::text, = 'ADRPRP'::text]), 'obj_item_loc'::text, 'meaning_code'::text, = meaning_code::text)), CONSTRAINT obj_item_loc_rel_speed_code_check CHECK = (br_check_305(rel_speed_code::text =3D ANY (ARRAY['FAST'::text, = 'MEDIUM'::text, 'ZERO'::text, 'SLOW'::text]), 'obj_item_loc'::text, = 'rel_speed_code'::text, rel_speed_code::text)), CONSTRAINT obj_item_loc_speed_precision_code_check CHECK = (br_check_305(speed_precision_code::text =3D ANY (ARRAY['KPH'::text, = 'KNOTS'::text, 'MPS'::text]), 'obj_item_loc'::text, = 'speed_precision_code'::text, speed_precision_code::text)) ) WITH ( OIDS=3DFALSE, autovacuum_enabled=3Dtrue ); ALTER TABLE obj_item_loc OWNER TO postgres; CREATE INDEX obj_item_loc_ix_rec_id ON obj_item_loc USING btree (rec_id); CREATE INDEX obj_item_loc_loc_id_idx ON obj_item_loc USING btree (loc_id); CREATE INDEX obj_item_loc_obj_item_id_idx ON obj_item_loc USING btree (obj_item_id); CREATE INDEX obj_item_loc_rptd_id_idx ON obj_item_loc USING btree (rptd_id); CREATE TRIGGER trg_01_obj_item_loc_before_insert BEFORE INSERT ON obj_item_loc FOR EACH ROW EXECUTE PROCEDURE obj_item_loc_before_insert(); --Apple-Mail=_4F9BB74F-6C5C-4D43-AC77-79CADAF0D0CA Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Hi!

I see a massive performance drop when writing a = large transaction. I'm writing data for 33 tables with COPY FROM = directly from streams in Scala/Java. Over all tables there are 2.2M = records which are unevenly distributed from 1 record to 315k records in = some tables.

For comparison I ran a test where I used UNLOGGED tables, no = PK/FK constraints, nor other constraints or indexes and no triggers for = all tables. The insert rate for this scenario is well above 105k = records/second over all tables (which I think is really cool!)
Turning = everything on (but still with UNLOGGED tables), i.e. PK/FK, additional = indexes, some column check constraints and a trigger for each table = which basically insert one additional record to another table, the rates = dropped expectedly to around 6k to 7k records/second.
Except - and = that's the wall I'm hitting - for one table which yielded just 75 = records/second.
The = main 'problem' seem to be the FK constraints. Dropping just them = restored insert performance for this table to 6k records/s. The table in = question has a composite PK (3 columns), 3 foreign keys and a bunch of = indexes (see table obj_item_loc at the end of the mail). Compared = to the other 32 tables nothing unusual.
I'd gladly supply more information if = necessary.

Dropping = and recreating constraints/indexes is (for now) no viable alternative, = since I have to write such transaction into an already populated = database.
What I'm = trying to understand is, which limit it is I'm hitting here. I need some = advice how to 'profile' this situation.

Configuration is more or less standard, except = WAL settings (which should not be relevant here).
EnterpriseDB One Click = installer.

Any hint is really appreciated. 

Horst = Dehmer



"PostgreSQL 9.2.1 on x86_64-apple-darwin, compiled by = i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build = 5658) (LLVM build 2336.9.00), 64-bit"
OS X 10.8.2
Mid-2012 MacBook Pro 16 GB, 512 GB SSD
"checkpoint_completion_target";"0.9"
"checkpoint_segments";"32"
"client_min_messages";"notice"
"lc_collate";"en_US.UTF-8"
"lc_ctype";"en_US.UTF-8"
"log_checkpoints";"on"
"log_destination";"stderr"
"log_line_prefix";"%t "
"logging_collector";"on"
"max_stack_depth";"2MB"
"port";"5432"
"server_encoding";"UTF8"
"shared_buffers";"24MB"
"TimeZone";"Europe/Vienna"
"wal_buffers";"768kB"
kern.sysv.shmall=3D393216
kern.sysv.shmmin=3D1
kern.sysv.shmmni=3D256
kern.sysv.shmseg=3D64
kern.maxprocperuid=3D512
kern.maxproc=3D2048

(
  obj_item_id = numeric(20,0) NOT NULL,
  loc_id numeric(20,0) NOT = NULL,
  obj_item_loc_ix numeric(20,0) NOT = NULL, 
  ver_acc_dim = numeric(12,3), 
  horz_acc_dim = numeric(12,3), 
  brng_angle = numeric(7,4), 
  brng_acc_angle = numeric(7,4), 
  brng_precision_code character = varying(6), 
  incl_angle = numeric(7,4), 
  incl_acc_angle = numeric(7,4), 
  incl_precision_code character = varying(6), 
  speed_rate = numeric(8,4), 
  speed_acc_rate = numeric(8,4), 
  speed_precision_code character = varying(6), 
  meaning_code character = varying(6), 
  rel_speed_code character = varying(6), 
  rptd_id numeric(20,0) NOT = NULL,
  creator_id numeric(20,0) NOT NULL, 
  = update_seqnr numeric(15,0) NOT NULL, 
  rec_id = bigint DEFAULT nextval('rec_seq'::regclass),
  = CONSTRAINT obj_item_loc_pkey PRIMARY KEY (obj_item_id, loc_id, = obj_item_loc_ix),
  CONSTRAINT = obj_item_loc_4fbc75641175ef1757ca310dd34e34ee_fkey FOREIGN KEY = (obj_item_id)
      REFERENCES obj_item = (obj_item_id) MATCH SIMPLE
      ON UPDATE NO = ACTION ON DELETE NO ACTION,
  CONSTRAINT = obj_item_loc_7895d64f5557b1e382c36d41212a3696_fkey FOREIGN KEY = (rptd_id)
      REFERENCES rptd = (rptd_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON = DELETE NO ACTION,
  CONSTRAINT = obj_item_loc_8d919243f69bcc599873caca07ac9888_fkey FOREIGN KEY = (loc_id)
      REFERENCES loc (loc_id) = MATCH SIMPLE
      ON UPDATE NO ACTION ON = DELETE NO ACTION,
  CONSTRAINT = obj_item_loc_brng_acc_angle_ra_check CHECK (br_check_305(brng_acc_angle = >=3D 0::numeric AND brng_acc_angle <=3D 359.9999, = 'obj_item_loc'::text, 'brng_acc_angle'::text, = brng_acc_angle::text)),
  CONSTRAINT = obj_item_loc_brng_angle_ra_check CHECK (br_check_305(brng_angle >=3D = 0::numeric AND brng_angle <=3D 359.9999, 'obj_item_loc'::text, = 'brng_angle'::text, brng_angle::text)),
  CONSTRAINT = obj_item_loc_brng_precision_code_check CHECK = (br_check_305(brng_precision_code::text =3D ANY (ARRAY['1000MN'::text, = '100MN'::text, '100SEC'::text, '10DEG'::text, '10MN'::text, = '10SEC'::text, 'DEGREE'::text, 'MIL'::text, 'MINUTE'::text, = 'SECOND'::text]), 'obj_item_loc'::text, 'brng_precision_code'::text, = brng_precision_code::text)),
  CONSTRAINT = obj_item_loc_incl_acc_angle_ra_check CHECK (br_check_305(incl_acc_angle = >=3D 0::numeric AND incl_acc_angle <=3D 359.9999, = 'obj_item_loc'::text, 'incl_acc_angle'::text, = incl_acc_angle::text)),
  CONSTRAINT = obj_item_loc_incl_angle_ra_check CHECK (br_check_305(incl_angle >=3D = 0::numeric AND incl_angle <=3D 359.9999, 'obj_item_loc'::text, = 'incl_angle'::text, incl_angle::text)),
  CONSTRAINT = obj_item_loc_incl_precision_code_check CHECK = (br_check_305(incl_precision_code::text =3D ANY (ARRAY['1000MN'::text, = '100MN'::text, '100SEC'::text, '10DEG'::text, '10MN'::text, = '10SEC'::text, 'DEGREE'::text, 'MIL'::text, 'MINUTE'::text, = 'SECOND'::text]), 'obj_item_loc'::text, 'incl_precision_code'::text, = incl_precision_code::text)),
  CONSTRAINT = obj_item_loc_meaning_code_check CHECK (br_check_305(meaning_code::text =3D= ANY (ARRAY['CEOFMA'::text, 'SHAPE'::text, 'LNBRNG'::text, = 'ASSCP'::text, 'COM'::text, 'CMDDET'::text, 'SOUND'::text, = 'DSPCTR'::text, 'FRMCTR'::text, 'POSOIM'::text, 'CTRMNB'::text, = 'ORGPRL'::text, 'STDPOS'::text, 'ADRPRP'::text]), 'obj_item_loc'::text, = 'meaning_code'::text, meaning_code::text)),
  = CONSTRAINT obj_item_loc_rel_speed_code_check CHECK = (br_check_305(rel_speed_code::text =3D ANY (ARRAY['FAST'::text, = 'MEDIUM'::text, 'ZERO'::text, 'SLOW'::text]), 'obj_item_loc'::text, = 'rel_speed_code'::text, rel_speed_code::text)),
  = CONSTRAINT obj_item_loc_speed_precision_code_check CHECK = (br_check_305(speed_precision_code::text =3D ANY (ARRAY['KPH'::text, = 'KNOTS'::text, 'MPS'::text]), 'obj_item_loc'::text, = 'speed_precision_code'::text, = speed_precision_code::text))
)
WITH (
  = OIDS=3DFALSE,
  = autovacuum_enabled=3Dtrue
);
ALTER TABLE = obj_item_loc
  OWNER TO postgres;
CREATE INDEX obj_item_loc_ix_rec_id
  ON = obj_item_loc
  USING btree
  = (rec_id);

CREATE INDEX = obj_item_loc_loc_id_idx
  ON obj_item_loc
  USING = btree
  (loc_id);

CREATE INDEX = obj_item_loc_obj_item_id_idx
  ON = obj_item_loc
  USING btree
  = (obj_item_id);

CREATE INDEX = obj_item_loc_rptd_id_idx
  ON obj_item_loc
  USING = btree
  (rptd_id);

CREATE TRIGGER = trg_01_obj_item_loc_before_insert
  BEFORE = INSERT
  ON obj_item_loc
  FOR EACH ROW
  EXECUTE = PROCEDURE obj_item_loc_before_insert();

= --Apple-Mail=_4F9BB74F-6C5C-4D43-AC77-79CADAF0D0CA--