Community Health Toolkit

What is the scope of couch2pg?

When I’ve created matviews in in the public schema for a project, they have been automatically added to the refreshes triggered by couch2pg.

Does this apply to all matviews in a database? Is the scope of what couch2pg updates configured on a project-by-project basis? If so, where would I find that configuration?

If I want to create a matview that is expensive to refresh but only needs to be refreshed every few days, is there a way to do that?

1 Like

To refresh matviews, medic-couch2pg executes a function called refresh_matviews() which is defined here. It basically refreshes every matview that is returned by this query: SELECT matviewname FROM pg_catalog.pg_matviews and I believe pg_matviews includes matviews from all schemas.

If your view needs to be a matview, you could add logic to refresh_matviews() to skip that matview entirely, only refresh it on Sundays (for example), or have the function only refresh matviews in the public schema… and then have a cron job refresh the other one on a different schedule.

Alternatively, you could set up a cron job to call a function that does a SELECT INTO.... (for example). That way you wouldn’t have to mess with refresh_matviews().

3 Likes