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 1oGhFV-0006ne-OA for pgsql-performance@arkaria.postgresql.org; Wed, 27 Jul 2022 13:38:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oGhFS-0005cs-Gj for pgsql-performance@arkaria.postgresql.org; Wed, 27 Jul 2022 13:38:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oGhFS-0005cj-1y for pgsql-performance@lists.postgresql.org; Wed, 27 Jul 2022 13:38:50 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oGhFP-0002Mq-Je for pgsql-performance@postgresql.org; Wed, 27 Jul 2022 13:38:49 +0000 Received: by mail-qk1-x731.google.com with SMTP id b25so13232362qka.11 for ; Wed, 27 Jul 2022 06:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc; bh=aDAHyj4dXZP7iMdv/mU1lJStyLDg9aWkRH7kjYeql9Y=; b=Bz9uiih8GxEWly9779Z9C2wtoyn5Miz2K5pF0PNZoA64dhFAIx5jMFsiFkcDvxrobm eT1poqY/OTOZS4qWhO8zLeeRIdUjeOhdZBJPuYbMc76663HbrV6QOdOo+huJ1R+7ayQa /R1kN+Vv70jfL8In/nnkwvC2rAsaxWRlEA0T0eX5uoTu1TRGaTS4MeXE8hOWPgPdCOBr WX0JBk07AkYeVPg1YpUxpiFR7x3xGyxP15lsx4pzMwMvzJG4XmsBe2dUJHXC4/3fZtYE Sf58NEuhAfV1IuMz305eSAQhyGtPR3H6CFd77N/KUHjEgX1b+kSd2wnYHWWKRXnTYAph g6gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=aDAHyj4dXZP7iMdv/mU1lJStyLDg9aWkRH7kjYeql9Y=; b=B/+hDEJvHcwHGSQuz5X+lbjia46YF8zQ16SO3piTwnkNriyU0p2dCATymd28rxb0H8 TRSesAaA/0iC8IZbla3Y33Utxoev/Ji3zkLC9u6ZxTa3pRizQzkzlOfsxfgNgfaT9404 v3O2fWTUZxmKczyR2cwAroB+zBIpC+3+DQfbmaHROXHQMBan6wvpn4CFxHNSjgJSUTca zA4V2fG6ky45dHVRpBUJBaa7/XA4q0He8/guSD6DJxMxZ2cRLNhAq3HZ9uA88Nje6Quo iKNN8On6zvOVnRZ66YI0KzZVJneTRT1pTDcOf1OMois4xNL7+Qv86arZV9yOqJ27VrW9 INfg== X-Gm-Message-State: AJIora/dFO7D2r6E4BIfQ4orM8Ymamb/vU3+rqZhmF0dgwZxXAszjvXk pZ8alv5kuSIMIljPEV0nEaOojQ== X-Google-Smtp-Source: AGRyM1twZeCXYWw6CipWrLnaJIbKPPc/z82zjUojqvKg0m01vmgr85YqJhFU5Beoygurp/QnstDU8w== X-Received: by 2002:a05:620a:f03:b0:6b6:6513:af63 with SMTP id v3-20020a05620a0f0300b006b66513af63mr8522330qkl.312.1658929125918; Wed, 27 Jul 2022 06:38:45 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id g8-20020a05620a40c800b006b60d5a7205sm14104176qko.51.2022.07.27.06.38.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jul 2022 06:38:45 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 53759800AF9; Wed, 27 Jul 2022 08:38:44 -0500 (CDT) Date: Wed, 27 Jul 2022 08:38:44 -0500 From: Justin Pryzby To: Rick Otten Cc: pgsql-performance@postgresql.org Subject: Re: Postgresql 14 partitioning advice Message-ID: <20220727133844.GH15006@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 27, 2022 at 08:55:14AM -0400, Rick Otten wrote: > I'm spinning up a new Postgresql 14 database where I'll have to store a > couple years worth of time series data at the rate of single-digit millions > of rows per day. Since this has to run in AWS Aurora, I can't use > TimescaleDB. > One person I talked to said "try not to have more than 100 partitions", > even with the latest postgresql you'll end up with a lot of lock contention > if you go over 100 partitions. I'm not familiar with this (but now I'm curious). We have over 2000 partitions in some tables. No locking issue that I'm aware of. One issue that I *have* seen is if you have many partitions, you can end up with query plans with a very large number of planner nodes, and it's hard to set work_mem*hash_mem_multiplier to account for that. > This person also recommended manually > kicking off vacuums on a regular schedule rather than trusting autovacuum > to work reliably on the partitioned tables. They must mean *analyze*, which does not run automatically on the partitioned tables (only the partitions). The partitioned table is empty, so doesn't need to be vacuumed. > I've got several keys, besides the obvious time-key that I could partition > on. I could do a multi-key partitioning scheme. Since the data is > inbound at a relatively steady rate, if I partition on time, I can adjust > the partitions to be reasonably similarly sized. What is a good partition > size? Depends on 1) the target number of partitions; and 2) the target size for indexes on those partitions. More partition keys will lead to smaller indexes. Depending on the type of index, and the index keys, to get good INSERT performance, you may need to set shared_buffers to accommodate the sum of size of all the indexes (but maybe not, if the leading column is timestamp). > Since the data most frequently queried would be recent data (say the past > month or so) would it make sense to build an archiving strategy that rolled > up older partitions into larger ones? ie, do daily partitions for the > first four weeks, then come up with a process that rolled them up into > monthly partitions for the next few months, then maybe quarterly partitions > for the data older than a year? (I'm thinking about ways to keep the > partition count low - if that advice is justified.) I think it can make sense. I do that myself in order to: 1) avoid having a huge *total* number of tables (which causes pg_attribute to be large, since our tables are also "wide"); and 2) make our backups of "recent data" smaller; and 3) make autoanalyze a bit more efficient (a monthly partition will be analyzed numerous times the 2nd half of the month, even though all the historic data hasn't changed at all). > Or, should I just have a single 7 Trillion row table with a BRIN index on > the timestamp and not mess with partitions at all? Are you going to need to DELETE data ? Then this isn't great, and DELETEing data will innevitably cause a lower correlation, making BRIN less effective. -- Justin