Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL_NO_CACHE for Postgresql?

Is there a postgresql equivalent for the MySQL keyword SQL_NO_CACHE (or the SQL Server dbcc drop clean buffers) i.e. which you can simply include in a SQL statement or as part of a script?

UPDATE: this question

See and clear Postgres caches/buffers?

seems to say that the answer is "no", although it is now two years old. Are there any relevant changes in postgresql 9.0?

like image 714
davek Avatar asked May 26 '11 18:05

davek


People also ask

Does PostgreSQL cache queries?

PostgreSQL caches the following for accelerating data access: Data in tables. Indexes. Query execution plans.

What is discard all in PostgreSQL?

The DISCARD ALL statement discards the session state. It discards all temporary tables, plans, and sequences, along with any session-specific configurations. This statement is often used by connection poolers before reusing the connection for the next client.


2 Answers

The two things you've stated are not at all equivalent.

MySQL's SQL_NO_CACHE does NOT stop the engine from using cached data. It means that the query is not cached in the MySQL query cache.

The query cache is not the same as any disc cache the engine might have because it caches the results of queries, not blocks from the disc (or rows from a table etc). So it caches the results of a text statement.

The reason for using SQL_NO_CACHE is that you know you're going to be doing an infrequently-used query which returns a lot of data (hence would take up a lot of space in the cache).

But most MySQL installations are now advised to turn the query cache off to make more memory for page caches etc (see http://dom.as/tech/query-cache-tuner/ )

like image 176
MarkR Avatar answered Sep 20 '22 13:09

MarkR


No need for, cache in PostgreSQL works very different and is 100% reliable.

like image 43
Frank Heikens Avatar answered Sep 18 '22 13:09

Frank Heikens