Cc: pgsql-performance@xxxxxxxxxxxxxxxxxxxx, pgsql-admin@xxxxxxxxxxxxxxxxxxxx Please avoid simultaneously sending the same question to multiple lists. It means that people can't see each others replies and everything that implies. On Sun, Nov 25, 2018 at 03:08:33PM +0200, Mariel Cherkassky wrote: > However when I run the query without the explain analyze it takes forever > to run it(More then two hours). > Is there a possibility that it is related to fetching or something like > that ? If it's a remote database, I expect that's why. Maybe you can test by running the query on the DB server. Or by running another variant of the query, such as: WITH x AS (QUERY GOES HERE) SELECT 1; which returns only one row but after having executed the query behind CTE, as optimization fence. Justin