Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ji1VR-00026n-8O for pgsql-novice@arkaria.postgresql.org; Sun, 07 Jun 2020 20:02:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ji1Ut-0004vX-Lu for pgsql-novice@arkaria.postgresql.org; Sun, 07 Jun 2020 20:02:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ji1Ut-0004vQ-DL for pgsql-novice@lists.postgresql.org; Sun, 07 Jun 2020 20:02:23 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ji1Ur-0000od-6B for pgsql-novice@lists.postgresql.org; Sun, 07 Jun 2020 20:02:22 +0000 Received: by mail-ed1-x536.google.com with SMTP id g9so11661378edw.10 for ; Sun, 07 Jun 2020 13:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ua0mR/CYkMUP7C52VuIrbGXYMIYyQMwq+fY53VM+mfg=; b=izjHoEBdzUNee0Cy7XEjn1EYA+C8WxX9qDQQOPeC73oxJe4dsZ9VNNe5N8bGUuwYMi M1q2TKKEushNYB3bHz570gVoWwutqqFAWz0xD9eBRrd1SKH1LxWA+uJeV7K+KgiDFl42 2QD0+3iXaotiQnhZCvYSYxwtmH+hprcxz0ErXkGv9yOTesbhFgD8Wt1Pju+m22d7hdaL PebQlGMPWuqDtFYgiB8+zzyDkxtAiTrzqakXczurbGmLWQklZNZ2bsyCR+GgiW1lLzcX T6vSyiyQOdq3yiCuWxjvBd9dYDGK42C7hrv2fE9Ueyq/04MFvfVQgKFvYX0iNHWV3c++ Yo0Q== 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:in-reply-to; bh=Ua0mR/CYkMUP7C52VuIrbGXYMIYyQMwq+fY53VM+mfg=; b=Z2XSjCmIr/j9dw5uU0Q5RzGACImvukxMnVcE27/Ils1lBJvv0EIJtn4fbyppSSajmS UTc7SFK63BG0e81mNfAPM3Uf0ae/o6ea3Y+G+Z3Z6dQP4wILtT+ewcY+Z4WCd2MZOIhc k8tchydqjzDJ/MdJXN2vUDYs0ftUHhmRXTSkNQlWzKNIHczYeNxpQlOFSUo7lNRfDsUy SBCtEuwWVSO6AbenJJ5dgWjSlPPhLiIsXzJs6vlzkJK1J29HKFzfDYHS289uIFQmBd+u WySD7vV4i0iO2cRFr1XSZalXJUxWB3zClvtTWcAYdmb/LoJI98V79h2M2AiFBvtqxp+H XQyw== X-Gm-Message-State: AOAM530CVU7iiroBcJzSPNlakTTMeLegIPyg4UwhATrFe1OAfYXz5BT6 VA1qWChrUnjrUH0146fa7B9NS0gTUp4= X-Google-Smtp-Source: ABdhPJx90IufAAuM4EPbgEQTm9wBfRXV9XzkY/DZ6Y5Zm18SAuBcsfIayfYFKkpf41fWSJ4hZNgpkQ== X-Received: by 2002:a50:cd56:: with SMTP id d22mr18491204edj.374.1591560138311; Sun, 07 Jun 2020 13:02:18 -0700 (PDT) Received: from daffy (cpc115932-epso6-2-0-cust230.6-3.cable.virginm.net. [81.108.136.231]) by smtp.gmail.com with ESMTPSA id la5sm9119954ejb.94.2020.06.07.13.02.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 13:02:16 -0700 (PDT) Date: Sun, 7 Jun 2020 21:02:15 +0100 From: David Harrigan To: Stephen Frost Cc: pgsql-novice@lists.postgresql.org Subject: Re: pages_in_range for BRIN index Message-ID: <20200607200215.kajtlbpbgeymk4bz@daffy> References: <20200606123556.GV6680@tamriel.snowman.net> <20200606132720.ji66sn6fc2zraovg@frodo.localdomain> <20200607192824.GW6680@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5lovzq6nnlsrktun" Content-Disposition: inline In-Reply-To: <20200607192824.GW6680@tamriel.snowman.net> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --5lovzq6nnlsrktun Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On 07/06/2020 15:28:24, Stephen Frost wrote: > Greetings, > > * David Harrigan (dharrigan@gmail.com) wrote: > > Thank you kindly for replying. Very insightful. Thank you! The type of > > query is mostly "give me all the rows between now and 1 week ago", > > i.e., 7 days worth of data. In some cases that may be extended to 2 > > weeks or 1 month ago, but generally it's around that time range (it is > > filtered on another few attributes, otherwise it would be a massive > > amount of data - however it is mostly time constrained). Would > > classify as a "bulk" query (not quite sure what you mean in that > > regard). > > Yes, that'd qualify as 'bulk'. > > If you really want to work on optimizing this (and, to be clear, I don't > know that you really need to- the BRIN is likely to be pretty small > with just the defaults), you could look at how many rows you typically > have on a page, and then how many pages account for a week or so of > data, and then maybe set your pages_in_range to, say, a fourth of that? > > That'd minimize the size of the BRIN while avoiding having queries using > it for a single week on average, hopefully, only end up scanning up to a > fourth of a week or so of pages that weren't actually relevant to the > query. > > > Perhaps I will go with the default and see how that works out! > > Definitely a reasonable approach too. :) > > > I haven't thought about partitioning. I'll have to read up on that > > (generally, why would I partition?) > > Partitioning is breaking up very large tables (hundreds of millions of > rows) into multiple tables, to make certain operations easier, > particularly ones around data maintenance. Examples include: easier to > expire out old data (just drop the partition instead of having to do a > big DELETE query...), takes less time to VACUUM or reindex a partition > than it does a huge table, pg_dump can export the data in parallel, etc. > > Once a partition is known to be 'complete' and you're not adding any > more rows to it you could also VACUUM FREEZE it, assuming you expect it > to be around long enough for transaction wraparound to be a possibility, > so you don't have to wonder when that's going to happen or such. > > Thanks, > > Stephen Hi Stephen, Thanks once again for your reply. Extremely helpful! I'm going to read up more on partitioning and consider my options with regard the BRIN index. Exciting! :-) -=david=- I prefer encrypted and signed messages. GPG Fingerprint: 110AF423364754E2880FADAD1C5285BFB20A22F9 No trees were harmed in the sending of this message, however, a number of electrons were inconvenienced. This email is sent without prejudice. --5lovzq6nnlsrktun Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEEQr0IzZHVOKID62tHFKFv7IKIvkFAl7dR8EACgkQHFKFv7IK IvkEuQf/U58aNE3rQrAm1M+sH+3Pi4CTEbyn/Pxz5NbjdHlDa4hL+vugNUsjWDNj 2hlO7q9oRHDSNGy5sCT6wwWtWiuL0+cLt3jLn4sg7ppynuip1BDxo3RzX6Pzuqbe Qxe9005Y771Xnq6Kqkdo+Hwm7xMpeNlBb469eUZy7Gv3hidDxKndZK/z1IzRMNic yGwdT74gQxlgYc1HiQsX57POjZUhbF/F8HmpSCM7v7F6nnX69/dlJghFTPES5KJQ Ui5RLZ3nemWK5mvSi3cWd3h8ldjrM+X6br4wTgXBY4V2+DH8DqBktKaUOEoS6MoQ hO76hHX/ZIPC4KAR2LTH+Z62eOcVkA== =+ChN -----END PGP SIGNATURE----- --5lovzq6nnlsrktun--