From: James(王旭) <wangxu@gu360.com>
To: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: How should I specify work_mem/max_worker_processes if I want to do big queries now and then?
Date: Thu, 21 Nov 2019 10:27:29 +0800
Message-ID: <tencent_66FE3CD15858DF5651C94407@qq.com> (raw)
In-Reply-To: <7dc8d3a4-3869-19fc-7056-0b5e498174f9@gmx.net>
References: <tencent_3E7AB8853A9009844041E40C@qq.com>
<7dc8d3a4-3869-19fc-7056-0b5e498174f9@gmx.net>
Thanks Thomas for this information, I will try that and get back here.
James
------------------ Original ------------------
From: "Thomas Kellerer"<spam_eater@gmx.net>;
Date: Wed, Nov 20, 2019 04:26 PM
To: "pgsql-general"<pgsql-general@lists.postgresql.org>;
Subject: Re: How should I specify work_mem/max_worker_processes if I want to do big queries now and then?
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: wangxu@gu360.com, spam_eater@gmx.net
Subject: Re: How should I specify work_mem/max_worker_processes if I want to do big queries now and then?
In-Reply-To: <tencent_66FE3CD15858DF5651C94407@qq.com>
References: <tencent_3E7AB8853A9009844041E40C@qq.com> <7dc8d3a4-3869-19fc-7056-0b5e498174f9@gmx.net> <tencent_66FE3CD15858DF5651C94407@qq.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox