From: Julien Rouhaud <rjuju123@gmail.com>
To: Atul Kumar <akumar14871@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: clear cache in postgresql
Date: Wed, 16 Jun 2021 14:39:19 +0800
Message-ID: <20210616063919.hrysiixqgr2wcyrx@nol> (raw)
In-Reply-To: <CA+ONtZ75zZv+7ThMdiyFVAa7ZXBSv6NLAGgLqmzbrrjMU3Os8g@mail.gmail.com>
References: <CA+ONtZ75zZv+7ThMdiyFVAa7ZXBSv6NLAGgLqmzbrrjMU3Os8g@mail.gmail.com>
On Wed, Jun 16, 2021 at 12:02:52PM +0530, Atul Kumar wrote:
>
> 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?
You can use pgbuffercache for that:
https://www.postgresql.org/docs/current/pgbuffercache.html> Can I force all caches to be cleared for tuning purposes?
> So I need to clear the cache without restarting/rebooting the postgres
> server to check the correct execution plan of my query.
No, cleaning postgres cache can only be done with a service restart. That
being said, tuning shouldn't be done assuming that there's no cache. On the
opposite maybe what you should do is use pg_prewarm
(https://www.postgresql.org/docs/current/pgprewarm.html) to make sure that your
cache isn't empty after a restart.
Note that you also have the operating system cache. It can be cleared without
restarting the OS, but I have no idea if this is possible with RDS.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: rjuju123@gmail.com, akumar14871@gmail.com
Subject: Re: clear cache in postgresql
In-Reply-To: <20210616063919.hrysiixqgr2wcyrx@nol>
References: <CA+ONtZ75zZv+7ThMdiyFVAa7ZXBSv6NLAGgLqmzbrrjMU3Os8g@mail.gmail.com> <20210616063919.hrysiixqgr2wcyrx@nol>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox