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 1iDgaE-0006Mh-9U for pgsql-general@arkaria.postgresql.org; Fri, 27 Sep 2019 03:06:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iDgaD-0007rZ-3Y for pgsql-general@arkaria.postgresql.org; Fri, 27 Sep 2019 03:06:13 +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 1iDgaC-0007rK-LZ for pgsql-general@lists.postgresql.org; Fri, 27 Sep 2019 03:06:12 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iDga9-0000iK-KA for pgsql-general@lists.postgresql.org; Fri, 27 Sep 2019 03:06:11 +0000 Received: by mail-pf1-x441.google.com with SMTP id q5so654424pfg.13 for ; Thu, 26 Sep 2019 20:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:organization:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=upqGyULMXJ5ch5gjUhlA+noziVOdg5S+Qd8LpCu10BI=; b=A/T7WfxLPez4+JE+o3B40XBoz1RdNGWxLRviy55b0XV9TNbXxbHgMZFPykczYkIbFq D369dqTR95Mv83FW/JB3oIfKAZeqFB6xaLMOfGHcaXdbf8RSxtIf7vUics94Lr6Gepux NbEmkaZx2X7dltmLpplf6fg0e84AKUtHr2OBOqEtSuTM4uaAg7GpiTkFBw3NhKKY5imU 93T39S/ilWyI9JImCBUY3s6xpN2+43Iobv9LInN7R/AEgaljWTmQ/CpXRyMER1SC7eOG C8EF/s5T6UG/QyVYH5Jr8AG3ZOPXg7gUjHoLuIesalVpoMXcBnii0y6tFfivVhATauNY Ai1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:organization:references:date :in-reply-to:message-id:user-agent:mime-version :content-transfer-encoding; bh=upqGyULMXJ5ch5gjUhlA+noziVOdg5S+Qd8LpCu10BI=; b=stkrX1/It7WBr9u6T2hMrh+I0Shh8nP90IscdIyQBLS+fXYVaiS47ImeK/slrB3r5b KwrnxYeZC19dvxhN+VgwTUmq0Zvxy/S2l8gYHWtHBvmn6VJly6/m02Rx45XHSIS0i3Y3 23gH0cDxivGjpFXLqdW2S8EF5b8qEBpWwCvAmFnMYkgc8kh1LZkEp6R2nXbFggJFzW3d u8/r1XVdyW0PLoqo3uoC6ws87qGS4QpKSind3u+fiWTK8afVK2C/MIRHEnrPIAFWy2pM KMPgYkKAr9S4ldcZ/XkY5IsaPk92O+AQonj40KBvPKbYvu/yVd/8rhnS3oS8myowbHqO x67g== X-Gm-Message-State: APjAAAUTfIU0JPbtSUR4oqt7Eb5fuFKePQhu0uY7ygCda6TKEPva2ND/ v4wontKOzp7pKhSRwga0JBV12RA= X-Google-Smtp-Source: APXvYqzdIhjf5VOOo2BzQ+eGH/XzRyt+yrqFUv/BV1h9D0AU73zvfOdVj35l/7QldtWrHgjSz6FPHQ== X-Received: by 2002:a17:90a:ad8f:: with SMTP id s15mr7266619pjq.50.1569553567797; Thu, 26 Sep 2019 20:06:07 -0700 (PDT) Received: from Pankajs-MacBook-Pro.local ([49.36.134.118]) by smtp.gmail.com with ESMTPSA id b20sm656106pff.158.2019.09.26.20.06.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Sep 2019 20:06:06 -0700 (PDT) Received: by Pankajs-MacBook-Pro.local (Postfix, from userid 501) id 9047120397DC84; Fri, 27 Sep 2019 08:36:03 +0530 (IST) From: Pankaj Jangid To: pgsql-general@lists.postgresql.org Subject: Re: managing primary key conflicts while restoring data to table with existing data Organization: Code is Great! References: <399629ce-aefe-d0df-7552-99fc6bc3d958@riseup.net> <920a0616-125c-6b6a-fd51-abd250a6ee9c@aklaver.com> <3dcb8017-9126-26ad-dbc8-99ad31b81d0f@riseup.net> <258FDE31-77A2-4E3B-8BD8-9AB9199999AA@gmail.com> <113DEFAE-E197-4966-B97F-C6F1C3471F75@gmail.com> <90a6191b-9b45-eb43-c3da-6587d7731a84@riseup.net> Date: Fri, 27 Sep 2019 08:36:03 +0530 In-Reply-To: <90a6191b-9b45-eb43-c3da-6587d7731a84@riseup.net> (Krishnakant Mane's message of "Thu, 26 Sep 2019 19:14:16 +0530") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Krishnakant Mane writes: >> You might think about adding the new UUID column and use the existing >> primary key to inform the updates in dependent tables. Then remove the >> old PK =C2=A0column and constraint followed by promoting the UUID to >> primary key. This could be safely scripted and applied to all >> instances of your data.=C2=A0 >> That said, this is only truly necessary of you have production >> databases to worry about. > > > Thanks a million, this is the most logical and safe way. > > yes I have a lot of production databases to worry about. > > I am only confused about what you mean by "use the existing primary key > to inform the updates in dependent tables." > > Are you refering to a cascading effect? > > If yes then does it mean I first program my upgrade script to manually > go through all new uuid keys and update the same in the depending tables > with reference to the old primary key working as foreign key in those > tables? I guess that is safest option given that the databases are in production. 1. add UUID UNIQUI column 2. add references to it by identifying ising pkey 3. remove pkey references and the columns 4. make UUID column the pkey 5. remove old pkey column. --=20 Pankaj Jangid