博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL wal_buffers 自动计算算法
阅读量:5814 次
发布时间:2019-06-18

本文共 2454 字,大约阅读时间需要 8 分钟。

标签

PostgreSQL , wal_buffers , shared_buffers


背景

当wal_buffers设置为-1时,PG会自动计算一个值,取决于几个因素,wal_segment_size, shared_buffer.

算法

src/backend/access/transam/xlog.c

/*   * GUC check_hook for wal_buffers   */  bool  check_wal_buffers(int *newval, void **extra, GucSource source)  {          /*           * -1 indicates a request for auto-tune.           */          if (*newval == -1)          {                  /*                   * If we haven't yet changed the boot_val default of -1, just let it                   * be.  We'll fix it when XLOGShmemSize is called.                   */                  if (XLOGbuffers == -1)                          return true;                    /* Otherwise, substitute the auto-tune value */                  *newval = XLOGChooseNumBuffers();          }            /*           * We clamp manually-set values to at least 4 blocks.  Prior to PostgreSQL           * 9.1, a minimum of 4 was enforced by guc.c, but since that is no longer           * the case, we just silently treat such values as a request for the           * minimum.  (We could throw an error instead, but that doesn't seem very           * helpful.)           */          if (*newval < 4)                  *newval = 4;            return true;  }      /*   * Auto-tune the number of XLOG buffers.   *   * The preferred setting for wal_buffers is about 3% of shared_buffers, with   * a maximum of one XLOG segment (there is little reason to think that more   * is helpful, at least so long as we force an fsync when switching log files)   * and a minimum of 8 blocks (which was the default value prior to PostgreSQL   * 9.1, when auto-tuning was added).   *   * This should not be called until NBuffers has received its final value.   */  static int  XLOGChooseNumBuffers(void)  {          int                     xbuffers;            xbuffers = NBuffers / 32;          if (xbuffers > (wal_segment_size / XLOG_BLCKSZ))                  xbuffers = (wal_segment_size / XLOG_BLCKSZ);          if (xbuffers < 8)                  xbuffers = 8;          return xbuffers;  }

算法

自动计算:shared_buffers/32

上限:wal_segment_size/XLOG_BLCKSZ

下限:8*XLOG_BLCKSZ

例子

postgres=# show wal_segment_size ;   wal_segment_size   ------------------   16MB  (1 row)    postgres=# show wal_block_size  ;   wal_block_size   ----------------   8192  (1 row)    postgres=# show shared_buffers ;   shared_buffers   ----------------   32GB  (1 row)

以上参数,如果wal_buffers设置为-1,那么自动计算得到的值为16MB.

转载地址:http://kqtbx.baihongyu.com/

你可能感兴趣的文章
python 开发之selenium
查看>>
Xcode3.2.5中找不到Mac OS X - Command Line Utility -...
查看>>
css的div垂直居中的方法,百分比div垂直居中
查看>>
如何理解EM算法
查看>>
nginx 域名跳转一例~~~(rewrite、proxy)
查看>>
linux用户家目录无损迁移到独立硬盘
查看>>
文件查找
查看>>
shell编程前言(一)
查看>>
5、centos7.*配置yum的EPEL源及其它源
查看>>
JSON前后台简单操作
查看>>
shell中一些常见的文件操作符
查看>>
CentOS 7 装vim遇到的问题和解决方法
查看>>
JavaScript基础教程1-20160612
查看>>
使用第三方类、库需要注意的正则类RegexKitLite的使用
查看>>
iOS \U7ea2 乱码 转换
查看>>
FCN图像分割
查看>>
ios xmpp demo
查看>>
python matplotlib 中文显示参数设置
查看>>
数据库事务隔离级别
查看>>
os模块大全详情
查看>>