title: Postgresql error statement is too large
body: <p>I developed a script on python and sqlalchemy to get and update the last activity of my active users.</p>
  
  <p>But the users are increasing a lot, now i´m getting the following error</p>
  
  <pre><code>psycopg2.ProgrammingError: Statement is too large. Statement Size: 16840277 bytes. Maximum Allowed: 16777216 bytes
  </code></pre>
  
  <p>I was thinking if I update the file <em>postgres.conf</em> it will work, so with the help of pgtune I updated the file, but it does not work, so I updated my kernel on <em>/etc/syslog.conf</em>, with the following parameters</p>
  
  <pre><code>kern.sysv.shmmax=4194304
  kern.sysv.shmmin=1
  kern.sysv.shmmni=32
  kern.sysv.shmseg=8
  kern.sysv.shmall=1024
  </code></pre>
  
  <p>and again it does not work.</p>
  
  <p>After that I divide my query into slices to reduce the size but I got the same error.</p>
  
  <p>How can know what parameter I need to update, to increase the size of my statement?</p>
  
  <p>Workflow</p>
  
  <pre><code>query = "SELECT id FROM {}.{} WHERE status=TRUE".format(schema, customer_table)
  ids = ["{}".format(i)for i in pd.read_sql(query, insert_uri).id.tolist()]
  
  read_query = """
  SELECT id,
   MAX(CONVERT_TIMEZONE('America/Mexico_City', last_activity)) lastactivity
  FROM activity WHERE
  DATE_TRUNC('d', CONVERT_TIMEZONE('America/Mexico_City', last_activity)) =
  DATE_TRUNC('d', CONVERT_TIMEZONE('America/Mexico_City', CURRENT_DATE))-{} and
   id in ({})
  GROUP BY id
  """.format(day, ",".join(ids))
  
  last_activity = pd.read_sql(read_query, read_engine, parse_dates=True)
  </code></pre>