Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j5sv8-0002tY-0m for pgsql-performance@arkaria.postgresql.org; Sun, 23 Feb 2020 15:11:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j5su8-0006wu-BN for pgsql-performance@arkaria.postgresql.org; Sun, 23 Feb 2020 15:10:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5su7-0006wV-P4 for pgsql-performance@lists.postgresql.org; Sun, 23 Feb 2020 15:10:48 +0000 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j5su3-0006tq-Bb for pgsql-performance@lists.postgresql.org; Sun, 23 Feb 2020 15:10:46 +0000 Received: by mail-yw1-xc41.google.com with SMTP id b81so4042165ywe.9 for ; Sun, 23 Feb 2020 07:10:42 -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=RTqG008B638gcAksyUY+EBJE5xCP4E8R7IVEUAKqqvk=; b=Xe7M0vCM8ZElNuhJvzdFGTtK3HjBASMJRboHodaDw12HgAnlNccWFljafy2ALMomoS ay+bxpDs2t/kBl8NBPLi4B6V44VJCGiHBGaPrwURZmEuq2+Gr6jZGHB8Uma7fLsFXt/G ypeXXIunHyZ4VrLhpV1n9fPnfj8hxTe5HU09XrytkAr1f7viBZUgOAzOcVuQXaHpoNY2 m66qoXwuqWNtqSu5QOl/U5R+6r2POhVfJhm2KSsV6wUvNfG+3WIVpy5krixu9T/bvHFz ji6azNEvh115puBbRpmIGmY/R0hYMKkGIUonEUyljNZIvVWHPZ3KWBePaZMXoGgeImPM /EVA== 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=RTqG008B638gcAksyUY+EBJE5xCP4E8R7IVEUAKqqvk=; b=ZBmphhrLy58ZK007CUakRObaz7RUDWmXVGhwaWJ25/OuvAo6K4koqoLIm0OnibolHK M9QLMugsnILXrd5wK6XcxCgrM8eCjtLkFb4+a9EPz+BXcZYYP22BT+Hd10DW0d3owhsG OnrdHyD6hrjKEbzjSckO7JsS6B7Zb72kVFsOpzkDiuEFFTU4jk3zAc6B4mhAONmdyLK/ Yx3eTlYbUyP7rUwZNM6uOpYxlAH9dZ7k/rTTIZpH0dF+713sPMdvQIwL9mCCnwK4MXHl wF0UVpRiM9unnWF0vqSuGYUMPipq/A0zYIk8BbuX8NdxvqLLyUP1O3CD2q8KKWgV96DS 0IwQ== X-Gm-Message-State: APjAAAWAL7ltx6TKz0Ho+y6WM7BglqQ49wGQhKvyo6KVs5DjC2pl2Xyy TzotCOwrxlNvJyxsof15ZG7ZM+1yVHw= X-Google-Smtp-Source: APXvYqz6KZivG2RQy5h1/u6d36dzHmsHYlACr0HzyzhOjF7PoDe3ec5Ulv2LEFePA6pt7Ha9acQ9cQ== X-Received: by 2002:a0d:d594:: with SMTP id x142mr37278441ywd.253.1582470641568; Sun, 23 Feb 2020 07:10:41 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id j184sm3971399ywa.39.2020.02.23.07.10.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Feb 2020 07:10:40 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id C8C17800897; Sun, 23 Feb 2020 09:10:38 -0600 (CST) Date: Sun, 23 Feb 2020 09:10:38 -0600 From: Justin Pryzby To: Ravi Garg Cc: pgsql-performance@lists.postgresql.org Subject: Re: PostgreSQL 11 higher Planning time on Partitioned table Message-ID: <20200223151038.GW31889@telsasoft.com> References: <1789489940.5008704.1582451790367.ref@mail.yahoo.com> <1789489940.5008704.1582451790367@mail.yahoo.com> <20200223101209.GU31889@telsasoft.com> <1169437250.5002073.1582455449880@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1169437250.5002073.1582455449880@mail.yahoo.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Feb 23, 2020 at 10:57:29AM +0000, Ravi Garg wrote: > - Currently we are thinking to have Daily partitions and as we need to keep 6 months of data thus 180 Partitions.However we have liberty to reduce the number of partitions to weekly/fortnightly/monthly, If we get comparable performance. I didn't hear how large the tables and indexes are. > - We need to look current partition and previous partition for all of our use-cases/queries. Do you mean that a given query is only going to hit 2 partitions ? Or do you mean that all but the most recent 2 partitions are "archival" and won't be needed by future queries ? > Can you please suggest what sort of combinations/partition strategy we can test considering data-volume/vacuum etc. Also let me know if some of the pg_settings can help us tuning this (I have attached my pg_settings). You should determine what an acceptable planning speed is, or the best balance of planning/execution time. Try to detach half your current partitions and, if that gives acceptable performance, then partition by day/2 or more. You could make a graph of (planning and total) time vs npartitions, since I think it's likely to be nonlinear. I believe others have reported improved performance under v11 with larger numbers of partitions, by using "partitions of partitions". So you could try making partitions by month themselves partitioned by day. > - Our use case is limited to simple selects (we don't join with the other > tables) however, we are expecting ~70 million records inserted per day > and there would be couple of updates on each records where average record > size would be ~ 1.5 KB. > shared_buffers | 1048576 If you care about INSERT performance, you probably need to make at least a single partition's index fit within shared_buffers (or set shared_buffers such that it fits). Use transactions around your inserts. If your speed is not limited by I/O, you could further use multiple VALUES(),() inserts, or maybe prepared statements. Maybe synchronous_commit=off. If you care about (consistent) SELECT performance, you should consider VACUUMing the tables after bulk inserts, to set hint bits (and since non-updated tuples won't be hit by autovacuum). Or maybe VACUUM FREEZE to freeze tuples (since it sounds like a typical page is unlikely to ever be updated). -- Justin