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

File details

Details for the file django-postgres-refresh-matviews-2020.12.5.tar.gz.

File metadata

  • Download URL: django-postgres-refresh-matviews-2020.12.5.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for django-postgres-refresh-matviews-2020.12.5.tar.gz
Algorithm Hash digest
SHA256 05ae2967884501d128516cb5e8bca550b55bf44c453ebfd521fa2dccf3f33e4b
MD5 ab0a4c3b9d49ed9306c54effd0019503
BLAKE2b-256 628a860b2df9ab1445e80b4bfeb52b43be5f25dbab9b4a7bc5b400488e42180d

See more details on using hashes here.

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