Skip to content

layers_clearCache control ​

pgRDF keeps two caches:

CacheWhere it livesWhat it holds
Shared term cacheShared memory, one per server (needs shared_preload_libraries)Recently used RDF terms and their dictionary ids, so loading doesn't look every term up in the dictionary table
Plan cacheEach connectionThe SQL translation of SPARQL queries that connection has run

Neither needs routine maintenance. Loading, updating, clearing and dropping graphs keep both caches correct. You don't clear anything after changing data.

After re-creating the extension ​

There is one case that needs action. If you drop and re-create the extension while the server keeps running (for example, resetting a test database), invalidate the shared term cache straight after CREATE EXTENSION:

sql
DROP EXTENSION pgrdf CASCADE;
CREATE EXTENSION pgrdf;
SELECT pgrdf.shmem_reset();

shmem_reset() returns nothing and affects the whole server. The cache refills as data is loaded. The cumulative counters in pgrdf.stats() keep their totals. A server restart also starts with an empty cache.

Warming the cache after a restart ​

After a restart the shared term cache is empty, so the first large load does more dictionary lookups. To fill the cache from the dictionary before the first load, turn on:

sql
SET pgrdf.shmem_prewarm_on_init = on;   -- default off

See Settings for every setting.

Diagnostic functions ​

pgrdf.surface() lists the stability class of each function. Two cache functions are internal: diagnostics, not part of any workflow, and subject to change.

sql
SELECT name, class FROM pgrdf.surface()
 WHERE name IN ('shmem_reset', 'shmem_cache_prewarm', 'plan_cache_clear')
 ORDER BY name;
        name         |  class
---------------------+----------
 plan_cache_clear    | internal
 shmem_cache_prewarm | internal
 shmem_reset         | stable
  • plan_cache_clear() drops the calling connection's plan cache and returns how many plans it held. Closing the connection has the same effect.
  • shmem_cache_prewarm(limit) loads up to limit terms into the shared term cache; the pgrdf.shmem_prewarm_on_init setting above is the supported way to warm it.

See also ​

pgRDF is released under the MIT license. Documentation built with VitePress, served via GitHub Pages.