From: Florents Tselai <florents.tselai@gmail.com>
To: Raj kumar <rajkumar820999@gmail.com>
Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: Improve "select count(*)" query - takes more than 30 mins for some large tables
Date: Mon, 11 Jul 2022 10:23:01 +0300
Message-ID: <1B1927BA-F7DE-40E8-8F67-BCC001CD4C6B@gmail.com> (raw)
In-Reply-To: <CACxU--UJY4sD2SjW8V3W0oAPuuTzE3fAvBzTaej-BmUUNJxN_Q@mail.gmail.com>
References: <CACxU--UJY4sD2SjW8V3W0oAPuuTzE3fAvBzTaej-BmUUNJxN_Q@mail.gmail.com>
> On 11 Jul 2022, at 10:16 AM, Raj kumar <rajkumar820999@gmail.com> wrote:
>
> Hi,
>
> How can I improve "select count(*)" for larger tables? I'm doing a db migration and need to validate the data count.
> "select count(*) " queries are taking more than 30 minutes for some tables which is more than the downtime we have.
> Will work_mem increase help? or how can i speed up this row count?
Personally, whenever I’ve had slow count(*) or count (distinct id), eventually
I’ve resorted to Unix tools.
psql “select id from my_table" | sort -u | wc -l
The convenience/performance tradeoff depends heavily on your schema.
After all unix streams don’t know much about your integrity requirements.
>
> Thanks,
> Raj
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 using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: florents.tselai@gmail.com, rajkumar820999@gmail.com, pgsql-admin@lists.postgresql.org
Subject: Re: Improve "select count(*)" query - takes more than 30 mins for some large tables
In-Reply-To: <1B1927BA-F7DE-40E8-8F67-BCC001CD4C6B@gmail.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