{"id":19059942,"url":"https://github.com/q-m/metabase-matview","last_synced_at":"2026-05-12T20:30:16.362Z","repository":{"id":146167271,"uuid":"405034420","full_name":"q-m/metabase-matview","owner":"q-m","description":"Basic webapp to materialize questions in Metabase","archived":false,"fork":false,"pushed_at":"2022-06-02T13:39:16.000Z","size":139,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T12:24:14.016Z","etag":null,"topics":["materialized-view","materialized-views","metabase","sql","webapp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/q-m.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-10T09:58:12.000Z","updated_at":"2023-10-10T20:32:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9064199-0c2f-473b-8f54-31d4845bffe7","html_url":"https://github.com/q-m/metabase-matview","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fmetabase-matview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fmetabase-matview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fmetabase-matview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/q-m%2Fmetabase-matview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/q-m","download_url":"https://codeload.github.com/q-m/metabase-matview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240114326,"owners_count":19749837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["materialized-view","materialized-views","metabase","sql","webapp"],"created_at":"2024-11-09T00:12:15.015Z","updated_at":"2026-05-12T20:30:16.296Z","avatar_url":"https://github.com/q-m.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Metabase matview\n\n[Metabase](https://www.metabase.com/) is a tool to query and visualise data in databases.\nThis tool allows 'converting' a Metabase question to a materialized view, so that questions\nthat take a long time to run can be cached, also when used [in another question](https://www.metabase.com/docs/latest/users-guide/referencing-saved-questions-in-queries.html).\n\nUltimately this may be [solved within Metabase](https://github.com/metabase/metabase/issues/5596),\nin the meantime this tool hopes to provide a workaround.\n\n![screenshot of app](screenshot-1.png)\n![screenshot of materialized Metabase question](screenshot-2.png)\n\n## Install\n\nDeployment can be done in several ways, depending on your needs. This section describes\nhow to put Metabase and this application on the same host, so that the Metabase session\ncookie can be used for authentication. It assumes that Metabase is\n[running as a service on Debian/Ubuntu](https://www.metabase.com/docs/latest/operations-guide/running-metabase-on-debian.html)\nwith nginx as a reverse proxy.\n\n### Dependencies\n\nMake sure you have Python 3. Then you need to install the dependencies. It's best to\ninstall dependencies using the package manager, so do that when possible (assuming\nDebian/Ubuntu here):\n\n```sh\napt install python3 python3-pip python3-requests python3-psycopg2\n```\n\nSome packages may not have up-to-date versions in the system repositories, install\nadditional dependencies from the [`requirements.txt`](requirements.txt) file:\n\n```sh\npip3 install -r requirements.txt\n```\n\n### Flask App\n\nFirst this app needs to be installed as a service on the same host as Metabase. There\nare [different options](https://flask.palletsprojects.com/en/2.0.x/deploying/),\nwe'll use [gunicorn](https://gunicorn.org/). First install this app and gunicorn:\n\n```sh\napt install gunicorn3\nuseradd -m -s /usr/sbin/nologin gunicorn\ngit clone https://github.com/q-m/metabase-matview.git /home/gunicorn/metabase-matview\n```\n\nThen create a systemd service to have it running always, as [described here](https://docs.gunicorn.org/en/stable/deploy.html#systemd).\n\nCreate `/etc/systemd/system/gunicorn.service` (note that we assume 19.x here, which\nis currently on Debian - see the link above if you have a later version):\n\n```systemd\n[Unit]\nDescription=gunicorn daemon\nRequires=gunicorn.socket\nAfter=network.target\n\n[Service]\nPIDFile=/run/gunicorn/gunicorn.pid\nUser=gunicorn\nGroup=gunicorn\nRuntimeDirectory=gunicorn\nWorkingDirectory=/home/gunicorn/metabase-matview\nEnvironmentFile=/etc/default/gunicorn\nExecStart=/usr/bin/gunicorn3 -p /run/gunicorn/gunicorn.pid -t 300 -w 3 server:app\nExecReload=/bin/kill -s HUP $MAINPID\nExecStop=/bin/kill -s TERM $MAINPID\nPrivateTmp=true\n\n[Install]\nWantedBy=multi-user.target\n```\n\nCreate `/etc/systemd/system/gunicorn.socket`:\n\n```systemd\n[Unit]\nDescription=gunicorn socket\n\n[Socket]\nListenStream=/run/gunicorn.sock\n# socket needs to be accessible by nginx (systemd passes it to gunicorn)\nSocketUser=www-data\nSocketMode=600\n\n[Install]\nWantedBy=sockets.target\n```\n\nFinally create a file with configuration variables in `/etc/default/gunicorn`:\n\n```sh\nWEB_PATH=/matview/\n# Adapt METABASE_URL to your own situation.\nMETABASE_URL=https://metabase.example.com/\n\n# For each database in Metabase, add a DATABASE_URL_x here, where x is the\n# database id in Metabase (hover over the database name in databases admin).\nDATABASE_URL_1=postgresql://user:pass@host/db\nDATABASE_URL_2=postgresql://user:pass@host/db\n```\n\nFix permissions (it contains secrets):\n\n```sh\nchown root:gunicorn /etc/default/gunicorn\nchmod 0640 /etc/default/gunicorn\n```\n\nThen start it:\n\n```sh\nsystemctl enable --now gunicorn.socket\n```\n\n### nginx\n\nThen in your `server` section in `/etc/nginx/sites-enabled/default` (or perhaps `/etc/nginx/nginx.conf`).\n\n```nginx\nserver {\n  # ...\n\n  # add this location\n  location /matview {\n    proxy_pass http://unix://run/gunicorn.sock\n    proxy_redirect off;\n  }\n\n  # you should already have something like this for Metabase\n  location / {\n    proxy_pass http://localhost:3000/;\n    proxy_redirect off;\n  }\n}\n```\n\n## Use\n\nMake sure you are logged into Metabase.\nThen visit https://metabase.example.com/matview (with the proper domain name you're using).\nClick _Add question_ and enter a question ID to materialize.\nDon't forget to _Refresh_ when you need updated data.\n\n## Current limitations\n\n- Only native SQL queries are supported.\n- Questions with filters don't work.\n- Materializing a question that references another questions works, but you can't refresh a\n  materialized question that another materialized question depends on.\n- When an error occurs, you'll notice the action hasn't been done, but no message is shown.\n- Need to refresh manually.\n\n## License\n\nThis project is licensed under the [GPL v3 or later](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fq-m%2Fmetabase-matview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fq-m%2Fmetabase-matview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fq-m%2Fmetabase-matview/lists"}