Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f6KZA-0006Jj-GM for pgsql-general@arkaria.postgresql.org; Wed, 11 Apr 2018 18:33:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f6KZ9-00027o-9K for pgsql-general@arkaria.postgresql.org; Wed, 11 Apr 2018 18:33:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f6KZ7-0001py-Ng for pgsql-general@lists.postgresql.org; Wed, 11 Apr 2018 18:33:55 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f6KZ3-0007Gz-4h for pgsql-general@postgresql.org; Wed, 11 Apr 2018 18:33:51 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id DF71320E48; Wed, 11 Apr 2018 14:33:47 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 11 Apr 2018 14:33:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=oGRv6dhdb9dhi16azS1DWIaWgePjU 9HYAHHWsib5iJU=; b=NIqQ1sx4McZ55DF3oLXYJ9jtYxd48sL8h2XE/pgiHR5RR njslMW1YiPEk28cYLk9vq4mmwnTuK6NouwE9Gjc+Vocbjz3cwWpGfQPgASESuVfH lD6X7yq8o2mS40MPDCnGXs8CQb4ce8HR59x1BmRACYatFeQbKl2yxnA5Nz2jvCQO wvmOl1uifjiuV+Y38FVSL5gkcIzgLBKHP1FVJjThLqbtOVsPEa/3sqZbk5ZbAqyu tq8LFsw02I6uelJgPTnhaYGZ2D6sIZMAfakkxRhbFdO3P5x6yBpMIEABw1YLmC3O giFBBVIP7l1vUZyd9XxC8/2Uf6AhqzP0BzobdL1kA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=oGRv6d hdb9dhi16azS1DWIaWgePjU9HYAHHWsib5iJU=; b=l49URK86IvtUCZTESCo4Vs lwulf65c8O2hYBpYyg644d/SV1/1e1HkVKaywFQqcM64xwwJoQVOySIFN9VOrq7j tQIDkcg/Q6j09oWWCG6xBXI0BgA843SraXIcgku0roOTr5jAZ2rf8n0NzpGRYa/q oMxDnJrmap2qASyz3qJZrfU724dsuEpNz+G9OvRKbMmIQUMEr+J6KVGpJ7lC95b9 iAsFMqOEw/A8qmhtvx5Cfpd/sANRLxvabbCaUDALQh/ZB//p4SNtwu4xlauUlgzn 7eRY7vTvtvdW0CiHyG2nl62SSVtjBCLM6Flkdd0wzazhjC63BwyhoeX+Fqv4VWAw == X-ME-Sender: Received: from ranger.suse (74-93-105-186-washington.hfc.comcastbusiness.net [74.93.105.186]) by mail.messagingengine.com (Postfix) with ESMTPA id 5C7D710260; Wed, 11 Apr 2018 14:33:47 -0400 (EDT) Subject: Re: Archiving Data to Another DB? To: Don Seiler Cc: pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: Date: Wed, 11 Apr 2018 11:33:46 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/11/2018 11:13 AM, Don Seiler wrote: > On Wed, Apr 11, 2018 at 12:58 PM, Adrian Klaver > > 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 -- Adrian Klaver adrian.klaver@aklaver.com