title: Postgres 'UPDATE' query producing out of memory error
body: <p>I have two tables: </p>
  
  <pre><code>CREATE TABLE public.organization
  (
   id_organization SERIAL PRIMARY KEY,
   name varchar, 
   country varchar,
   prod_id varchar
   );
  
  
  CREATE TABLE public suborganization
  (
   id_suborganization SERIAL PRIMARY KEY,
   id_organization bigint references organization(id_organization) ON UPDATE CASCADE ON DELETE CASCADE,
   full_address varchar,
   prod_id varchar
   );
  </code></pre>
  
  <p>Both tables are populated apart from the suborganization.id_organization. I'm trying to populate this column using the following statement: </p>
  
  <pre><code>UPDATE suborganization SET id_organization = organization.id_organization 
  FROM organization 
  WHERE suborganization.prod_id = organization.prod_id;
  </code></pre>
  
  <p>However, Postgres is producing the following error message and failing to populate the foreign key:</p>
  
  <pre><code>ERROR: out of memory
  DETAIL: Failed on request of size 8
  </code></pre>
  
  <p>These are large tables, approximately 200 million rows but I'm running it on a machine with 62.8GB of RAM and work_mem set to 4MB. </p>
  
  <p>Can anyone explain why I'm getting this error message? Is it simply a hardware issue or do I need to reconfigure postgres? Or is it my method that is flawed, is there a better way to create this foreign key? </p>
  
  <p>PotgreSQL 9.4.7 running on Red Hat Enterprise Linux Server 6.7</p>