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 1hEbkZ-00026N-HY for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Apr 2019 15:36:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hEbkX-0005iC-Dx for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Apr 2019 15:36:25 +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 1hEbkX-0005i5-52 for pgsql-hackers@lists.postgresql.org; Thu, 11 Apr 2019 15:36:25 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEbkT-0000HZ-9m for pgsql-hackers@lists.postgresql.org; Thu, 11 Apr 2019 15:36:24 +0000 Received: by mail-qt1-x842.google.com with SMTP id d13so7607016qth.5 for ; Thu, 11 Apr 2019 08:36:20 -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=t2odVpGrYXMHgjg5MIGNaLzs2Am9LZwBTGzVxCVH+zc=; b=VRY5GcGmOKsihzQyKW8P9M1LyAjBh/oo5CphYEejEf8n2Y0oOHNtaC1hvYCEuLlMRc 6Gg9Cf9nBnWZ2YjH4Pvrvc4hpTk4OFuSy+HZZK70cJMnjXi2GX+KmZN4jMMvR1epV1Lv 08KSsjcjLGNCdQTRwS7sozmENl5GBXg7fP6RNKzgTcvLnE8/mFE3C4DgdAxhK49rHWZ0 xjPZ5ioDvbWHJRe397s2ADm8/Uwjoc/GVh3FcGAHp+C7X3pdjZ0j2Did5uZoW6rpme4n 62nrUZDXSBC7tRVCAaDRBsGi1ACpL8ThXNp8agBZ55x+ahHvBnzjurTFd9DwZCP4FT54 a0tA== 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=t2odVpGrYXMHgjg5MIGNaLzs2Am9LZwBTGzVxCVH+zc=; b=lpmSoRkRN23Df4Wh6yznoeXCcEPveiQKfz/FL1rKC6X02c4yApqk0aSerSrwJEeGVP iZYAf2t6FECalyuNjaqDmd98WowmUuc3C9/TAQQe50l/sxrWUgIbEiN0x6MqRWnPOldU tJY6BJH38d2tstIjGHPBWjYyMK5E/AXkwS5p2fnb0+z3lwkto7wV5t+8XGqsmfjqiD8R nD8I5vF56KdYYd1hiavpMyq9+oj0RULCTqQCL91o5UEcBOYyxt+RoG+uB8AxWH7h56Mr khZGQFyzSfXvkKZLXqjkwpr35uP6QcoG4xD5zGhmpmJlvUKNwbHri7z5yi1Zp4N0KFFQ cd2A== X-Gm-Message-State: APjAAAX2JgGbRGnm52VdsywQUDQFMz9Zn6YSgrLgCFou96BBmZnYLyuI nRUxcuyHZy1eNi5AT5IEfSAbLtLLKnI= X-Google-Smtp-Source: APXvYqzUZD6p/p4Z3H5CVSAHnBDmJOyIeOv4KeqknTeJdwjmG70PJPGDOGsMPh8EGh0Vc8Gsx8kobw== X-Received: by 2002:ac8:37ce:: with SMTP id e14mr39684283qtc.146.1554996979213; Thu, 11 Apr 2019 08:36:19 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id u57sm27620979qta.12.2019.04.11.08.36.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Apr 2019 08:36:18 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 9AD51120FBF; Thu, 11 Apr 2019 11:36:16 -0400 (-04) Date: Thu, 11 Apr 2019 11:36:16 -0400 From: Alvaro Herrera To: Andres Freund Cc: David Rowley , PostgreSQL Hackers Subject: Re: pg_dump is broken for partition tablespaces Message-ID: <20190411153616.GA7862@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190410221121.GA23248@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 On 2019-Apr-10, Alvaro Herrera wrote: > 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.) Found a "solution" to this -- namely, to set the GUC default_tablespace to the empty string temporarily, and teach ruleutils.c to attach TABLESPACE clauses on index/constraint definitions only if they are not in the database tablespace. That makes everything works correctly. (I did have to patch psql to show tablespace for partitioned indexes.) However, because the tablespace to use for an index is determined at phase 3 execution time (i.e. inside DefineIndex), look what happens in certain weird cases: create tablespace foo location '/tmp/foo'; set default_tablespace to foo; alter table t add unique (b) ; create index on t (a); at this point, the indexes for "a" and "b" is in tablespace foo, which is correct because that's the default tablespace. However, if we do a type change *and add an index in the same command*, then that index ends up in the wrong tablespace (namely the database tablespace instead of default_tablespace): alter table t alter a type bigint, add unique (c); I'm not seeing any good way to fix this; I need the default tablespace reset to only affect the index creations caused by the rewrite, but not the ones used by different commands. I suppose forbidding ADD CONSTRAINT subcommands together with ALTER COLUMN SET DATA TYPE would not fly very far. (I'm not sure that's complete either: if you change datatype so that a toast table is created, perhaps this action will affect the location of said new toast table, also.) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services