Count distinct performance compared on top 4 SQL databases 12 years ago
Another reason postgres could be running very slow, is that it may be spooling the intermediate result to a temp file on hard disk.
Do you see a performance increase when using SSD Drives?