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 1ghdrg-0006yD-Us for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2019 17:11:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ghdrf-0006dq-GH for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Jan 2019 17:11:31 +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 1ghdrf-0006di-9o for pgsql-bugs@lists.postgresql.org; Thu, 10 Jan 2019 17:11:31 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ghdrc-0006yF-1n for pgsql-bugs@lists.postgresql.org; Thu, 10 Jan 2019 17:11:30 +0000 Received: by mail-qt1-x841.google.com with SMTP id e5so13985596qtr.12 for ; Thu, 10 Jan 2019 09:11:27 -0800 (PST) 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=NFGWSxGAKuXjeSSumVYIuQlGOrpnetFx2zfiKm+a3Ng=; b=L4MxGUGFdLl7CF8Tf3XRuKrQ71WVcMTA/aQCK7pXOKwkyriblClyqa/IuXjYVcZCQg 3km9eQXZXvgJQi9uWzo6/AFTiP6TF71tTlxptWYK2BaFb+YhgqVE6Nm7U9YCOk83lsA1 62Xp3BG7VQgh7nTVXlEzQWc1mYj4oZEVL3hi70AwfmbTZwqbKQ24EKc3UHLmvp3uGXKQ wWcmNnDzH3sKHhCLEUnYiWfzWCwHbxZVkbt8zUxsYpAfcPlM0zptBwyFfYFlWV+t5wCO eVTP7yCWTTBcp+xmF76sVtJZAGxFYiOOZWoDg+cgkJ+JFPklArje2+ifLGDnz02g4hgH xb7Q== 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=NFGWSxGAKuXjeSSumVYIuQlGOrpnetFx2zfiKm+a3Ng=; b=JqRhs8CTQ6JbnLQBcCjtmSGrtNVf7IDehHj9pdvuI3rWg9OXAV1sgGDocfMvSBF0vB oi2uOvrFsAuCe+h0jZkYHVKbPQN5SU9aCDBdcwLriu+pVgueWEuVN/RJsMva4OR0Vqqa wzmluFQ+5kI4OK/0njD+fBVLHB/UGLtA38LQrE2BQ6FmXwyqF/rid5w2sWJiPjvfO7rP OR2ysYS67kwywZ4s6LGGiMLZWBJ+gZIXYcJclUpkxorT5+tTb6FSIzF6Rn1WvoPwP6jX fZqRYUSz26pyZZYfN9uo8nvW50o28xo6jO7zLtjT7pZzobT9Ak9eaiYd+q4PbollTAY4 DRbA== X-Gm-Message-State: AJcUukfP54Pjokyb5FPzdW59xqNDTJ2D65OffbdGpFWWi20jeT3ZCliu VU3gOymUYhRMzpOMeXdIcIuXqKUtKtmYss+7rabrVErdZTumj8fQo8MVl5a9X7rQD2s/0ubF/dZ VuNdu7d8Si3PxRnoHveuOLGkvm5+hJJkqz9lZFEQP+xaKUWW5C8X+ukC7y+hnCxSO28fBMNwwHU KmpfgSGBeUJ45H X-Google-Smtp-Source: ALg8bN6jT7bu0pCe0xbP8Q/67GA6Xe6wS6oShXVXtKHihiMgVGmrWQCvc66mM34qqJd0D5XCnCgysA== X-Received: by 2002:a37:4792:: with SMTP id u140mr10224204qka.301.1547140286079; Thu, 10 Jan 2019 09:11:26 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id a42sm14982862qka.96.2019.01.10.09.11.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 09:11:25 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 70E8D762; Thu, 10 Jan 2019 14:11:23 -0300 (-03) Date: Thu, 10 Jan 2019 14:11:23 -0300 From: Alvaro Herrera To: jesper.pedersen@redhat.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15587: Partitions with ALTER TABLE ADD CONSTRAINT Message-ID: <201901101711.ngskkvwyqgr6@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <15587-562060223190c97a@postgresql.org> User-Agent: NeoMutt/20180716-1013-2c1e88 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Jan-10, PG Bug reporting form wrote: > The following works > > CREATE TABLE t1 (i1 INT NOT NULL, i2 INT NOT NULL) PARTITION BY HASH (i1); > > \o /dev/null > SELECT 'CREATE TABLE t1_p' || x::text || ' PARTITION OF t1 > FOR VALUES WITH (MODULUS 64, REMAINDER ' || x::text || ');' > from generate_series(0,63) x; > \gexec > \o > > ALTER TABLE ONLY t1 ADD CONSTRAINT uniq_t1_i1_i2 UNIQUE (i1, i2); > > which gives > > test=# \d+ t1 > Partitioned table "public.t1" > Column | Type | Collation | Nullable | Default | Storage | Stats target > | Description > --------+---------+-----------+----------+---------+---------+--------------+------------- > i1 | integer | | not null | | plain | > | > i2 | integer | | not null | | plain | > | > Partition key: HASH (i1) > Indexes: > "uniq_t1_i1_i2" UNIQUE CONSTRAINT, btree (i1, i2) INVALID > > > Removing ONLY from the ALTER command makes the index correct. I'm not clear what problem you're reporting. If you use ONLY, then the command doesn't cascade to create the index on partitions, and the index is marked invalid. If you add the constraint to each partition and ALTER INDEX ATTACH PARTITION, the index on t1 should become valid when every partition of the table has its index. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services