PostgreSQL pending patch : pg_basebackup throttling, limit network transfer rate

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:
PostgreSQL 的一个限速补丁, 目前可以实现基础备份命令pg_basebackup的限速.

PostgreSQL 9.3beta2为例
安装补丁
root@db-172-16-3-33-> cd postgresql-9.3beta2
root@db-172-16-3-33-> wget http://www.postgresql.org/message-id/attachment/29732/backup_throttling.patch
root@db-172-16-3-33-> patch -p1 < ./backup_throttling.patch
root@db-172-16-3-33-> gmake && gmake install

pg_basebackup   新增-r选项.
root@db-172-16-3-33-> pg_basebackup --help
  -r, --max-rate         maximum transfer rate between server and client


[测试]
限速1MB/s (可以单位m, k)
pg93@db-172-16-3-39-> pg_basebackup -D $PGDATA -F p -x -P -v -h 172.16.3.33 -U postgres -r 1m
WARNING:  skipping special file "./.s.PGSQL.1999"
transaction log start point: 1/6F000028 on timeline 13
WARNING:  skipping special file "./.s.PGSQL.1999"/pg_root/pg_subtrans/0059)
207155/403043 kB (51%), 0/1 tablespace (...03/pg93/pg_root/base/16384/16385)


root@db-172-16-3-39-> sar -n DEV 5 10000|grep eth0
02:47:33 PM      eth0    752.00     58.00 1110626.40   7256.80      0.00      0.00      2.00
02:47:38 PM      eth0    663.20     57.40 972859.20   7505.00      0.00      0.00      1.80
02:47:43 PM      eth0    749.00     61.20 1107662.00   7462.00      0.00      0.00      1.60
02:47:48 PM      eth0    791.80     58.40 1170254.00   7282.80      0.00      0.00      1.60


[参考]
2.
+      <term><option>--max-rate</option></term>
+      <listitem>
+       <para>
+       The maximum amount of data transferred from server per second.
+       The purpose is to limit impact of
+       <application>pg_basebackup</application> on a running master server.
+       </para>
+       <para>
+       Suffixes <literal>k</literal> (kilobytes) and <literal>m</literal>
+       (megabytes) are accepted. For example: <literal>10m</literal>
+       </para>
+      </listitem>

3. 
root@db-172-16-3-33-> pg_basebackup --help
  -r, --max-rate         maximum transfer rate between server and client

4.
+/*
+ * If the progress is more than what max_rate allows, sleep.
+ *
+ * Do not call if max_rate == 0.
+ */
+static void
+enforce_max_rate()
+{
+       int64           min_elapsed,
+                               now,
+                               elapsed,
+                               to_sleep;
+
+       int64           last_chunk;
+
+       last_chunk = totaldone - last_measured;
+
+       /* The measurements shouldn't be more frequent then necessary. */
+       if (last_chunk < RATE_MIN_SAMPLE)
+               return;
+
+
+       now = localGetCurrentTimestamp();
+       elapsed = now - last_measured_time;
+
+       /*
+        * max_rate relates to seconds, thus the expression in brackets is
+        * milliseconds per byte.
+        */
+       min_elapsed = last_chunk * (USECS_PER_SEC / max_rate);
+
+       /*
+        * min_elapsed is the minimum time we must have spent to get here. If we
+        * spent less, let's wait.
+        */
+       to_sleep = min_elapsed - elapsed;
+       if (to_sleep > 0)
+               pg_usleep((long) to_sleep);
+
+       last_measured = totaldone;
+       last_measured_time = now + to_sleep;
+}
+

 /*
  * Write a piece of tar data
@@ -852,6 +977,8 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
                totaldone += r;
                if (showprogress)
                        progress_report(rownum, filename);
+               if (max_rate > 0)
+                       enforce_max_rate();
        }  

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
9月前
|
SQL NoSQL 数据库
GPDB中gp_vmem_protect_limit参数的意义
GPDB中gp_vmem_protect_limit参数的意义
102 0
|
存储 缓存 大数据
Starrocks执行查询报错:Memory of process exceed limit. Used: XXX, Limit: XXX. Mem usage has exceed the limit of BE
Starrocks执行查询报错:Memory of process exceed limit. Used: XXX, Limit: XXX. Mem usage has exceed the limit of BE
|
JSON Kubernetes API
etcdserver: mvcc: database space exceeded
etcdserver: mvcc: database space exceeded
370 0
|
SQL 关系型数据库 MySQL
Packets larger than max_allowed_packet are not allowed(mysql数据查询提示:不允许超过允许的最大数据包)解决方案
Packets larger than max_allowed_packet are not allowed(mysql数据查询提示:不允许超过允许的最大数据包)解决方案
244 0
|
关系型数据库 MySQL
MySQL - Packet for query is too large (4,544,730 > 4,194,304). You can change this value on the …
MySQL - Packet for query is too large (4,544,730 > 4,194,304). You can change this value on the …
297 0
|
关系型数据库 数据库 PostgreSQL
PG异常无法启动的问题:could not read file "pg_logical/replorigin_checkpoint": Success
问题描述 新安装不久的PostgreSQL数据库,断电后重启,查看日志如下 2019-01-08 08:44:19.989 UTC [7493] LOG: database system was interrupted; last known up at 2018-12-24 10:56:28 UTC 2019-01-08 08:44:19.
3229 0
|
弹性计算 关系型数据库 数据库连接
PostgreSQL 12 preview - Move max_wal_senders out of max_connections for connection slot handling
标签 PostgreSQL , max_wal_senders , max_connections , sorry, too many clients already 背景 如果你需要使用PG的流复制,上游节点的max_wal_senders参数,用来限制这个节点同时最多可以有多少个wal sender进程。 包括逻辑复制、物理复制、pg_basebackup备份等,只要是使用stre
337 0
|
关系型数据库 MySQL Linux
Packet for query is too large (12238 > 1024). You can change this value
MySQL max_allowed_packet 设置过小导致记录写入失败 mysql根据配置文件会限制server接受的数据包大小。 有时候大的插入和更新会受max_allowed_packet 参数限制,导致写入或者更新失败。
1993 0