Search code examples
postgresqldockervacuumautovacuum

How to ensure that the autovacuum daemon is running in my PostgreSQL Docker Container?


I am benchmarking my database running in a Docker container against fragmentation issues and found out that the autovacuum daemon is not running.

SELECT
    schemaname, relname,
    last_vacuum, last_autovacuum,
    vacuum_count, autovacuum_count  -- not available on 9.0 and earlier
FROM pg_stat_user_tables;

gives:

| schemaname | relname     |last_vacuum| last_autovacuum |vacuum_count| autovacuum_count |
|------------|-------------|-----------|-----------------|------------| -----------------|
| public     | mt_doc_order|   <null>  |    <null>       |      0     |         0        |

I am therefore running into fragmentation performances effects:

enter image description here

How can I make sure that this autovacuum daemon is running when I am starting my PostgreSQL Docker Container?


Solution

  • Run the SQL statement

    ALTER SYSTEM SET autovacuum = on;
    

    as superuser, then restart the PostgreSQL server process.