On Thu, Nov 18, 2021 at 8:28 AM Tom Lane <tgl@xxxxxxxxxxxxx> wrote: > Justin Pryzby <pryzby@xxxxxxxxxxxxx> writes: > > It shows that the process is running FK triggers. > > Indeed, and doing a seqscan therein. Normally I'd suppose that > this reflects a lack of an index, but RI_FKey_check should always > be doing something that matches the referenced table's unique > constraint, so why isn't it using that? I wonder if the reference tables are empty sometimes, and there's an unlucky sequence of events that results in cached RI plans with seq scans being used later in the same session after the tables are populated.