暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

等待 PostgreSQL 18 – 允许更改 autovacuum_max_workers 而无需重新启动

飞象数据 2025-07-15
82

原文地址:

https://www.depesz.com/2025/01/24/waiting-for-postgresql-18-allow-changing-autovacuum_max_workers-without-restarting/


2025 年 1 月 6 日,Nathan Bossart提交了补丁:

    Allow changing autovacuum_max_workers without restarting.
    允许更改autovacuum_max_worker不需要重启。


    This commit introduces a new parameter named
    autovacuum_worker_slots that controls how many autovacuum worker
    slots to reserve during server startup.  Modifying this new
    parameter's value does require a server restart, but it should
    typically be set to the upper bound of what you might realistically
    need to set autovacuum_max_workers.  With that new parameter in
    place, autovacuum_max_workers can now be changed with a SIGHUP
    (e.g., pg_ctl reload).


    If autovacuum_max_workers is set higher than
    autovacuum_worker_slots, a WARNING is emitted, and the server will
    only start up to autovacuum_worker_slots workers at a given time.
    If autovacuum_max_workers is set to a value less than the number of
    currently-running autovacuum workers, the existing workers will
    continue running, but no new workers will be started until the
    number of running autovacuum workers drops below
    autovacuum_max_workers.


    Reviewed-by: Sami Imseih, Justin Pryzby, Robert Haas, Andres Freund, Yogesh Sharma
    Discussion: https://postgr.es/m/20240410212344.GA1824549%40nathanxps13

    这很有趣。

    您可能知道,我是自动清理 (auto vacuum) 的粉丝,并且我个人认为人们通常不会正确配置他们的auto vacuum。

    其中一个方案是能够配置 auto vacuum,使其在一天中的特定时间段内更高效地工作。

    由于这一变化,我们可以:

    • 将 autovacuum_worker_slots 设置为 50 之类的值

    • 将 autovacuum_max_workers 设置为正常值 3-10

    然后,例如在晚上或周末,将autovacuum_max_workers提升到更高的值,以使autovacuum完成更多需要的工作(如果需要)。

    那么,让我们看看它实际上是如何运作的:

      =show autovacuum_worker_slots ;
       autovacuum_worker_slots
      ─────────────────────────
       50
      (1 row)


      =show autovacuum_max_workers ;
       autovacuum_max_workers
      ────────────────────────
       3
      (1 row)
      这就是基准线。现在,假设我们进入了一段时期,希望 autovacuum 能够做更多工作,这样我就可以:
        =alter system set autovacuum_max_workers = 10;
        ALTER SYSTEM


        =select pg_reload_conf();
         pg_reload_conf
        ────────────────
         t
        (1 row)
        从此刻起,autovacuum 将最多支持 10 个并发:
          =show autovacuum_max_workers ;
           autovacuum_max_workers
          ────────────────────────
           10
          (1 row)
          当低负荷期结束时,我们必须缩减维护工作:
            =alter system reset autovacuum_max_workers;
            ALTER SYSTEM


            =select pg_reload_conf();
             pg_reload_conf
            ────────────────
             t
            (1 row)


            =show autovacuum_max_workers ;
             autovacuum_max_workers
            ────────────────────────
             3
            (1 row)
            这真是太棒了,我等这样的事已经很久了。

            文章转载自飞象数据,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

            评论