Re: Improve "select count(*)" query - takes more than 30 mins for some large tables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On 11 Jul 2022, at 10:16 AM, Raj kumar <rajkumar820999@xxxxxxxxx> 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







[Index of Archives]     [Postgresql Home]     [Postgresql General]     [Postgresql Performance]     [Postgresql PHP]     [Postgresql Jobs]     [PHP Users]     [PHP Databases]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Forum]

  Powered by Linux