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 1hELRK-0005gk-4S for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Apr 2019 22:11:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hELRJ-0003ls-0R for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Apr 2019 22:11:29 +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 1hELRI-0003lf-HI for pgsql-hackers@lists.postgresql.org; Wed, 10 Apr 2019 22:11:28 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hELRF-0006fY-He for pgsql-hackers@lists.postgresql.org; Wed, 10 Apr 2019 22:11:27 +0000 Received: by mail-qt1-x842.google.com with SMTP id k2so4882201qtm.1 for ; Wed, 10 Apr 2019 15:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=peZDPsVCFa7qN3l9jb5CUI2ZJWimHhG3DttLyTVZ+Hg=; b=2ARwEsHK09TYki7P9gI0rCXrgXmmXRxYAoAA6T307/m785bkq6R1bWJauSttXuu4wG VypSWQkX7RPAb9Sk5Mf+Qz6tx1GebhCrHIyYAwwWFYLJ2uwbrrMRMOHGt7QCJM5TSY9O aVkUL0OG7DDOGBe2U0e95AGybRNZGV9sLv7ioAkMtidK5hQs4bfLWl1H1qpya26HL35g RQihPI6cDM/BVaBNKBG/JsJMs2TB4+GHJDQxkxFvm+iks3xC0cFjy5fQswVgEA8A7vFw Fi7LAsQ6px2A1dKvVx+Lyo76M8z8fLbX9L/frkA35CfFRnTB55Bf7bJ47HxzKBRxoEO2 vEwg== 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:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=peZDPsVCFa7qN3l9jb5CUI2ZJWimHhG3DttLyTVZ+Hg=; b=lHQdwjY7VYh6RLoxbeoAKw9kzmju2ztuSKcj8ff/FwpmSztnV3CgF2AMBDDdktCIzR 7/Hq4DkIwwh4MHkoid0zMsJAF9ccyKYSDBnE0RzVOiGfsEdekHA4W0NpempXvb4mYdJe KeYn/wTALLsPKplUaLDZCoCHN02/Qs5CShsah5d00IgRf7MVQF+M7JuM5E2+KClawBeR StkgmNdi9o00s0/3BO3sya2Y9Ju6dGisU9fNSpvhU87ja8r/4+LlrHyw1f0Lf1EcCuph K5fCYdgEJ52SCTeRVmqULSdwV3vFcq/aI1o0rrD1JLy3VQv5O3+T8Z2ele3RQUeICKl3 7pjA== X-Gm-Message-State: APjAAAV4RHdGu8BrJbnFGARydP9ThHGnKjSNSkVZ4DgKaojNE3nnhP8P 2/860ZNAR3Mx7CmEQniI9+6e3Q== X-Google-Smtp-Source: APXvYqyJT1slHyUIxUCqN8cQZZPYw15mo+M2u9QHGF3+3s/Qj/9C7qKYQ/ohlOjfKs5vW5Qv3RS0jA== X-Received: by 2002:ac8:30f9:: with SMTP id w54mr38513922qta.336.1554934284629; Wed, 10 Apr 2019 15:11:24 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id c9sm21374409qkb.86.2019.04.10.15.11.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Apr 2019 15:11:23 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id E46A4120D5C; Wed, 10 Apr 2019 18:11:21 -0400 (-04) Date: Wed, 10 Apr 2019 18:11:21 -0400 From: Alvaro Herrera To: Andres Freund Cc: David Rowley , PostgreSQL Hackers Subject: Re: pg_dump is broken for partition tablespaces Message-ID: <20190410221121.GA23248@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="y0ulUmNC+osPPQO6" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190410202152.GA10240@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --y0ulUmNC+osPPQO6 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Apr-10, Alvaro Herrera wrote: > but the test immediately does this: > > alter table at_partitioned alter column b type numeric using b::numeric; > > and watch what happens! (1663 is pg_default) > > alvherre=# select relname, reltablespace from pg_class where relname like 'at_partitioned%'; > relname | reltablespace > ----------------------+--------------- > at_partitioned | 0 > at_partitioned_a_idx | 0 > at_partitioned_b_idx | 1663 > (3 filas) > > Outrageous! This is because ruleutils.c attaches a TABLESPACE clause when asked to dump an index definition; and tablecmds.c uses ruleutils to deparse the index definition into something that can be replayed via CREATE INDEX commands (or ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY, if that's the case.) This patch (PoC quality) fixes that behavior, but I'm looking to see what else it breaks. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --y0ulUmNC+osPPQO6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="tblsp.patch" diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 83f72470b10..acb6b09a576 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -10567,7 +10567,13 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, tab->changedIndexOids = lappend_oid(tab->changedIndexOids, foundObject.objectId); tab->changedIndexDefs = lappend(tab->changedIndexDefs, - pg_get_indexdef_string(foundObject.objectId)); + /* + * we include a tablespace clause + * only if it's a plain index. + * This likely breaks some stuff. + */ + pg_get_indexdef_string(foundObject.objectId, + relKind == RELKIND_INDEX)); } } else if (relKind == RELKIND_SEQUENCE) diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 0c7a533e697..41144d84a76 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -1142,11 +1142,11 @@ pg_get_indexdef_ext(PG_FUNCTION_ARGS) * Returns a palloc'd C string; no pretty-printing. */ char * -pg_get_indexdef_string(Oid indexrelid) +pg_get_indexdef_string(Oid indexrelid, bool tablespace) { return pg_get_indexdef_worker(indexrelid, 0, NULL, false, false, - true, true, + tablespace, true, 0, false); } @@ -2170,6 +2170,7 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand, pfree(options); } + /* XXX this tablespace works even if it's 0 */ tblspc = get_rel_tablespace(indexId); if (OidIsValid(tblspc)) appendStringInfo(&buf, " USING INDEX TABLESPACE %s", diff --git a/src/include/utils/ruleutils.h b/src/include/utils/ruleutils.h index 7c49e9d0a83..6ff3b841057 100644 --- a/src/include/utils/ruleutils.h +++ b/src/include/utils/ruleutils.h @@ -18,7 +18,7 @@ #include "nodes/pg_list.h" -extern char *pg_get_indexdef_string(Oid indexrelid); +extern char *pg_get_indexdef_string(Oid indexrelid, bool tablespace); extern char *pg_get_indexdef_columns(Oid indexrelid, bool pretty); extern char *pg_get_partkeydef_columns(Oid relid, bool pretty); --y0ulUmNC+osPPQO6--