Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark view refreshes #104 #105

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- a function to refresh all materialized views
CREATE OR REPLACE FUNCTION refresh_matviews() RETURNS INTEGER AS $$
DECLARE
matview RECORD;
start_time TIMESTAMPTZ;
BEGIN
RAISE NOTICE 'Refreshing base metaviews';
-- other matviews rely on contactview_metadata, which is a matview
-- so load this first
REFRESH MATERIALIZED VIEW CONCURRENTLY contactview_metadata;
FOR matview IN SELECT matviewname FROM pg_catalog.pg_matviews LOOP
IF matview.matviewname = 'contactview_metadata' THEN
-- this one is already done, skip it.
CONTINUE;
END IF;
RAISE NOTICE 'Refreshing %', matview.matviewname;
start_time := clock_timestamp();
EXECUTE format('REFRESH MATERIALIZED VIEW CONCURRENTLY %I', matview.matviewname);
RAISE INFO 'Finished refreshing % took %', matview.matviewname, clock_timestamp() - start_time;
END LOOP;
RAISE NOTICE 'Materialized views refreshed.';
RETURN 1;
END;
$$ LANGUAGE plpgsql;