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 1f6IYD-0006kc-GU for pgsql-general@arkaria.postgresql.org; Wed, 11 Apr 2018 16:24:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f6IYB-0005Hi-Cw for pgsql-general@arkaria.postgresql.org; Wed, 11 Apr 2018 16:24:47 +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 1f6IYA-0005HZ-Ux for pgsql-general@lists.postgresql.org; Wed, 11 Apr 2018 16:24:47 +0000 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f6IY8-00043s-GW for pgsql-general@lists.postgresql.org; Wed, 11 Apr 2018 16:24:45 +0000 Received: by mail-oi0-x244.google.com with SMTP id z8-v6so2288485oix.2 for ; Wed, 11 Apr 2018 09:24:44 -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=eGSIkhAX/pI7zAmTv68iFPeHAO3/n7VKwAgqvU1tsGc=; b=Uon3BSoVT4oR5iH2B6u4IO7cpDI3JwK0J2sFrVB1VkTDDPGzx8+fPTZVbcZSVDgywn zYkmiMhcZAAFDeLRA+Em1OwTbJy0BsssRDILYXyISt169L/q3yyjkHzX7P3BzpeURZg6 rfWXZ5ztPG3Ldk3MbvEDkewtCD3UaPW15JwE/It47OGfNWhHCySxYd6uKWLoSPt6WeZS Hv6R9Y67w8I51CT8JWtg+og9JZIjRtI7Qr0RdiEhRWx4pt2gdEgxbtp/HBpE9weXhjdk gCxsJY3+C2Nd3mvu0FFaKPISJvkYcGraBURvI26XKYBb5wDA2zqjJqspI3YtcPS4O+lW Pz0A== 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=eGSIkhAX/pI7zAmTv68iFPeHAO3/n7VKwAgqvU1tsGc=; b=dBcKEmPlBIEyTj/iowfnCrO9Aa9SOksib9IQA8E4Z3kU7lxYJlIsdy+vkEI+9JQV+g jHHG6BnDauh1BnFTezGC8uxBgLe0YnM+EfYP3z0SFw8rRgmev3qZTNQkHiQ5iI+J2bEO dUwxmel1MSDX17KqIt/E7l2JNbleLhP7iPE7cusTsPUfxRpquwaKvwxdyuchHXlPv5uG fo0V95JyeUHRC5vUwQJQ54PQO95Djz7UzOEFPtUdbfczBITgQHWDEbKGkZN9uK3XMMEn KJ8brGElJ2XX4u0r7mpuFg7pAhcZS6Ex9QGvoe9yl3kNIyNCkjvS6IOEy8Gp0asiLpm2 yHVQ== X-Gm-Message-State: ALQs6tBplzT4q98+paHU1Yb+DKKMf0pFvtoVMZHZ+ReXslO9iR8kxVTQ CyLdyniz1y981e3kuHlfa8q1Eg== X-Google-Smtp-Source: AIpwx48Xb1LeS5VvtEtSBQb5l9Qg3GJKUJxHN/GvrAuwqOUh98hY29N0g2qAgOUn6iqvNS6Gn+X+RQ== X-Received: by 2002:aca:1c05:: with SMTP id c5-v6mr1109075oic.198.1523463883407; Wed, 11 Apr 2018 09:24:43 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id s143-v6sm1005652ois.40.2018.04.11.09.24.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Apr 2018 09:24:42 -0700 (PDT) Subject: Re: Archiving Data to Another DB? To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: Date: Wed, 11 Apr 2018 11:24:41 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.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 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. -- Angular momentum makes the world go 'round.