I need to clear system cache in order to record the time taken by a postgres query in cold cache. For clearing the system cache I am executing the following commands as root on Ubuntu server 12.04:
sync; echo 1 > /proc/sys/vm/drop_caches
sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches
I am running the following SQL commands along with clearing caches:
1. select col1 from my_table; //Time Taken= 3000 ms
2. sync; echo 1 > /proc/sys/vm/drop_caches
sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches
3. Now again running the same select command and clearing caches:
select col1 from my_table; //Time Taken= 200 ms
4. sync; echo 1 > /proc/sys/vm/drop_caches
sync; echo 2 > /proc/sys/vm/drop_caches
sync; echo 3 > /proc/sys/vm/drop_caches
5. Now again running the same select command and clearing caches:
select col1 from my_table; //Time Taken= 10 ms
From what I can interpret from the reduced query execution time is, even after clearing the caches, in effect caches are not getting cleared. Is my interpretation correct? Is there some other way of clearing caches in Ubuntu 12.04 server?