Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmvh3-0003fK-9o for pgsql-general@arkaria.postgresql.org; Tue, 16 Nov 2021 10:28:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mmvh2-0007U3-8r for pgsql-general@arkaria.postgresql.org; Tue, 16 Nov 2021 10:28:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmvh1-0007Tm-UQ for pgsql-general@lists.postgresql.org; Tue, 16 Nov 2021 10:27:59 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mmvgz-0006tC-QP for pgsql-general@lists.postgresql.org; Tue, 16 Nov 2021 10:27:58 +0000 Received: by mail-ed1-x533.google.com with SMTP id e3so49136810edu.4 for ; Tue, 16 Nov 2021 02:27:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tnljunqO9t1iWvTlxJLK2cww3EU8AOE7TJhjIzxR52c=; b=Aeebtx0XxXaIZchPib+ShDxHC37aLRNx/6a0yApnEgTR9bgSlktkl8mFRykvGTyrTP 7B58RpEE1X5+/yrc2aUSteiWN+y+GNkTHoLIKfztE+zkUPNmBHEjuastEs6ieeyJGj0D ahUvlLx0js5q7V6uRC7UJLvTjOBpeZS8E3BTfgBCYgmJeNS/SkYMglfvk9JVkDHpcXiS tcL9yUnmFVrOURUBghzwIt6nuSXJyugrX8SY2nTfbAYANeoB9K4FdiC+lvH+RzUgKeef xh9VEdwslEzG81zTeHZwgdsvDLeO8cHqtz2KEeSP6u/iZP217xhmDYCbpZtNsI6tlMUO fSmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=tnljunqO9t1iWvTlxJLK2cww3EU8AOE7TJhjIzxR52c=; b=kHTVyWcYOGS+gKPKJYFxPnJbBGLwPWz84j/hxK5X+ZbbA28xocximTqO2h19gdO6V/ UhYqLpXVkYkFCdbqSndrfIk7XlsDeCvtCvOU3wA9i0VqvYIaaMUBdsh3TErBNSZYV+ZG F87HoKXe5nr7LhluzF0YqkYFUr6tzoG+VixL4hunlwCbquB0PyjXoR590Z2RdK8ZkMoP 1N4pazMsbHSrkx8vXxar7fQbY819qDTF4YVZO5J8atkfFj2zQ4BgPl8oPH2VsNyQ33tV AcTx2VJP8rw/m6POw33zuFCZHobJ6nrCzYZu7gPaPDtN2z7Ztf1lamarSVgRuI9ebKk1 go/w== X-Gm-Message-State: AOAM531Fp9sVP+l6y/kgcfIWfNZpym3nGJodlD2bOBbHu1qU23cP159M 9xTELGHMJi16UOUquSDxtTg= X-Google-Smtp-Source: ABdhPJyjxz7QJEaqbaSuZnIe/E2Tr10MAtoRTHEu8oJZHRoPogxxDz8XjeNXYmDPTXeirCkvpUPJQQ== X-Received: by 2002:a05:6402:27cd:: with SMTP id c13mr8828213ede.57.1637058475623; Tue, 16 Nov 2021 02:27:55 -0800 (PST) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id kw10sm7748193ejc.71.2021.11.16.02.27.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Nov 2021 02:27:55 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: historical log of data records From: Alban Hertroys In-Reply-To: <6e3e5cea05a44013d2dcbfddab96c3d9ad11238b.camel@cybertec.at> Date: Tue, 16 Nov 2021 11:27:54 +0100 Cc: Sanjay Minni , pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <6e3e5cea05a44013d2dcbfddab96c3d9ad11238b.camel@cybertec.at> To: Laurenz Albe X-Mailer: Apple Mail (2.3608.120.23.2.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 16 Nov 2021, at 10:20, Laurenz Albe = wrote: >=20 > On Tue, 2021-11-16 at 13:56 +0530, Sanjay Minni wrote: >> I need to keep a copy of old data as the rows are changed.=20 >>=20 >> For a general RDBMS I could think of keeping all the data in the same = table with a flag >> to indicate older copies of updated / deleted rows or keep a = parallel table and copy >> these rows into the parallel data under program / trigger control. = Each has its pros and cons.=20 >>=20 >> In Postgres would i have to follow the same methods or are there any = features / packages available ? >=20 > Yes, I would use one of these methods. >=20 > The only feature I can think of that may help is partitioning: if you = have one partition > for the current data and one for the deleted data, then updating the = flag would > automatically move the row between partitions, so you don't need a = trigger. Are you building (something like) a data-vault? If so, keep in mind that = you will have a row for every update, not just a single deleted row. = Enriching the data can be really useful in such cases. For a data-vault at a previous employer, we determined how to treat new = rows by comparing a (md5) hash of the new and old rows, adding the hash = and a validity interval to the stored rows. Historic data went to a = separate table for each respective current table. The current tables =E2=80=9Cinherited=E2=80=9D the PK=E2=80=99s from the = tables on the source systems (this was a data-warehouse DB). Obviously = that same PK can not be applied to the historic tables where there = _will_ be duplicates, although they should be at non-overlapping = validity intervals. Alternatively, since this is time-series data, it would probably be a = good idea to store that in a way optimised for that. TimescaleDB comes = to mind, or arrays as per Pavel=E2=80=99s suggestion at = https://stackoverflow.com/questions/68440130/time-series-data-on-postgresq= l. Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.