Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khy7B-0007fD-Kz for pgsql-general@arkaria.postgresql.org; Wed, 25 Nov 2020 16:57:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1khy7A-0006tJ-CF for pgsql-general@arkaria.postgresql.org; Wed, 25 Nov 2020 16:57:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khy7A-0006tC-56 for pgsql-general@lists.postgresql.org; Wed, 25 Nov 2020 16:57:56 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khy77-0008QM-A4 for pgsql-general@lists.postgresql.org; Wed, 25 Nov 2020 16:57:55 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 448222BD; Wed, 25 Nov 2020 11:57:51 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 25 Nov 2020 11:57:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=9 pmkb+FDqENgDx1WtE2HTO7RZq+Vx0YqTlwRmYmetT8=; b=FQ4VlzAbSscXMprz6 /p2RZ/sILxgG58lGmsZ4XdyTZ7MLkXfF1xh7eioCT4ewI321LJ/0v7upedKmsxfC Q/O+4p8J0Afrzo3PSbO3EcO8QqoP4u1xbHlDgVo/X30+k62rtWkN/d20iHOXKMYc TsixrOByTt/qhaPDjnl1dAAKPonOuF0wKNfO6HPCge2yX8FNWa5gwZFrM7lIhatr HQ13pmgfatdkvL4G8xjIRgzZ6ELt/umBgzxlzbVJkuZ8go7xZuWQIZ8Cpv+3JNoG C2/pLbsDECITOt5ouNLgJ55K8NXOxeQfc0TJWXXGTL0bSHiL9NYIGJLvtoOUxRFw 7C5Pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=9pmkb+FDqENgDx1WtE2HTO7RZq+Vx0YqTlwRmYmet T8=; b=Kw7DthzcLt4Dd87gDwZU3X0FtyB33Rf46qlPcwMboIbOqYSS/cEsAP5XE 7VnqXbwEMzZAjnb1ZSYfRcwS2iSMdZ6suvJpOjvYlMUJKcMYxwIs4TyW5/8C5P1L 2zPSnYL8wemWmyudvGdYSoNT0UzyzV58Q7r8OAu2gcKBXvzLP8dKz8/ZBh/uystq fwp/ssMs/ui9F2lzd+AeWcUgLozQE7ZH0Q3icQvOFaNQbnOp4Wops/HJQV6SPgWa MWV+tPtMMVGqJEWhUJIUDK4XcOJqCK847fuwLTIh+wBGDfsRc29qYnnCAumjWJj4 u3irr9B4/W1mkq31Q2EpbUHl2b9mQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudehtddgleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeduieehtdeuveehtdehheevteffheetkeeufeeukeef tdejtdeuhffhfedtheeuudenucffohhmrghinhepghhithhhuhgsrdgtohhmpdguvghpvg hsiidrtghomhenucfkphepjeehrddujedvrdduledrudefleenucevlhhushhtvghrufhi iigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrse grkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.4] (75-172-19-139.tukw.qwest.net [75.172.19.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 1C0263064AA7; Wed, 25 Nov 2020 11:57:50 -0500 (EST) Subject: Re: postgres_fdw insert extremely slow To: Mats Julian Olsen , pgsql-general@lists.postgresql.org References: <3862aa4d-01c7-c76b-4497-ebce1af702cc@aklaver.com> <10df210c-a1bb-f909-9a48-61ac54880df0@duneanalytics.com> From: Adrian Klaver Message-ID: <1e78ec1e-ae8a-4d20-ea22-cc9a965ce98a@aklaver.com> Date: Wed, 25 Nov 2020 08:57:49 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <10df210c-a1bb-f909-9a48-61ac54880df0@duneanalytics.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/25/20 8:48 AM, Mats Julian Olsen wrote: > Apologies for the sloppiness! >> Postgres version(s)? > > x: Aurora PostgreSQL 11.7 on x86_64-pc-linux-gnu, compiled by gcc (GCC) > 4.9.3, 64-bit (RDS) > > y: PostgreSQL 12.2 (Ubuntu 12.2-2.pgdg19.10+1) on x86_64-pc-linux-gnu, > compiled by gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008, 64-bit (GCP) So they are separated by what network distance? > >> >> Without the actual query and EXPLAIN ANALYZE on it this will be >> difficult to answer with any detail. >> >> Also would be nice to have the table schema. >> > > Here's the query, schema and the EXPLAIN ANALYZE FYI, you will get more responses by including below information directly in the email. To that end: On x CREATE TABLE labels ( id integer NOT NULL, address_id bytea NOT NULL, name text NOT NULL, author character varying(50) NOT NULL, type text NOT NULL, source text, updated_at timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT lowercase_name CHECK ((name = lower(name))), CONSTRAINT lowercase_type CHECK ((type = lower(type))), CONSTRAINT whitespace_name CHECK ((regexp_replace(btrim(name, ' '::text), '(\s+)'::text, ' '::text, 'g'::text) = name)), CONSTRAINT whitespace_type CHECK ((regexp_replace(btrim(type, ' '::text), '(\s+)'::text, ' '::text, 'g'::text) = type)) ); CREATE INDEX labels_label ON labels USING BTREE (name); CREATE INDEX labels_label_type ON labels USING BTREE (type); CREATE INDEX labels_address ON labels USING HASH (address_id); CREATE INDEX labels_source ON labels USING BTREE (source); On y CREATE TABLE labels.labels ( address bytea PRIMARY KEY, labels text[] ); > > query: https://gist.github.com/mewwts/704663e19a21bc51864f3298f09a18c0 INSERT INTO foreign.labels (address, labels) SELECT address_id, ARRAY_AGG(name) AS labels FROM labels GROUP BY 1 LIMIT 100; > > plan: https://explain.depesz.com/s/RQFQ Insert on labels (cost=0.42..26.19 rows=100 width=53) (actual time=11541.205..11541.205 rows=0 loops=1) -> Limit (cost=0.42..25.19 rows=100 width=53) (actual time=0.068..3.549 rows=100 loops=1) -> GroupAggregate (cost=0.42..26502.02 rows=106996 width=53) (actual time=0.066..3.449 rows=100 loops=1) Group Key: labels_1.address_id -> Index Only Scan using labels_address_id_type_name_key on labels labels_1 (cost=0.42..24068.85 rows=219145 width=31) (actual time=0.054..0.414 rows=201 loops=1) Heap Fetches: 0 Planning Time: 0.102 ms Execution Time: 12797.143 ms > > > Best, > -- Adrian Klaver adrian.klaver@aklaver.com