Search code examples
postgresqlpostgresql-9.5

Postgres pg_prewarm to keep table in buffer gives 0 after dropping table


I followed the steps as outlined in this tutorial to use pg_prewarm extention for pre-warming the buffer cache in PostgreSQL:

https://ismailyenigul.medium.com/pg-prewarm-extention-to-pre-warming-the-buffer-cache-in-postgresql-7e033b9a386d

The first time I ran it, I got 1 as the result:

mydb=> SELECT pg_prewarm('useraccount');
 pg_prewarm 
------------
          1

After that I had to drop the table and recreate it. Since then, when I run the same command, I get 0 as the result always. I am not sure if that's expected or if I am missing something?

mydb=> SELECT pg_prewarm('useraccount');
 pg_prewarm 
------------
          0

Solution

  • The function comment in contrib/pg_prewarm/pg_prewarm.c says:

     * [...] The
     * return value is the number of blocks successfully prewarmed.
    

    So the first time, there was 1 block in the table. After dropping and re-creating the table, it is empty, so 0 blocks are cached.