pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Don Seiler <don@seiler.us>
Cc: pgsql-general@postgresql.org
Subject: Re: Archiving Data to Another DB?
Date: Wed, 11 Apr 2018 11:33:46 -0700
Message-ID: <ae18f69c-8ae3-79e3-517a-719bd7700643@aklaver.com> (raw)
In-Reply-To: <CAHJZqBDJ7M_sJAOAKAp7JarSfxfTtOjqjgWta5Nhu4tgqwqjHw@mail.gmail.com>
References: <CAHJZqBAnK+fNpWM55yHXOVqZxPwzq0Gkgv8yPEDAy6KSuhQkBQ@mail.gmail.com>
	<ed6050c8-bd18-87c9-9522-ea1f2c07a5c8@aklaver.com>
	<CAHJZqBDJ7M_sJAOAKAp7JarSfxfTtOjqjgWta5Nhu4tgqwqjHw@mail.gmail.com>

On 04/11/2018 11:13 AM, Don Seiler wrote:
> On Wed, Apr 11, 2018 at 12:58 PM, Adrian Klaver 
> <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     "F.33.3. Transaction Management
> 
>     During a query that references any remote tables on a foreign
>     server, postgres_fdw opens a transaction on the remote server if one
>     is not already open corresponding to the current local transaction.
>     The remote transaction is committed or aborted when the local
>     transaction commits or aborts. Savepoints are similarly managed by
>     creating corresponding remote savepoints.
> 
>     ..."
> 
> 
> Interesting, I'll work on a test case later!
> 
>     I may be missing something, but why not reverse your original set up?
>     Assuming transactional behavior works as expected something like:
> 
>     1) Setup postgres_fdw in main database.
> 
>     2) Create FOREIGN TABLE pointing to table in archive database.
> 
>     3) INSERT INTO/SELECT from main table to archive table.
> 
>     4) DELETE FROM main table.
> 
> 
> I had considered this as well, as this would allow me to rollback the 
> delete (assuming my intel on postgres_fdw transactions was correct, 
> which it may not be after all). I wondered if a remote insert woultd be 
> broken up into individual inserts like the remote delete was, as that 
> would be equally unappealing for the same reasons. But obviously worth 
> confirming.

A test case here confirms it sends individual INSERTS:

test_(postgres)# insert into fdw_test_table select * from fdw_test;
INSERT 0 3

Where fdw_test_table is the remote table and fdw_test is the local one.

postgres-2018-04-11 11:29:23.812 PDT-0LOG:  statement: insert into 
fdw_test_table select * from fdw_test;
postgres-2018-04-11 11:29:23.812 PDT-0LOG:  execute pgsql_fdw_prep_2: 
INSERT INTO public.fdw_test_rcv(id, fld_1, fld_2) VALUES ($1, $2, $3)
postgres-2018-04-11 11:29:23.812 PDT-0DETAIL:  parameters: $1 = '1', $2 
= 'one', $3 = 't'
postgres-2018-04-11 11:29:23.813 PDT-10140LOG:  execute 
pgsql_fdw_prep_2: INSERT INTO public.fdw_test_rcv(id, fld_1, fld_2) 
VALUES ($1, $2, $3)
postgres-2018-04-11 11:29:23.813 PDT-10140DETAIL:  parameters: $1 = '2', 
$2 = 'two', $3 = 'f'
postgres-2018-04-11 11:29:23.813 PDT-10140LOG:  execute 
pgsql_fdw_prep_2: INSERT INTO public.fdw_test_rcv(id, fld_1, fld_2) 
VALUES ($1, $2, $3)
postgres-2018-04-11 11:29:23.813 PDT-10140DETAIL:  parameters: $1 = '3', 
$2 = 'three', $3 = 'f'

So much for that idea(:

> 
> Don.
> 
> -- 
> Don Seiler
> www.seiler.us <http://www.seiler.us;


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (12+ messages)  latest in thread

Message-ID: <ae18f69c-8ae3-79e3-517a-719bd7700643@aklaver.com>
Permalink:  ../ae18f69c-8ae3-79e3-517a-719bd7700643@aklaver.com/
Also on:    postgresql.org/message-id/ae18f69c-8ae3-79e3-517a-719bd7700643@aklaver.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: adrian.klaver@aklaver.com, don@seiler.us
  Subject: Re: Archiving Data to Another DB?
  In-Reply-To: <ae18f69c-8ae3-79e3-517a-719bd7700643@aklaver.com>
  References: <CAHJZqBAnK+fNpWM55yHXOVqZxPwzq0Gkgv8yPEDAy6KSuhQkBQ@mail.gmail.com> <ed6050c8-bd18-87c9-9522-ea1f2c07a5c8@aklaver.com> <CAHJZqBDJ7M_sJAOAKAp7JarSfxfTtOjqjgWta5Nhu4tgqwqjHw@mail.gmail.com> <ae18f69c-8ae3-79e3-517a-719bd7700643@aklaver.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