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.89) (envelope-from ) id 1iXLJZ-0007Xr-9G for pgsql-general@arkaria.postgresql.org; Wed, 20 Nov 2019 08:26:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXLJY-00067F-2i for pgsql-general@arkaria.postgresql.org; Wed, 20 Nov 2019 08:26:16 +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 1iXLJX-00066L-Lb for pgsql-general@lists.postgresql.org; Wed, 20 Nov 2019 08:26:15 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iXLJU-0005ts-EH for pgsql-general@lists.postgresql.org; Wed, 20 Nov 2019 08:26:14 +0000 Received: from [10.8.0.75] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.145]) with ESMTPSA (Nemesis) id 1MX0Xf-1iMUUj2uVd-00XPKC for ; Wed, 20 Nov 2019 09:26:08 +0100 Subject: Re: How should I specify work_mem/max_worker_processes if I want to do big queries now and then? To: pgsql-general@lists.postgresql.org References: From: Thomas Kellerer Message-ID: <7dc8d3a4-3869-19fc-7056-0b5e498174f9@gmx.net> Date: Wed, 20 Nov 2019 09:26:07 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:8+VC7Nchbfnl8NmxRyND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8sEowrEtp+uWNURMco9lDgVozT4Q+V5FfsN6njKiSauVU2LXg5x7wLAmec6W9V1KpZtDZYmo tZA3CTHyp6xs/GhjEaUMgnGlBZrbGRfeyCizOsCAs= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk James(王旭) schrieb am 20.11.2019 um 08:56: > I am doing a query to fetch about 10000000 records in one time. But > the query seems very slow, like "mission impossible". I am very > confident that these records should be fit into my shared_buffers > settings(20G), and my query is totally on my index, which is this > big:(19M x 100 partitions), this index size can also be put into > shared_buffers easily.(actually I even made a new partial index which > is smaller and delete the bigger old index) > > This kind of situation makes me very disappointed.How can I make my > queries much faster if my data grows more than 10000000 in one > partition? I am using pg11.6. max_worker_processes can't be changed without a restart. But work_mem and max_parallel_workers_per_gather can be changed for a single session. If you normally don't need parallel execution, I would suggest to configure max_worker_processes and max_parallel_workers to a sensible "maximum" value. Set max_parallel_workers_per_gather to a very low value or even 0 if you want to disable it by default. Then, when you run a really "big" query, you can set max_parallel_workers_per_gather to a sensible value to make the query use parallel execution and increase work_mem so that potential sort, hash or grouping operations don't spill to disk. To give you some hints there we would need to see the current execution plan generated using explain (analyze, buffers, format text). If you turn on track_io_timing before that, it would be even more helpful. Thomas