Skip to main content

Django postgres refresh materialized views

Project description

Installation

$ [sudo] pip install django-postgres-refresh-matviews

How it works

  1. refresh_pg_matviews - refresh all pg_matviews matviews
  2. refresh_pending_matviews - refresh Matview model matviews:
    • repeat_seconds - seconds interval to refresh matview
    • is_pending - set True to force refresh
settings.py
INSTALLED_APPS+=['django_postgres_refresh_matviews']
migrate
$ python manage.py migrate

Examples

from django_postgres_refresh_matviews.utils import refresh_pg_matviews

refresh_pg_matviews()
from django_postgres_refresh_matviews.models import Matview
from django_postgres_refresh_matviews.utils import refresh_pending_matviews

Matview.objects.get_or_create(schemaname='public',matviewname='matview1')

refresh_pending_matviews()

Matview.objects.filter(schemaname='public').update(is_pending=False)

Log

from django_postgres_refresh_matviews.models import Log

for l in Log.objects.filter(schemaname='public',matviewname='matview1'):
    l.started_at, l.completed_at

cli

$ python manage.py clear_matviews   # clear matviews
$ python manage.py init_matviews    # init postgres matviews
$ python manage.py refresh_pg_matviews # refresh pg_matviews
$ python manage.py refresh_pending_matviews # refresh pending Matview matviews

raw sql

INSERT INTO refresh_matview(schemaname,matviewname)
SELECT schemaname,matviewname
FROM pg_matviews
ON CONFLICT (schemaname,matviewname) DO NOTHING;

UPDATE refresh_matview SET is_pending=true
WHERE schemaname='public' AND matviewname='matview1';

readme42.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page