Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZEoA-0006Wq-SK for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Dec 2018 12:49:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZEo7-0000kh-Pw for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Dec 2018 12:49:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZEo7-0000kY-GZ for pgsql-bugs@lists.postgresql.org; Tue, 18 Dec 2018 12:49:07 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZEny-0003mo-Re; Tue, 18 Dec 2018 12:49:04 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id wBICmumj018719; Tue, 18 Dec 2018 21:48:56 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 249B5639369; Tue, 18 Dec 2018 21:48:56 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 19479638B52; Tue, 18 Dec 2018 21:48:56 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 126CF40086E; Tue, 18 Dec 2018 21:48:56 +0900 (JST) Message-ID: <5C18ECBB.2000507@lab.ntt.co.jp> Date: Tue, 18 Dec 2018 21:48:59 +0900 From: Etsuro Fujita User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Subject: Re: BUG #15552: Unexpected error in COPY to a foreign table in a transaction References: <15552-c64aa14c5c22f63c@postgresql.org> <8e82d10d-cc16-eed4-7634-3654f59d8053@lab.ntt.co.jp> <30718b48-8020-329a-c6f0-74e1222e5283@lab.ntt.co.jp> In-Reply-To: <30718b48-8020-329a-c6f0-74e1222e5283@lab.ntt.co.jp> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: Amit Langote Cc: Luis Carril , "pgsql-bugs@lists.postgresql.org" , PG Bug reporting form X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Luis and Amit, Thanks for the report, Luis! Thanks for the discussion, Amit! (2018/12/18 12:24), Amit Langote wrote: > On 2018/12/17 22:12, Luis Carril wrote: >>> heap_sync should only be called for relations that actually have files to >>> sync, which isn't true for foreign tables. So, a simple relkind check >>> before calling heap_sync() in CopyFrom would suffice I think. Although, >>> we might also need such a check higher up in CopyFrom where some >>> optimizations that are specific to "heap" relations are enabled. For >>> example, this piece of code: >> >> thanks for the input, so it seems that is enough with adding the check as you suggested: >> >> if (cstate->rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE&& >> cstate->rel->rd_rel->relkind != RELKIND_FOREIGN_TABLE&& >> (cstate->rel->rd_createSubid != InvalidSubTransactionId || >> cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId)) >> { >> hi_options |= HEAP_INSERT_SKIP_FSM; >> if (!XLogIsNeeded()) >> hi_options |= HEAP_INSERT_SKIP_WAL; >> } > > I think that would do the trick. I think so too. FDWs would not look at heap_insert options, so another option would be to 1) leave that options as-is for foreign tables and 2) if the target is a foreign table, just skip heap_sync at the bottom of CopyFrom, or just return without doing anything in heap_sync. Best regards, Etsuro Fujita