This was performed on Ubuntu 14.04 with a fresh install of PostgreSQL 9.3.14 directly from the official Postgres apt repo. It only works if the query planner chooses the attached plan (with HashAggregate).
Create and populate a new database:
psql -U postgres -c "create database test;"
psql -U postgres test < populate.sql
Open a connection to the database and execute query.sql
. The Postgres worker memory usage will rise approximately 50MB and won't be released until the connection is closed.
A memory leak is when the process doesn't release memory that is no longer needed, causing memory to rise indefinitely. Killing a process will always release the memory.
The Postgres process should release resources after the query is done.
Here's the full context: https://www.postgresql.org/message-id/CAHYFdT-QWmnZy%3DP-D9qcBPmnx5hr1SD2%3De73XxJbawGpMW2Jfw%40mail.gmail.com
Turns out it was due to the implementation of array_agg() in 9.3: https://www.postgresql.org/message-id/25527.1472215262%40sss.pgh.pa.us