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 1iDVyG-0006xh-5W for pgsql-general@arkaria.postgresql.org; Thu, 26 Sep 2019 15:46:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iDVyD-0004Mz-Gh for pgsql-general@arkaria.postgresql.org; Thu, 26 Sep 2019 15:46:17 +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 1iDVyD-0004Mh-1m for pgsql-general@lists.postgresql.org; Thu, 26 Sep 2019 15:46:17 +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 1iDVyA-0002ws-Gn for pgsql-general@postgresql.org; Thu, 26 Sep 2019 15:46:16 +0000 Received: by mail-pf1-x441.google.com with SMTP id 205so2085754pfw.2 for ; Thu, 26 Sep 2019 08:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=NTthjOJ9aeAIKo6M5cO28WGHApjglLUJmWOxcmEzZ3U=; b=gZTvmYdy4cif2K6H7G9NLiwZzXBk1eFIIvsJ6YO8uu5/FPyBZP79He1k/5g77jpRK1 1OdVp3qHhpVQbaIKiIK76hNrNKqxI8ATooStaJzfmTUYVxiRDcSpmwF5uEU5nPRewcIL 5GQPnJPDdtucauRKcNmORP8yAtwAZrpql/Pk75HerA4y8NeYKg2L4GGolrQHEwTYeCvW OHVb3URmi7nEKMUYRmAYVyKn/HHGaBbrxbyh9vkWHM7N5s6NIAP1mVf5jzLmaWbMQ2dl XsgXfBZjYWpdYc6q3D66U4cuvlJG6u6GgSfNNJvXLS/z1l3a6zZKYcYDHaQAOy7/l9kh k83A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=NTthjOJ9aeAIKo6M5cO28WGHApjglLUJmWOxcmEzZ3U=; b=d33DlgkTv4AXCWzVpGhHMMckWLPG/4Vc4XrAI4hrAkhGQc9okgvnm7q/l4r6Bfg4P1 10nZTaqVMsixzolENq/g1ZxoWnVNfXs4ySvzDa908l1rG2XlOc3lfkQzQMya+Glx3fyg M+wkD9GJuVJKOH4FpnXsMOhqoJNUxcObjppg6pP/NGhJSrLsTEtNXyAQXwcungKRa4vV bj3oDaNE7nOmVc44nKAZtwBp286J6YgQlKEWlo5iFr7AQGHsmKY2kkOyrXgDbD+lRCxD ozBiLy9l+50aDQuHBIS2TPfGCOg/s85Jr4G63AwklJzHUqcaOSGN2bSchZfnhrXVITfR 316g== X-Gm-Message-State: APjAAAVJshYZssw0jcbrxMpc/ZivhicgmGykYvyJRmspkILDjP1zZery fjI6qRuNHrDawDOrI6ZJmL152SP/KXQ= X-Google-Smtp-Source: APXvYqyF8VMYeuCMXrq31f0akd4b5NFlGPQUDc9v9MvjmFfMKqkG+lL7Bw/zPz3Bu2IIF6Y2KKk3pg== X-Received: by 2002:a17:90a:310:: with SMTP id 16mr4377363pje.100.1569512772983; Thu, 26 Sep 2019 08:46:12 -0700 (PDT) Received: from [10.104.134.41] ([155.100.47.1]) by smtp.gmail.com with ESMTPSA id g24sm3471732pfi.81.2019.09.26.08.46.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Sep 2019 08:46:12 -0700 (PDT) Subject: Re: managing primary key conflicts while restoring data to table with existing data To: Krishnakant Mane Cc: Adrian Klaver , pgsql-general@postgresql.org 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> From: Rob Sargent Message-ID: <28585755-0eb7-1b46-9966-a9a0d9acc216@gmail.com> Date: Thu, 26 Sep 2019 09:46:11 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <90a6191b-9b45-eb43-c3da-6587d7731a84@riseup.net> Content-Type: multipart/alternative; boundary="------------A18E100D6F5B7A73FC8F43C9" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------A18E100D6F5B7A73FC8F43C9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit >>> -- >>> Regards, >>> Krishnakant Mane, >>> Project Founder and Leader, >>> GNUKhata >>> //(Opensource Accounting, Billing and Inventory Management Software)// >> 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  column and constraint followed by promoting the UUID to >> primary key. This could be safely scripted and applied to all >> instances of your data. >> 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? > > It occurs to me you will also need to "duplicate" the columns in which you have foreign keys.  How many tables are there in the affected schemata and what is the size? Pretty sure you will have to go off-line to perform this sort of transition.  Nearly everything will be touched. > > -- > Regards, > Krishnakant Mane, > Project Founder and Leader, > GNUKhata > //(Opensource Accounting, Billing and Inventory Management Software)// --------------A18E100D6F5B7A73FC8F43C9 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
--
Regards,
Krishnakant Mane,
Project Founder and Leader,
GNUKhata
(Opensource Accounting, Billing and Inventory Management Software)
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  column and constraint followed by promoting the UUID to primary key. This could be safely scripted and applied to all instances of your data. 
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?


It occurs to me you will also need to "duplicate" the columns in which you have foreign keys.  How many tables are there in the affected schemata and what is the size? Pretty sure you will have to go off-line to perform this sort of transition.  Nearly everything will be touched.

--
Regards,
Krishnakant Mane,
Project Founder and Leader,
GNUKhata
(Opensource Accounting, Billing and Inventory Management Software)
--------------A18E100D6F5B7A73FC8F43C9--