Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVM61-0000Hc-3D for pgsql-performance@arkaria.postgresql.org; Sat, 30 Dec 2017 18:43:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eVM60-0007Va-8d for pgsql-performance@arkaria.postgresql.org; Sat, 30 Dec 2017 18:43:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eVM5z-0007VR-UU for pgsql-performance@lists.postgresql.org; Sat, 30 Dec 2017 18:43:00 +0000 Received: from mail-io0-x22e.google.com ([2607:f8b0:4001:c06::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eVM5s-0005dU-3o for pgsql-performance@lists.postgresql.org; Sat, 30 Dec 2017 18:42:59 +0000 Received: by mail-io0-x22e.google.com with SMTP id i143so23799010ioa.3 for ; Sat, 30 Dec 2017 10:42:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=S9nmgCEMvXqYk7bQkuHhhTcqqhN5Ed9wUAEIcZ/5hcg=; b=TkLQEsKjCDeK7azZSsK5HFI4ORZAPQaDF88bnlzpAG5jHH2N2/w7GyrfvblA5ccbAK 2H6xrqnhN6yuYfw39IDJLZyrfgowC8vrtLeBaMFsqOIDOWLRl+5B9hkK01lxiXD8IMcA EenGn17E9x1gDyLuYyy/0iSbL47yMLxU56PGsRdIUzT18YWh0n4zkrcqwaXB714D2y/S uPrWzCk+MNIXscmFReqFPYXPfoii0ebBhdFC/KCemP+dzAUH+LXKEna/V0rQOoCM+wtn V0w285T2n5Ku7axWG+QJNgqk11Yi1kD2HrskosKup+HF/MSAZTVN/XUOFFqsh+jwz3Wy XUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=S9nmgCEMvXqYk7bQkuHhhTcqqhN5Ed9wUAEIcZ/5hcg=; b=pdeZoXQoIqWFDz4WUjygTcciTPU8SzPtvleSzmaEqrBXowdaPYWbSsQZaBZcC3ykXK muuaJI6X+tt6AhOppXEsDcawn2CW3A8fTGwjN3lhvQXxkCvdDi+Ugm71cnYG2UYVQIsq 41pGJolZKYyjI5lYQAkmbdeEeJOEY4xHMOTepggRl31UTWnKhEXcE0AE1m828fGseTnc BCidj1EufxEm5JwRXCtZHDVRI7pk+eoRo3LTzNMEjb2KfvABE7LEUHkewbizJA8I3sDA iAHmepiO16864cdaU0tQDIiB9NbhIqDkPA+OKj3Rh0J5Yh/n3Pdb7UYCkeRnbV2ODGVU OacQ== X-Gm-Message-State: AKGB3mK3guBxs9c4T+LeC7obkaekC4eLnInlq2o6TXMoPUx5eVvyLAwn cnYFYF5I5o/C9oOcv/3yo0EUWQ== X-Google-Smtp-Source: ACJfBovF0O4vlBf7G5iaq5Yyjevbzh0Em9uf8uM2JhNJFIpMsqufz+E0+HTHkW88BxV0lUVfcapsWw== X-Received: by 10.107.132.24 with SMTP id g24mr51756801iod.151.1514659369274; Sat, 30 Dec 2017 10:42:49 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id k23sm14229062iti.22.2017.12.30.10.42.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Dec 2017 10:42:48 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id CCB538011F3; Sat, 30 Dec 2017 12:42:47 -0600 (CST) Date: Sat, 30 Dec 2017 12:42:47 -0600 From: Justin Pryzby To: Robert Blayzor Cc: pgsql-performance@lists.postgresql.org Subject: Re: partitioning an existing table - efficient pg_dump Message-ID: <20171230184247.GH4172@telsasoft.com> References: <20171230053821.GE4172@telsasoft.com> <942C6568-41A7-46EC-B391-D523CC36B3AB@inoc.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <942C6568-41A7-46EC-B391-D523CC36B3AB@inoc.net> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Dec 30, 2017 at 09:19:05AM -0500, Robert Blayzor wrote: > On Dec 30, 2017, at 12:38 AM, Justin Pryzby wrote: > > BTW depending on your requirements, it may be possible to make pg_dump much > > more efficient. For our data, it's reasonable to assume that a table is > > "final" if its constraints exclude data older than a few days ago, and it can > > be permanently dumped and excluded from future, daily backups, which makes the > > backups smaller and faster, and probably causes less cache churn, etc. But I > > imagine you might have different requirements, so that may be infeasible, or > > you'd maybe have to track insertions, either via p > > The idea is only only keep a # of months available for searching over a period of months. Those months could be 3 or more, up to a year, etc. But being able to just drop and entire child table for pruning is very attractive. Right now the average months data is about 2-3 million rows each. Data is just inserted and then only searched. Never updated… > > I also like the idea of skipping all this older data from a PGdump. We archive records inserted into these tables daily into cold storage. ie: export and compressed. So the data is saved cold. We dump the DB nightly also, but probably would make sense to skip anything outside of the newest child table. Just not sure how to make that happen, yet…. For us, I classify the tables as "partitioned" or "not partitioned" and subdivide "partitioned" into "recent" or "historic" based on table names; but if you design it from scratch then you'd have the opportunity to keep a list of partitioned tables, their associated date range, date of most recent insertion, and most recent "final" backup. This is the essence of it: snap= ... SELECT pg_export_snapshot(); pg_dump --snap "$snap" -T "$ptnreg" -f nonpartitioned.new pg_dump --snap "$snap" -t "$recent" -f recent.new loop around historic partitioned tables and run "final" pg_dump if it's been INSERTed more recently than it's been dumped. remove any "final" pg_dump not included in any existing backup (assuming you keep multiple copies on different rotation). Note that pg_dump -t/-T is different from "egrep" in a few special ways.. Justin