Is there a way to turn-off page caching for reads in Linux? More specifically, I would like my processes to read directly from the disk.

The setting of my problem: I am trying out new query processing techniques in Postgres and measuring their running time. To have an accurate comparison of the running time of different methods, I need to turn-off reading from OS cache.

I have read the following approaches but none of them apply to my case:

  1. Clear the cache using echo 1 > /proc/sys/vm/drop_caches: I need to call this at every iteration of my query which would mess up my final measured times.
  2. Use O_DIRECT within the program: I have no control on how Postgres reads the files
  3. Mount my device using -o sync. I read here that it will turn off the write buffering but I am not sure if it disable reading from the cache as well?
  4. Use hdparm -W 0 /dev/sda1: Again, this only disable the cache for writes.
  5. Use an application specific script explained here: This would work if I had a single application, but in my setting, I have a Postgres server as a service (with many threads) and a client. I am not 100% sure but it seems like the script works for regular applications not the services such as Postgres.


You must log in to answer this question.

Browse other questions tagged .