是否查看并清除Postgres缓存/缓冲区? [英] See and clear Postgres caches/buffers?

查看:201
本文介绍了是否查看并清除Postgres缓存/缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我运行一个Postgres查询需要30秒.然后,我立即运行相同的查询,这需要2秒钟.看来Postgres具有某种缓存.我可以以某种方式查看该缓存保存了什么吗?我可以强制出于清理目的清除所有缓存吗?

Sometimes I run a Postgres query it takes 30 seconds. Then, I immediately run the same query and it takes 2 seconds. It appears that Postgres has some sort of caching. Can I somehow see what that cache is holding? Can I force all caches to be cleared for tuning purposes?

注意:我基本上是在寻找以下SQL Server命令的postgres版本:

Note: I'm basically looking for a postgres version of the following SQL Server command:


DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS

但是我也想知道如何查看该缓冲区中实际包含的内容.

But I would also like to know how to see what is actually contained in that buffer.

感谢您的帮助.

推荐答案

您可以使用pg_buffercache模块查看PostgreSQL缓冲区高速缓存中的内容.我已经做了一个名为"在PostgreSQL缓冲区高速缓存内的演示,它解释了什么您会看到,而我展示了一些更复杂的查询,以帮助解释随之而来的信息.

You can see what's in the PostgreSQL buffer cache using the pg_buffercache module. I've done a presentation called "Inside the PostgreSQL Buffer Cache" that explains what you're seeing, and I show some more complicated queries to help interpret that information that go along with that.

在某些系统上也可以查看操作系统缓存,请参见

It's also possible to look at the operating system cache too on some systems, see pg_osmem.py for one somewhat rough example.

无法轻松清除缓存.在Linux上,您可以停止数据库服务器并使用 drop_caches 工具清除OS缓存;请务必留意那里的警告,以便先运行同步.

There's no way to clear the caches easily. On Linux you can stop the database server and use the drop_caches facility to clear the OS cache; be sure to heed the warning there to run sync first.

这篇关于是否查看并清除Postgres缓存/缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆