Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VO19t-0005IZ-9Q for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2013 08:06:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VO19s-0005fz-PQ for pgsql-bugs@arkaria.postgresql.org; Mon, 23 Sep 2013 08:06:16 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VO19r-0005fs-OZ for pgsql-bugs@postgresql.org; Mon, 23 Sep 2013 08:06:15 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VO19g-00069X-Q3 for pgsql-bugs@postgresql.org; Mon, 23 Sep 2013 08:06:15 +0000 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 9F21B28509; Mon, 23 Sep 2013 01:06:03 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 9C540402B4; Mon, 23 Sep 2013 01:06:03 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 782D7C005B; Mon, 23 Sep 2013 01:06:13 -0700 (PDT) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Mon, 23 Sep 2013 01:06:12 -0700 (PDT) Message-ID: <523FF667.6040202@vmware.com> Date: Mon, 23 Sep 2013 11:05:59 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: jan.mate@inf-it.com CC: pgsql-bugs@postgresql.org Subject: Re: BUG #8465: major dump/reload problem References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -9.2 (---------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 21.09.2013 20:16, jan.mate@inf-it.com wrote: > today I tried to upgrade from 9.2 to 9.3 (pg_upgradecluster 9.2 main) and > the upgrade of one of my databases failed with the following error: "ERROR: > new row for relation ... violates check constraint ...". > > I created an example to reproduce this bug: > > http://www.inf-it.com/fixes/postgres-bugreport2/schema.sql The problem is that when the database is dumped with pg_dump and reloaded, the activity table is loaded first, and codebook table second. The check constraint checks that when a row is inserted into activity table, the corresponding row exists in codebook table, which clearly isn't true if the activity table is loaded first and the codebook table is still empty. The system doesn't know about that dependency since it's all implemented in the PL/pgSQL code. With a constraint like that, you would also get an unrestorable dump if you e.g deleted a row from codebook table after loading the activities. Usually you would implement a schema like that using foreign keys. That would be less code, and the system would automatically get the dump order correct. I would recommend that over a check constraint, if possible. As a work-around, you can drop the constraints from the database before upgrading, and restore them afterwards. The problem isn't really related to upgrade per se, BTW. Running pg_dump + restore even on the same version will give you the same error. - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs