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 1f6JgL-0003Kf-DP for pgsql-general@arkaria.postgresql.org; Wed, 11 Apr 2018 17:37:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f6JgK-0005e2-9b for pgsql-general@arkaria.postgresql.org; Wed, 11 Apr 2018 17:37:16 +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 1f6JgJ-0005dt-S6 for pgsql-general@lists.postgresql.org; Wed, 11 Apr 2018 17:37:16 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f6JgG-0005sA-Gx for pgsql-general@lists.postgresql.org; Wed, 11 Apr 2018 17:37:14 +0000 Received: by mail-pf0-x242.google.com with SMTP id h69so1257362pfe.13 for ; Wed, 11 Apr 2018 10:37:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=e/UjoEAGp0kouollJUb6SzfY6XyI2PwRQvPcJlF26c0=; b=vDvR07HPuFwJBV6UIZsD56HxEL5ImCXCsRHMBTV3s+53jQi1PeOTGHWcJKyFVyoPdl dwwzpiGNTodt+5Ps7D/QG9FNjIw9bHxlbBGvZyQfdNQL/XINw82kF4tY0uyzdBf9HWJl 9AwmbSRqojpfdldJm67RxGD0jscZLXQW+K0npV9LhxtfQo+vhGLatCpo9gG0U0qDbVzQ mKZ/E6gfkOEh2GdnxEqFZp2zIdAmulOn3BwjE1DVdGixK6L5+O3cWlt6tbFhW4rKrLv1 brnPY+CNSx4ObTbnu6yRlFE/5gPSJLanbRFpNYPoozzb5owulZIUjafiKA4Vq/fD+csx zbEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=e/UjoEAGp0kouollJUb6SzfY6XyI2PwRQvPcJlF26c0=; b=HpDJoHFUb/Qf/YorjLFyzT8pVVC1qFySpZcHkPYo/EWQbKx76e5nkg8gW1uZNN+lmF IrVCyAK+kqkYRmVVfRsOGsQYznWTrfnaOqX+KKq8IME5uKudABFPGuYF+f557Jl7ilGH 4JS6LrEY+RGZqe0UTCekUy+RqIa/ZZUK+pyTDUIHM+kbdJWkkSersgazeSHFYvylYHR8 DvYPH5qDUTWErBs9sDNZ+rn3KTxRdU4xaH0+GDT6Fc4XYsjGbCNKX+qLCkLj4Ap23buw w0Wfrxqo0PlOGhNPwOWzNaUv+jIrg1SQy4lWmPAZxiHTdgcvOxg0ZqsTlxiF01m3Q+VV rS9w== X-Gm-Message-State: ALQs6tClGvXlCWja8tZicnkUwpqebQiJXwUpYS6aP4DZDTGyhJVnsww+ ENOISSRxwL7mKsRKGmDYbL57FOGO X-Google-Smtp-Source: AIpwx49KbYOAA+Ij0YFBzln1E6QTnk/rinVizhjl2UCeODkwAXrltuoirDdK7jNATCSe3b0MuesV9w== X-Received: by 10.98.133.212 with SMTP id m81mr4831776pfk.61.1523468230238; Wed, 11 Apr 2018 10:37:10 -0700 (PDT) Received: from [10.104.134.14] ([155.100.47.6]) by smtp.gmail.com with ESMTPSA id a5sm5696592pfl.159.2018.04.11.10.37.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Apr 2018 10:37:09 -0700 (PDT) Subject: Re: Archiving Data to Another DB? To: pgsql-general@lists.postgresql.org References: From: Rob Sargent Message-ID: <0581fbc0-f85e-5a46-3b04-98eda54bd481@gmail.com> Date: Wed, 11 Apr 2018 11:37:08 -0600 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-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/11/2018 10:24 AM, Ron wrote: > > > On 04/11/2018 11:15 AM, Don Seiler wrote: >> Let's say I have two DBs: main (9.6.6) and archive (10.2). >> >> I have a table in main where I want to archive data older then 60 >> days. For various reasons, the table is not partitioned, so for now >> we must use DELETE. The destination table in the archive DB is >> partitioned with the new Pg10 partitioning. >> >> My initial plan was to have a stored procedure on the archive DB use >> postgres_fdw to do an INSERT INTO / SELECT to select the data >> remotely and insert into the local archive table. It would then issue >> a single DELETE command to remotely remove the data from the main DB. >> However I found that doing this resulted in the main DB calling >> thousands (perhaps millions if it's one-per-row) of individual DELETE >> statements based on a ctid column. Aside from WAL behavior concerns, >> it is flooding my postgresql server logs since I log any DML. >> >> On top of that, I'm told that a remote DELETE wouldn't be >> transactional, so if I were to compare inserted rows vs deleted rows >> and found a mismatch, I couldn't just rollback the DELETE. I plan to >> verify this with a small test case later but for now I'll assume this >> to be true. >> >> Right now I'm thinking of falling back to the far-less-elegant method >> of dumping the data to a flat file via COPY, running psql to connect >> to the archive DB remotely and running a COPY to load the data (or >> maybe transferring the flat file to the archive DB to load it there, >> offloading that part of the workload), then deleting the data from >> the main DB. I could capture the rows dumped in a control table and >> compare the rows deleted against that and then rollback the delete if >> necessary. >> >> Like I said, not elegant, but I don't want to risk losing data that >> wasn't successfully archived to the archive DB. I'm very interested >> to hear what others might be doing for tasks like this. > > It might not be elegant, but a COPY / DELETE / LOAD is granular, so > you can restart at any point. > > I might be inclined to COPY/LOAD/check/DELETE