Skip to content

Reduce memory usage when backing up postgres #727

Description

@ibizaman

When backing up postgres, the COPY process takes more than 1Gb of memory, up to 3Gb.

sudo -u postgres psql

postgres=# SELECT datname, pid, state, query, age(clock_timestamp(), query_start) AS age 
FROM pg_stat_activity
WHERE state <> 'idle' 
    AND pid <> pg_backend_pid()
ORDER BY age;
  datname  |  pid   |        state        |                                                        query                                                        |       age       
-----------+--------+---------------------+---------------------------------------------------------------------------------------------------------------------+-----------------
 nextcloud | 666198 | idle in transaction | COPY public.oc_flow_operations (id, class, name, checks, operation, entity, events) TO stdout;                      | 00:00:00.986075

The COPY is pretty fast but it runs multiple COPY one after the other. Maybe it's because they are all in one transaction?

From htop:

    PID USER       PRI  NI  VIRT   RES▽  SHR S  CPU% MEM%   TIME+  Command
 666198 postgres    20   0 3262M 2962M 2952M R   5.7  9.4  2:13.32 postgres: postgres nextcloud [local] COPY

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions