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 1ki02e-00074N-Fb for pgsql-general@arkaria.postgresql.org; Wed, 25 Nov 2020 19:01:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ki02d-0004FH-ET for pgsql-general@arkaria.postgresql.org; Wed, 25 Nov 2020 19:01:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ki02d-0004F9-3E for pgsql-general@lists.postgresql.org; Wed, 25 Nov 2020 19:01:23 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ki02a-0007It-N7 for pgsql-general@lists.postgresql.org; Wed, 25 Nov 2020 19:01:22 +0000 Received: by mail-lj1-x22a.google.com with SMTP id y10so3397769ljc.7 for ; Wed, 25 Nov 2020 11:01:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=duneanalytics-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=XbSj/Q4TexUpR5EPTAjbLMmfnvWP41uVPiJ8Pitb6Lw=; b=TQU76aGjSQOVKcp6Af5qAHd2ucG/mF7Rel95KQ9ZUfgG/hzjUmd0AVex3Xyd1qlOGL qSvb3BzcG04cPpZ+zoi7doMvgwY2ROEksvtv65KrEiRg81Cy4+LON1S5K74ppCwDpyCN idSY4Z3Kdi027UqsVpdzmeSDB4a1fFRLBNtAXEHJIRRs+V2tB6u81s5S0kSXShLZbXEk iWoLd1jAjMFLzdprr0Qhy1XGhRlf/t6OeOHFDU9OsImmixSOD0nj67TDZ5KbLXgtzZiF YcrdkEx+NmnjMsApezn2Q9X5wr55E9lU8cWn85bcad0mxLKxMsPhS+mYxMcOqZbTl+yh mTNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=XbSj/Q4TexUpR5EPTAjbLMmfnvWP41uVPiJ8Pitb6Lw=; b=iYe/Xn3wrpTOq+GkowZJ9I/317IA9kctWNODsET2k0SCiJDRl6pRH0bQT7PScW96ub DXfcLyfM3vk3uXfHuh9Qq1yGEwFUpButuI5jA4rO01SQzv/JZ9mzQpWbA4ir3cHfIr85 pdqWGVksV/gD7ThjzC2tP89m8nHME0s5Addux7MpN6Z8Kt4mk656jaFraoXhdf+mfK/s zBEWbDIKNBEBYauF8iyw24Ux2s2dnlJh1Xq1gQY/XjTFzgMdPVky5rAa0Ptal/29jjbt qzWZMFV0z6xj8P7xG3fA+A85N6eVUO/vBj+fujyBRha8N5U8FvdLIAGK8jTSpXMzFTV6 rsqg== X-Gm-Message-State: AOAM533iFURrmQeL7I/RVUjvDA9gkC7G9/k4j4P4npI9wDTfUkXy002p dLPgb3LtpEuoM0I2JrNHpeD2WjXy+4DIqQsFNkU= X-Google-Smtp-Source: ABdhPJxsKauJqPxKFP9pF4CP959sDFNO7DvClesKaM2soW6yv3WcDBKx1ZfvBkZEBYLQcI8fTrlPjw== X-Received: by 2002:a2e:8983:: with SMTP id c3mr1874885lji.184.1606330878884; Wed, 25 Nov 2020 11:01:18 -0800 (PST) Received: from [192.168.1.149] (host-37-191-231-244.lynet.no. [37.191.231.244]) by smtp.gmail.com with ESMTPSA id c19sm19297lfr.182.2020.11.25.11.01.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Nov 2020 11:01:18 -0800 (PST) Subject: Re: postgres_fdw insert extremely slow To: Tom Lane Cc: Adrian Klaver , pgsql-general@lists.postgresql.org, wilhelm@duneanalytics.com References: <3862aa4d-01c7-c76b-4497-ebce1af702cc@aklaver.com> <10df210c-a1bb-f909-9a48-61ac54880df0@duneanalytics.com> <493978.1606323509@sss.pgh.pa.us> <494596.1606324345@sss.pgh.pa.us> From: Mats Julian Olsen Organization: Dune Analytics Message-ID: <56a2c3cf-374d-893b-2feb-964805ff0884@duneanalytics.com> Date: Wed, 25 Nov 2020 20:01:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: <494596.1606324345@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 25.11.2020 18:12, Tom Lane wrote: > Mats Julian Olsen writes: >> On 25.11.2020 17:58, Tom Lane wrote: >>> ... Have you tried looking into pg_locks on the >>> remote server while this query is running? >> Thanks Tom, I'll try to spin up a regular Postgres instance on both rds >> and ec2 and see if that helps. As for the locks, I can not see any >> blocked activity on the remote server while the query runs. > Another place to check is pg_stat_activity, specifically wait_event_type > and wait_event. Thanks Tom, I've now setup the fdw from a local postgres instance and seeing similar timings for the selects and inserts. I've got some more numbers here: x (aurora aws eu-west-1) => y  (gcp gce us-central-1):  ~15 s local (eu) => y: ~15 s local (eu) => test 1 (postgres aws rds eu-west-1): ~4 s local (eu) => test 2 (postgres google cloud sql, us-central-1): ~15s local (eu) => local (eu): < 1s SELECTs in all instances are sub-second. To me this does indicate some sort of networking issue, but I'm wondering if INSERTs are treated differently than SELECTs in postgres_fdw? The only feasibly explanation I have is that postgres_fdw does many more network calls for INSERT than for SELECT, e.g. something like 1 for SELECT and `n` for INSERT? Best, Mats