Skip to content

repro memory leak under pg_stat_monitor #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

steve-chavez
Copy link
Member

Problem

When adding pg_stat_monitor like:

shared_preload_libraries='pg_net, pg_stat_monitor'

Memory usage keeps increasing for the pg_net background worker.

To prove this execute in one terminal:

xpg -v 15 psql

And this in another:

watch -n 1 'ps -p $(cat build-15/bgworker.pid) -o %mem,rss,vsz,comm'

%MEM   RSS    VSZ COMMAND
 0.1 19164 722508 postgres

The RSS should be seen as always growing, which proves the memory leak.

Root cause

pg_stat_monitor statistics are split into configurable time intervals (buckets). As one bucket fills or a time interval passes, pg_stat_monitor creates a new one, keeping historical data in distinct buckets.

pg_net queries its internal tables each second.

This means that the "memory leak" is actually expected behavior by pg_stat_monitor.

We need to fix this in pg_net itself, by doing #164.

To do this execute in one terminal:

```bash
xpg -v 15 psql
```

And this in another:

```bash
watch -n 1 'ps -p $(cat build-15/bgworker.pid) -o %mem,rss,vsz,comm'

%MEM   RSS    VSZ COMMAND
 0.1 19164 722508 postgres
```

The RSS should be seen as always growing, which proves the memory leak.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant