recursive query too big to complete. are there any strategies to limit/partition?

From: Jonathan Vanasco <postgres(at)2xlp(dot)com>
To: pgsql-general general <pgsql-general(at)postgresql(dot)org>
Subject: recursive query too big to complete. are there any strategies to limit/partition?
Date: 2017-01-26 23:37:21
Message-ID: 682C14D4-B6CE-4969-8EF8-71A68DB90882@2xlp.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There are over 20 million records in a self-referential database table, where one record may point to another record as a descendant.

Because of a bug in application code, there was no limit on recursion. The max was supposed to be 4. A few outlier records have between 5 and 5000 descendants (there could be more. I manually found one chain of 5000.

I need to find all the chains of 5+ and mark them for update/deletion. While the database is about 10GB, the recursive search is maxing out on diskspace and causing a failure (there was over over 100GB of workspace free)

Is there any way to make a recursive query work, or will I have to use another means and just iterate over the entire dataset (either in postgres or an external service)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2017-01-27 00:07:00 Re: recursive query too big to complete. are there any strategies to limit/partition?
Previous Message Jeff Janes 2017-01-26 18:06:31 Re: Transaction apply speed on the standby