PostgreSQL: How to Clear Cache of the Database Sessions

This is one of the important discussion for PostgreSQL Database Administrator.
Yes, it is true that PostgreSQL has a caching system by setting “shared_buffers”.

But I didn’t find any perfect solution to clear the cache of PostgreSQL Server.
If you really want to clear cache, you should restart the PostgreSQL Server.

In this post, I provide you a short note on PostgreSQL Discard functionality to discard temp, query plan for running sessions.

Using DISCARD you can release internal resources of a Database Sessions.

DISCARD TEMP: Using this, you can drop all temporary tables which are created in the current session.

DISCARD PLANS: Using this, you can release all internal cached query plans.

DISCARD ALL: Using this, you can reset a session to its original state. You cannot execute this command inside the transaction block.

Once you have executed DISCARD ALL, internally following sequence executes.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

5 Comments on "PostgreSQL: How to Clear Cache of the Database Sessions"

Notify of

Sort by:   newest | oldest | most voted
8 months 5 days ago

Hi there, I enjoy reading through your article post.
I like to write a little comment to support you.

8 months 2 hours ago

Thank you for sharing excellent informations. Your website is very cool. I’m impressed by the details that you’ve on this site. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found simply the information I already searched all over the place and simply could not come across. What a perfect web-site.

7 months 20 days ago

I appreciate you sharing this blog.Really thank you! Much obliged.

7 months 20 days ago

wow, awesome blog.Really thank you! Will read on…

26 days 46 minutes ago

Just wow !, thank you very much.
You are fantastic man, Please Keep sharing…