Open epratt-yb opened 3 years ago
This is not necessarily restricted to pgloader. ALTER TABLE ADD CONSTRAINT ... FOREIGN KEY
ends up doing a LEFT JOIN from the parent table to the dependent table. This query must be able to resolve on a single nodes heap memory. If the heap is insufficient, then the backend will likely be OOM-killed and all sessions tied to that tserver (postmaster) process will also be killed. See #9541.
Relevant code:
static void
validateForeignKeyConstraint(char *conname,
...
/*
* See if we can do it with a single LEFT JOIN query. A false result
* indicates we must proceed with the fire-the-trigger method.
*/
if (RI_Initial_Check(&trig, rel, pkrel))
return;
...
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
...
First, notice that there is an alternative to the LEFT JOIN. This alternative path looks very similar to the COPY OOM issue. If that's the case, we can solve this by
It should address #2 in comment above.
Jira Link: DB-2576 We have been testing migrating mysql databases. We were using the employees' sample DB to do some testing and when we get to the foreign key creation we end up OOM the system. The data is not very big so I'm surprised we OOM. this seems to be the query we hit the issue with:
We can see from dmesg -T that we OOM:
Attached is the core dump and screen grab.