pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Setting up a server with previous day data
Date: Tue, 23 Aug 2022 19:15:58 -0500
Message-ID: <f44409a6-13f3-61ec-fb5a-df2bf6f65166@gmail.com> (raw)
In-Reply-To: <CAFruNddwg1QHJD75rH_swG_+TVMHiCxLU8pOouxxJH=mz-YUHw@mail.gmail.com>
References: <CAFruNddwg1QHJD75rH_swG_+TVMHiCxLU8pOouxxJH=mz-YUHw@mail.gmail.com>

On 7/19/22 02:22, Srinivasa T N wrote:
> Hi All,
>    I have a primary postgresql 12 server which is being continuously used 
> for transaction processing.  For reporting purposes, I want to set up a 
> secondary server which has got previous day data.  Everyday night, I want 
> the data from primary to be shifted to secondary.  I can achieve this 
> manually using pg_basebackup on primary and pg_restore on secondary.  Is 
> there any other automated efficient way to achieve the same?  Any relevant 
> docs would be helpful.

We populated a "reporting" database from the OLTP database (not PostgreSQL) 
by creating "/X/_log1" and "/X/_log2" tables which had the same columns as 
relevant "main" tables, plus an ACTION_CODE with values 'I", "U" or "D", and 
a datetime field which defaults to CURRENT_TIMESTAMP.

ON INSERT, ON UPDATE and ON DELETE triggers were added to the "main" tables 
which inserted into X_log2 on even days, and into X_log1 on odd days.

Soon after midnight, a cron job dumped "yesterday's" _log table, loaded it 
into the reporting table, and then truncated the _log table.

That was before someone developed a utility to convert the roll-forward logs 
into INSERT, UPDATE and DELETE statements.

Such a utility for PostgreSQL that would convert yesterday's WAL files into 
SQL would /really/ solve your problem.

-- 
Angular momentum makes the world go 'round.

view thread (7+ messages)  latest in thread

Message-ID: <f44409a6-13f3-61ec-fb5a-df2bf6f65166@gmail.com>
Permalink:  ../f44409a6-13f3-61ec-fb5a-df2bf6f65166@gmail.com/
Also on:    postgresql.org/message-id/f44409a6-13f3-61ec-fb5a-df2bf6f65166@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Setting up a server with previous day data
  In-Reply-To: <f44409a6-13f3-61ec-fb5a-df2bf6f65166@gmail.com>
  References: <CAFruNddwg1QHJD75rH_swG_+TVMHiCxLU8pOouxxJH=mz-YUHw@mail.gmail.com> <f44409a6-13f3-61ec-fb5a-df2bf6f65166@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox