[英]Throttling i/o in postgres's pg_dump?
所以我们在一台16GB内存的机器上有一个32GB的生产数据库。 由于缓存,这通常不是问题。 但每当我启动数据库的pg_dump时,来自应用程序服务器的查询就会开始排队,几分钟后队列就会运行,我们的应用程序就会停止运行。
我将是第一个承认我们有查询性能问题的人,我们正在解决这些问题。 同时,我希望能够以一种从数据库中啜饮的方式每晚运行pg_dump并且不会关闭我们的应用程序。 我不在乎是否需要数小时。 我们的应用程序没有运行任何DDL,所以我不担心锁争用。
尝试解决问题,我正在使用nice和ionice运行pg_dump。 不幸的是,这并没有解决这个问题。
nice ionice -c2 -n7 pg_dump -Fc production_db -f production_db.sql
即使使用ionice,我仍然会看到上面的问题。 似乎I / O等待和许多寻求导致问题。
vmstat 1
告诉我,爱荷华州有时徘徊在20-25%左右,飙升至40%。 实际CPU%有时会在2-5%之间波动,达到70%。
我不认为锁是可能的罪魁祸首。 当我运行此查询时:
select pg_class.relname,pg_locks.* from pg_class,pg_locks where pg_class.relfilenode=pg_locks.relation;
我只看到被标记为grant ='t'的锁。 我们通常不会在生产中运行任何DDL - 因此锁定似乎不是问题。
这是ps的输出,启用了WCHAN列:
PID WIDE S TTY TIME COMMAND
3901 sync_page D ? 00:00:50 postgres: [local] COPY
3916 - S ? 00:00:01 postgres: SELECT
3918 sync_page D ? 00:00:07 postgres: INSERT
3919 semtimedop S ? 00:00:04 postgres: SELECT
3922 - S ? 00:00:01 postgres: SELECT
3923 - S ? 00:00:01 postgres: SELECT
3924 - S ? 00:00:00 postgres: SELECT
3927 - S ? 00:00:06 postgres: SELECT
3928 - S ? 00:00:06 postgres: SELECT
3929 - S ? 00:00:00 postgres: SELECT
3930 - S ? 00:00:00 postgres: SELECT
3931 - S ? 00:00:00 postgres: SELECT
3933 - S ? 00:00:00 postgres: SELECT
3934 - S ? 00:00:02 postgres: SELECT
3935 semtimedop S ? 00:00:13 postgres: UPDATE waiting
3936 - R ? 00:00:12 postgres: SELECT
3937 - S ? 00:00:01 postgres: SELECT
3938 sync_page D ? 00:00:07 postgres: SELECT
3940 - S ? 00:00:07 postgres: SELECT
3943 semtimedop S ? 00:00:04 postgres: UPDATE waiting
3944 - S ? 00:00:05 postgres: SELECT
3948 sync_page D ? 00:00:05 postgres: SELECT
3950 sync_page D ? 00:00:03 postgres: SELECT
3952 sync_page D ? 00:00:15 postgres: SELECT
3964 log_wait_commit D ? 00:00:04 postgres: COMMIT
3965 - S ? 00:00:03 postgres: SELECT
3966 - S ? 00:00:02 postgres: SELECT
3967 sync_page D ? 00:00:01 postgres: SELECT
3970 - S ? 00:00:00 postgres: SELECT
3971 - S ? 00:00:01 postgres: SELECT
3974 sync_page D ? 00:00:00 postgres: SELECT
3975 - S ? 00:00:00 postgres: UPDATE
3977 - S ? 00:00:00 postgres: INSERT
3978 semtimedop S ? 00:00:00 postgres: UPDATE waiting
3981 semtimedop S ? 00:00:01 postgres: SELECT
3982 - S ? 00:00:00 postgres: SELECT
3983 semtimedop S ? 00:00:02 postgres: UPDATE waiting
3984 - S ? 00:00:04 postgres: SELECT
3986 sync_buffer D ? 00:00:00 postgres: SELECT
3988 - R ? 00:00:01 postgres: SELECT
3989 - S ? 00:00:00 postgres: SELECT
3990 - R ? 00:00:00 postgres: SELECT
3992 - R ? 00:00:01 postgres: SELECT
3993 sync_page D ? 00:00:01 postgres: SELECT
3994 sync_page D ? 00:00:00 postgres: SELECT
\n psql -c'pg_start_backup()'\n rsync --checksum --archive / var / lib / pgsql / backups / pgsql\n psql -c'pg_stop_backup()'\n但请注意,您还需要为此设置连续归档 ,并且在备份期间创建的所有WAL文件都会在数据文件备份中隐藏。
你的PS输出有多个处于“等待”状态的UPDATE语句,它仍然对我说锁(你的锁测试查询除外)。 我很确定你不会在PS输出中看到“等待”。 您可以检查此查询是否在问题期间显示任何内容:
SELECT * FROM pg_stat_activity WHERE waiting;
(你没有说你正在运行什么版本的PostgreSQL,所以我不确定这是否有用。)
如果那里有任何东西(也就是wait = TRUE),那么它就是锁定/交易问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.