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 1h9ryj-0005Hc-Cl for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Mar 2019 13:55:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9ryi-00013n-2S for pgsql-bugs@arkaria.postgresql.org; Fri, 29 Mar 2019 13:55:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9ryh-00011V-Qi for pgsql-bugs@lists.postgresql.org; Fri, 29 Mar 2019 13:55:27 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9rye-0008LQ-Me for pgsql-bugs@lists.postgresql.org; Fri, 29 Mar 2019 13:55:27 +0000 Received: by mail-qt1-x843.google.com with SMTP id z16so2634966qtn.4 for ; Fri, 29 Mar 2019 06:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=omWeQt8Qb2OjlDx34D3Oy8cagrhz+MyahiXS5IyGe3s=; b=PVXV/gkGOuZ2bF50qbVreBUEaUPlmrfxpYUGKjW+l7NDKweuG74OyLtMe8KwLilgpc maCWjaCU/tKCvZNPjn7Z6RxRr3leEXypfsEChRawt8Jx/txY+bmSe/Y70q9AdZGwR2ta SAxZpsPk3Ov2Oe6z9ESdxw9CjJW1Zsqi1tJGsYvD+F4dfb5r3/ZecKPsaxlUsR6Z9gEH otMNMxiJ1oU9jQmnLIeVHqo6aGsQm78b8RDp2Fc/NMUDD0oc99hG2eAuEW8cWvualQcX 79ppmkKfVgSYL79bE8xBDY2XTIL5oA1cI+M6/fltOerhzzPsf+EebaWBSRGGNWO4+l89 Zzzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=omWeQt8Qb2OjlDx34D3Oy8cagrhz+MyahiXS5IyGe3s=; b=nVV7CnrXm/eu9r7A0BYxwerRq3sE0l3cdzPoMmlV6h2U/g6AL4I7ZYRsmW8yUwnxhH Jzld3A7MDlPvYiVURWITDF51tXbNC7nbOwfmvLNA4+hUxnWVY0h+HLRc27PlNh9D006Q d5dMpBF4RaX3lMWy4mL1URqL5CCEBBnimDiqUQvqRHVSZihen+3OfyxSNR7kWHfdOcUY 9Oaw8HsdRMHS+N+vVgvyoNlViOlIroOvlwAwpnc3fT4e42u813mevgEJ58lYEqC3bOwV Gu7xabE+bBXIjVTO/+gKgjjvsGRWF/M/EnMiyZiiymlV/9WPynOqKdOSudSNU7LjGdWH ariA== X-Gm-Message-State: APjAAAVaHB6iRnpIA8XtnIbsjdLeMwFYMxy2ROBzJluFOPkpPLoSmYv0 bJUpDMpJ9olfEUKD1paOc9xq66h+lwDHrvmwHHO91oofkPqwBHffzhfcPHhQ3exMhbKFf1F4OoS rQqAm3oyDRThwOR01oAC03sWjEcvP0UDnmiiN3h3VJLlBi47BYXcRWXR+TmM9zBsmhvc87E4dKl Dji2mN0+az8Q== X-Google-Smtp-Source: APXvYqyX6haVvTDTlwtUqSqy710ILI3TbcsTXSiT1F/tMB1rq7S5jW2l85Jz9UUaTg2uyUabcASREg== X-Received: by 2002:ac8:2de7:: with SMTP id q36mr41175012qta.3.1553867722744; Fri, 29 Mar 2019 06:55:22 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id x191sm1072596qka.78.2019.03.29.06.55.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Mar 2019 06:55:22 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 13C5A120A6D; Fri, 29 Mar 2019 10:55:19 -0300 (-03) Date: Fri, 29 Mar 2019 10:55:19 -0300 From: Alvaro Herrera To: stepya@ukr.net, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15724: Can't create foreign table as partition Message-ID: <20190329135519.GA21373@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="CE+1k2dSO48ffgeK" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <15724-d5a58fa9472eef4f@postgresql.org> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Mar-29, PG Bug reporting form wrote: > CREATE FOREIGN TABLE staging.msg_json PARTITION of msg_json > FOR VALUES FROM (20170101) TO (20180101) > SERVER postgres_big_data_arch > OPTIONS (schema_name 'fix_capture', table_name 'msg_json'); > > > I got error !!!! > > SQL Error [42809]: ERROR: cannot create index on foreign table "msg_json" > ERROR: cannot create index on foreign table "msg_json" > ERROR: cannot create index on foreign table "msg_json" Ah, this is because we try to propagate the index to the partition, which appears to be less than desirable. Maybe this patch fixes it? I have not tested it, only verified that it compiles. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --CE+1k2dSO48ffgeK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="partforeign-no-indexes.patch" diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index f8ee4b0a84b..f2da75d9b9c 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -921,6 +921,14 @@ DefineIndex(Oid relationId, int maplen; childrel = heap_open(childRelid, lockmode); + + /* don't try to create indexes on foreign tables, though */ + if (childrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) + { + heap_close(childrel, lockmode); + continue; + } + childidxs = RelationGetIndexList(childrel); attmap = convert_tuples_by_name_map(RelationGetDescr(childrel), diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 23c2e923757..eb34914f5ec 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -14934,6 +14934,10 @@ AttachPartitionEnsureIndexes(Relation rel, Relation attachrel) MemoryContext cxt; MemoryContext oldcxt; + /* don't try to create indexes on foreign tables */ + if (attachrel->rd_rel->relkind == RELKIND_FOREIGN_TABLE) + return; + cxt = AllocSetContextCreate(CurrentMemoryContext, "AttachPartitionEnsureIndexes", ALLOCSET_DEFAULT_SIZES); --CE+1k2dSO48ffgeK--