突然间,一天或两天的postgres行动开始耗费大量时间.创建命令(52秒)并恢复数据库(现在9分钟,最多50秒).
通过在运行postgres命令时运行iostat,我可以确认其ec2卷的IOPS已达到其限制(3 IOPS / GB等于100 IOPS的300 IOPS).运行此命令后可以在下面看到它iostat -d 5 -x -p xvdf.
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.35 2.28 1.20 298.99 19.65 13082.19 87.29 23.42 78.03 64.19 78.09 3.29 98.75 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 1.80 0.00 297.40 0.00 13067.20 87.88 126.47 420.75 0.00 420.75 3.35 99.76 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 1.80 0.00 297.40 0.00 13067.20 87.88 126.32 417.95 0.00 417.95 3.35 99.76 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 1.80 0.00 297.80 0.00 13093.60 87.94 131.70 440.82 0.00 440.82 3.36 100.00 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 0.00 0.00 301.00 0.00 13225.60 87.88 129.36 422.97 0.00 422.97 3.32 99.84
aws上的IO characteristics表示每个IOPS接受256KiB或更少的请求,因此使用较小的数据块写回的postgres会产生更多的IOPS请求吗?
虽然我有另一个100GB卷的ec2实例(Say S2)(现在95%已满),postgres数据在根卷上并且表现很好.所以体积的大小是我确定无关紧要的.
S1的受影响的数量只存储postgres数据仍然可以通过iostat看到下面的统计数据.不确定为什么统计数据是这样的,如何在不增加音量大小的情况下减少postgres命令的时间. (虽然所有操作3GB内存总是免费的)
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.34 2.29 1.23 298.93 20.10 13079.03 87.28 26.19 87.26 66.96 87.34 3.29 98.78 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 2.40 0.60 299.00 4.80 13020.80 86.95 132.22 434.48 108.00 435.14 3.34 100.00 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 3.20 4.40 295.20 43.20 12866.40 86.18 122.18 417.09 142.00 421.20 3.34 100.00 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 2.80 2.40 297.20 23.20 12940.00 86.54 122.70 401.11 124.00 403.34 3.34 99.92 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util xvdf 0.00 3.40 4.80 294.80 46.40 12840.00 86.02 127.43 433.15 161.67 437.57 3.34 99.92
注意:受影响的postgres卷包含100个不同的postgres db,平均大小为110 MB / db(但老实说,我认为这无论如何都不是问题)
解决方法
Postgres文件说
The statistics collector transmits the collected @R_266_4045@ion to
backends (including autovacuum) through temporary files. These files
are stored in the 07001 subdirectory. When the postmaster shuts
down,a permanent copy of the statistics data is stored in the global
subdirectory. For increased performance,the parameter
stats_temp_directory can be pointed at a RAM-based file system,
decreasing physical I/O requirements.
我通过在tmpfs文件系统中挂载pg_stats_tmp将pg_stats_tmp文件指向ram而不是磁盘.这个blog解释了如何一步一步地做到这一点.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。