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 1iD54J-0002HK-Lu for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 11:02:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iD54H-00014o-Vl for pgsql-general@arkaria.postgresql.org; Wed, 25 Sep 2019 11:02:45 +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 1iD54H-00014h-HX for pgsql-general@lists.postgresql.org; Wed, 25 Sep 2019 11:02:45 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iD54B-0000gF-8u for pgsql-general@postgresql.org; Wed, 25 Sep 2019 11:02:44 +0000 Received: by mail-io1-xd41.google.com with SMTP id q10so12694878iop.2 for ; Wed, 25 Sep 2019 04:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=1kapz4+9rDOkvdiNLCTALLs7N+rbyeEFgwKVOo9OVXc=; b=aQX2QJNZcEFjN2YXUhLXvu9CvvMjwQbGOp+E0gz2hm5UDRTNhD0EhurNLTPl5KDwgt nqfP/fphLWA3c0c8RzRSKFk5WheSLAanwLFR6+D55CZcEqtQRFYatUJ6+m6/OzjE6XfL dqlBP+B8TeSn9WGW+yR8K6cO4JsMSJbJ6JyUbjnV2GKCFdlIdMgNvn0KhOnaZXPsINcv Dcwav5qdZ6UJT+NaXrRvh4wanWCFR55FieGtLtp7DGim15a7sw8Pye7jvekHpS5RraJE MPOzswSyr953UaZfNnBTVkHd/AqxTBimbG3eXMinqyaIVzr9l4PR8i1ew9yi2HcQt+/Q Twhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=1kapz4+9rDOkvdiNLCTALLs7N+rbyeEFgwKVOo9OVXc=; b=sDI8dMfGMqucbBfEix1Gs86kJWrOvI3aqaTPlELFnRPuFhAuO2RSeDTh/pGgIf4zXE Xla8aC8VqqUu+QQdGFvHm+P0VxFPeINdr2Wlb+WojUNVZNhVRAVFmX5iQyVCPU5r3ptZ UQnrOuEL0VCgZrP7WkPLSXoGamYTVSdSrTm3bZXpIRE2Y5C3QkyHSpmdjkDZ7WDTxSxG 4N02tTw0pocBdmP88B158jIlBrDTNOElEugspLfdUKbEFPMbh/yQOsW+kErxpGJmj3et CYVlIczZ5HHSWnarwalwugVRKwd3c/VUoRD1BGFzfTvA+MXu7QzQJU31+GihZbF2DfOS 3MFg== X-Gm-Message-State: APjAAAXuciUgiO7IeusugtWf0v8jeTH6y5As+FranpYwH/itLE1gxdCo 0t5BXk2XbTyfZpZFu7U2ivbhT5PoU0g= X-Google-Smtp-Source: APXvYqzEnu2VEE+ovDlIO0wEmYobYnh/qsd0nZQLAVKhRBEB2jREs+2RUeylqgdtHQ7wJpSaM4vzkw== X-Received: by 2002:a05:6602:10d:: with SMTP id s13mr9079806iot.244.1569409358321; Wed, 25 Sep 2019 04:02:38 -0700 (PDT) Received: from [10.0.0.10] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id u11sm7138168iof.22.2019.09.25.04.02.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Sep 2019 04:02:37 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-30863E42-A64B-44C9-A54E-C9CF1498AD18 Mime-Version: 1.0 (1.0) Subject: Re: managing primary key conflicts while restoring data to table with existing data From: Rob Sargent X-Mailer: iPhone Mail (16G102) In-Reply-To: <399629ce-aefe-d0df-7552-99fc6bc3d958@riseup.net> Date: Wed, 25 Sep 2019 05:02:35 -0600 Cc: pgsql-general@postgresql.org Content-Transfer-Encoding: 7bit Message-Id: References: <399629ce-aefe-d0df-7552-99fc6bc3d958@riseup.net> To: Krishnakant Mane List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail-30863E42-A64B-44C9-A54E-C9CF1498AD18 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > On Sep 25, 2019, at 1:15 AM, Krishnakant Mane wrote: >=20 > Hello all, >=20 > I have been using postgresql for an enterprise quality account's automatio= n and inventory management software called GNUKhata >=20 > Our team is planning to add backup and restore function in the software. >=20 > But we don't want to dump the entire database and then restore the same. >=20 > What we are trying to do is to copy data specific to an organization. >=20 > The challenge here is that I might copy all data (account heads, bills, vo= uchers etc ) for one organization from an instance on one machine. >=20 > I take the archive in what ever format to another machine and now attempt t= o restore. >=20 > The risk here is for example if the primary key value for orgcode in the o= rganization table is 5, it might conflict with the data where I am attemptin= g it to be restored. >=20 > Same holds true for bills, invoices etc. >=20 > A certain account head with accountcode 1 might be already present on the s= econd machine. >=20 > I am not expecting the users to empty all data from the destination machin= e before restoring a backup. >=20 > The reason is that an auditor may have many client's data and one can't pr= edict what primary key values are going to come from a backup. >=20 > Basically I can even say this is a copy paste instead of a pure backup and= restore. >=20 > Can any one suggest how to handle such conflicts? >=20 >=20 >=20 > --=20 > Regards,=20 > Krishnakant Mane, > Project Founder and Leader, > GNUKhata > (Opensource Accounting, Billing and Inventory Management Software) I=E2=80=99m not sure I like your definition of =E2=80=98backup and restore=E2= =80=99 but you might get away with your approach if your keys were UUIDs. Bu= t I=E2=80=99ll bet dollars to doughnuts you=E2=80=99re using serial keys. Th= ose seem to appeal to accounting types.=20= --Apple-Mail-30863E42-A64B-44C9-A54E-C9CF1498AD18 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

On Sep 25, 2019, at 1:15 AM, Krishnakant Mane &l= t;kkmane@riseup.net> wrote:
<= br>
=20 =20 =20

Hello all,

I have been using postgresql for an enterprise quality account's automation and inventory management software called GNUKhata <ht= tps://gnukhata.in>

Our team is planning to add backup and restore function in the software.

But we don't want to dump the entire database and then restore the same.

What we are trying to do is to copy data specific to an organization.

The challenge here is that I might copy all data (account heads, bills, vouchers etc ) for one organization from an instance on one machine.

I take the archive in what ever format to another machine and now attempt to restore.

The risk here is for example if the primary key value for orgcode in the organization table is 5, it might conflict with the data where I am attempting it to be restored.

Same holds true for bills, invoices etc.

A certain account head with accountcode 1 might be already present on the second machine.

I am not expecting the users to empty all data from the destination machine before restoring a backup.

The reason is that an auditor may have many client's data and one can't predict what primary key values are going to come from a backup.

Basically I can even say this is a copy paste instead of a pure backup and restore.

Can any one suggest how to handle such conflicts?


--
Regards,
Krishnakant Mane,
Project Founder and Leader,
GNUKhata<= br> (Opensource Accounting, Billing and Inventory Management Software)
=20
I=E2=80=99m not sure I like your definition of =E2=80=98b= ackup and restore=E2=80=99 but you might get away with your approach if your= keys were UUIDs. But I=E2=80=99ll bet dollars to doughnuts you=E2=80=99re u= sing serial keys. Those seem to appeal to accounting types. = --Apple-Mail-30863E42-A64B-44C9-A54E-C9CF1498AD18--