What you will set up
Metabase turns the data in your database into answers, charts and dashboards. You build a question by picking a table, a sum and a grouping, without writing SQL, and Metabase draws the chart. Those who know SQL can write it directly. Questions go on dashboards that the whole team can open.
Metabase is developed by Metabase, Inc., a company in San Francisco, in the open on GitHub. The edition here, the open-source edition, is free under the AGPL 3.0 licence. Metabase also sells Pro and Enterprise editions, with features such as single sign-on with SAML and finer permissions, and Metabase Cloud, its hosted service. Out of the box, Metabase sends anonymous usage data to Metabase, checks for new versions with Metabase, and looks up the location of every login with GeoJS, an IP lookup service, by sending the visitor's IP address. Step 4 switches all three off; one page still uses GeoJS, as step 10 explains.
Metabase keeps its own data, such as users, questions and dashboards, in a database of its own. Without settings it uses a file in H2 format, which Metabase advises against for real use, so here it gets PostgreSQL. It reads your business data from your own database, through a login that can only read.
Here Metabase runs as a Compose project under a user of its own called metabase, behind Caddy from the Docker guide, and reads a database on PostgreSQL from the PostgreSQL guide on the same server.
The app-specific results below come from the tested Podman guide on a Melonslab server with Debian 13:
- Metabase 0.64.2.1 started with its own data in PostgreSQL 18, and the admin account was created over an SSH tunnel before Caddy was set up.
- Metabase connected to a shop database on the server's PostgreSQL 18 through the read-only login. A question built without SQL drew revenue per month, a SQL question counted paid orders per city, and both went on a dashboard.
- A
DELETEin a SQL question failed withcannot execute DELETE in a read-only transaction. With the transaction switched to read-write, the login still gotpermission denied for table orders, and a query running longer than 60 seconds was stopped. - A second user, without the right to write SQL, could open the questions, and got an error when they tried SQL against the database.
- Without email set up, adding a user gave a temporary password instead of an invitation. With email set up, invitations and password resets arrived, at a test mail catcher on the server.
- The interface was shown in Swedish.
- Logins were recorded with the visitor's real IPv4 address, and a forged
X-Forwarded-Forheader was ignored. - A capture of the server's traffic showed no connections to Metabase or anyone else while Metabase started, restarted and was used, with one exception, described in step 10.
- An update from Metabase 0.63 to 0.64 kept the questions and dashboards, and the Podman test's
podman auto-updatemoved Metabase from 0.64.1 to 0.64.2.1. Metabase 0.64.2.2 later started on the same settings and read the shop database. Metabase was restored from a backup into an empty volume, and everything came back by itself after a reboot.
In the Podman test, Metabase used about 1.7 GB of memory after the reboot, nearly all of it Java, and its own PostgreSQL about 30 MB. Java lets Metabase use up to a quarter of the server's memory, 2 GB on this server, so a 4 GB server is the smallest we would run it on together with PostgreSQL.
The Docker version below follows the tested rootless Docker base guide. The app-specific results above come from the tested Podman guide on a Melonslab server; they were not measured under Docker.
Before you start
You need:
- a server set up as in the Docker guide, with Caddy running;
- PostgreSQL on the same server, as in the PostgreSQL guide, with the database you want to look at;
- an A record and an AAAA record for
metabase.example.compointing at your server; - SSH access to the server from your own computer.
The examples use metabase.example.com for Metabase, 203.0.113.10 for your server's IPv4 address, and appdb and appuser for the database and the app login from the PostgreSQL guide. Replace them throughout.
1. Create a read-only login
Metabase only needs to read your data. Give it a login of its own that cannot change anything, so that a mistake in a SQL question, or someone who gets into Metabase, cannot delete or change your data. As root, create the login with a long password, which createuser asks for twice:
openssl rand -base64 24
sudo -u postgres createuser --pwprompt metabase_ro
Then let it read the tables in appdb:
sudo -u postgres psql -d appdb <<'EOF'
ALTER ROLE metabase_ro SET default_transaction_read_only = on;
ALTER ROLE metabase_ro SET statement_timeout = '60s';
GRANT CONNECT ON DATABASE appdb TO metabase_ro;
GRANT USAGE ON SCHEMA public TO metabase_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO metabase_ro;
ALTER DEFAULT PRIVILEGES FOR ROLE appuser IN SCHEMA public GRANT SELECT ON TABLES TO metabase_ro;
EOF
What the lines do:
GRANT SELECTlets the login read the tables that exist now, and nothing else. It cannot insert, change or delete rows, or create tables.ALTER DEFAULT PRIVILEGESgives it the same right to the tables thatappuser, the app's own login, creates later, such as after an update of the app.default_transaction_read_onlymakes every transaction read-only as well, a second lock on top of the grants.statement_timeoutstops any query from Metabase after 60 seconds, so a heavy question cannot keep your app's database busy.
Keep the password for step 7. If your tables are in another schema than public, repeat the last three lines for it.
2. Create the user
As root:
useradd -m -s /bin/bash metabase
loginctl enable-linger metabase
uid=$(id -u metabase)
Everything up to step 6 runs as metabase.
3. Create the secrets
The passwords are generated with the Compose file in the next step and kept in a 0600 file under the app directory.
The 0600 file holds the password of Metabase's own database and the key Metabase encrypts the connection details of your databases with, such as the password of metabase_ro, before it stores them. Without the key, those details in a backup cannot be read, and you have to enter them again, so step 12 saves a copy.
4. Define the Compose project
Create a Compose file in the app's directory. It uses the same images, ports, volumes, environment and restart policy as the Podman guide:
mkdir -p /home/metabase/metabase
cat > /home/metabase/metabase/compose.yaml <<'YAML'
services:
db:
image: docker.io/library/postgres:18-alpine
volumes:
- db:/var/lib/postgresql
environment:
POSTGRES_USER: metabase
POSTGRES_DB: metabase
env_file: metabase.env
healthcheck:
test: ["CMD", "pg_isready", "-U", "metabase", "-d", "metabase"]
interval: 10s
restart: always
app:
image: docker.io/metabase/metabase:v0.64.x
ports:
- "127.0.0.1:8131:3000"
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
MB_SITE_URL: https://metabase.example.com
MB_DB_TYPE: postgres
MB_DB_HOST: 127.0.0.1
MB_DB_PORT: "5432"
MB_DB_DBNAME: metabase
MB_DB_USER: metabase
MB_ANON_TRACKING_ENABLED: "false"
MB_CHECK_FOR_UPDATES: "false"
MB_SEND_EMAIL_ON_FIRST_LOGIN_FROM_NEW_DEVICE: "false"
JAVA_TIMEZONE: Europe/Stockholm
env_file: metabase.env
restart: always
volumes:
db:
YAML
umask 077
dbpw=$(openssl rand -hex 24)
printf 'POSTGRES_PASSWORD=%s\nMB_DB_PASS=%s\nMB_ENCRYPTION_SECRET_KEY=%s\n' "$dbpw" "$dbpw" "$(openssl rand -hex 32 | tr -d '\n')" > /home/metabase/metabase/metabase.env
unset dbpw
chmod 600 /home/metabase/metabase/metabase.env
chown -R metabase:metabase /home/metabase/metabase
uid=$(id -u metabase)
runuser -u metabase -- env HOME=/home/metabase XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/metabase/metabase && docker compose up -d"
Use the weekly docker-update.service/docker-update.timer from the rootless Docker guide instead of Podman's auto-update timer. It runs docker compose pull and docker compose up -d in the app directory each Sunday. Set it up once for metabase as shown there; it covers every Compose app in that user's home.
The first start downloads about 1.4 GB of images, and Metabase takes a minute or two to set up its database. Leave room for about 2.1 GB in all: at every start, Metabase's container also writes a 0.7 GB copy of its program file. It is ready when this prints {"status":"ok"}:
curl -s http://127.0.0.1:8131/api/health
5. Create the admin account over an SSH tunnel
Until an admin account exists, whoever opens Metabase first can create it and see all your data. Caddy does not show Metabase to anyone yet, so create the account through an SSH tunnel, which only you have.
On your own computer, open a tunnel to Metabase's port on the server, and keep it open:
ssh -L 8131:127.0.0.1:8131 root@203.0.113.10
Open http://localhost:8131 in your browser. It shows Welcome to Metabase. Choose Let's get started, and fill in First name, Last name, Email, Company or team name, and a password under Create a password and Confirm your password. Next creates the account straight away, so the rest of the questions are up to you:
- Under What will you use Metabase for?, choose Self-service analytics for my own company and Next.
- Under Add your data, choose Continue with sample data. You add your own database in step 7, once Metabase has its address.
- Under Usage data preferences, switch off Allow Metabase to anonymously collect usage events, and choose Finish. The switch starts out on, but
MB_ANON_TRACKING_ENABLED=falsefrom step 4 keeps the collection off either way.
Close the tunnel when you are done.
6. Put Caddy in front
Go back to root with exit, switch to runuser -u caddy -- /bin/bash, and add this block at the end of ~/Caddyfile:
metabase.example.com {
reverse_proxy 127.0.0.1:8131
}
Restart Caddy with runuser -u caddy -- env HOME=/home/caddy XDG_RUNTIME_DIR=/run/user/$(id -u caddy) DOCKER_HOST=unix:///run/user/$(id -u caddy)/docker.sock PATH=/usr/bin:/bin bash -lc 'cd /home/caddy/caddy && docker compose restart caddy', and log in at https://metabase.example.com.
7. Connect your database
Open the menu at the top right, the square of dots, and choose Admin, then Databases > Add database. Database type is already PostgreSQL. Fill in:
- Display name: the name your team sees, such as
Shop; - Host:
host.docker.internal, the server's own127.0.0.1as seen from the pod (step 4); - Port:
5432; - Database name:
appdb; - Username:
metabase_ro, and its Password from step 1.
Choose Save. Metabase connects, reads which tables and columns there are, and shows Syncing completed. It reads them again every hour by default, so new tables show up by themselves. Metabase stores the password encrypted with the key from step 3.
Leave Model actions off. Actions let users change data through Metabase, which needs a login that can write.
Choose who may write SQL. By default, everyone in Metabase may write SQL against every database you add. They still only read what metabase_ro may read, but a SQL question can read every column of every table, including ones you would leave out of a dashboard, such as email addresses. To keep SQL to admins, open Permissions, choose the database, set All Users to Query builder only under Create queries, choose Save changes and confirm with Yes. Others can then build questions with the query builder and open saved questions. In our test, a SQL query from such a user was refused.
8. Questions and dashboards
A question is a query with its chart. To build one without SQL, choose New at the top right, then Question, your database and a table, such as Orders:
- Under Summarize, choose Pick a function or metric, then Sum of ... and a column, such as
Total. - Next to by, choose Pick a column to group by and a date, such as
Created At. Metabase groups it by week; choose by week next to the column and then Month to change it. - Choose Visualize. Metabase shows a line chart, and you can switch to another chart under Visualization.
Choose Save, give it a name, such as Revenue per month, and Save again.
For SQL, choose New > SQL query, pick the database at the top, write the query, and run it with Ctrl+Enter:
SELECT c.city, count(*) AS orders
FROM orders o JOIN customers c ON c.id = o.customer_id
WHERE o.status = 'paid'
GROUP BY c.city ORDER BY orders DESC
Save it the same way. A query that tries to change data gets an error from PostgreSQL, such as ERROR: cannot execute DELETE in a read-only transaction.
To gather questions in one place, choose New > Dashboard, give it a name and choose Create. Choose Add a chart, then each saved question, arrange the cards, and choose Save. A dashboard runs its questions every time someone opens it.
Metabase also offers ready-made overviews of a table, which it calls X-rays, on the home page. Its AI features, such as AI exploration and Metabot, need an account with an AI provider that you connect under Admin > AI; until you do, they do nothing. We did not test them.
9. Use Metabase in Swedish
Metabase is translated into Swedish. To make Swedish the default for everyone, choose Admin > Settings > Localization, and under Instance language choose Swedish. It takes effect straight away. Each user can choose their own under Language in their account settings, which open from their name in the same menu at the top right.
The names of your tables, columns and questions are not translated. Dates follow the language, while numbers keep a comma as the thousands separator until you change Separator style under Localization.
10. People
Choose Admin > People > Invite someone, fill in First name, Last name and Email, and choose Create. Without email (step 11), Metabase shows "We couldn’t send them an email invitation" with a temporary password. Pass it on to the person, who should change it after logging in.
New users join the All Users group, which may view everything in Our analytics, and use the databases as set under Permissions (step 7). Make someone an admin by adding them to Administrators.
Metabase records every login with the visitor's address, which each user sees under Login History in their account settings. Opening that page sends the listed addresses to GeoJS to look up a place for each one: this was the only outside connection in our capture. Single sign-on with Google or LDAP is under Admin > Settings > Authentication; SAML and JWT need a paid edition. We did not test them.
11. Email
Metabase sends email for invitations, password resets, dashboard subscriptions and alerts on questions. This guide does not set up email, and without it:
- an invited user gets a temporary password on your screen instead of an email, as in step 10;
- I seem to have forgotten my password on the login page says "Please contact an administrator to have them reset your password.", and an admin resets it under Admin > People;
- subscriptions and alerts cannot be set up.
Logins with a password work as usual.
To send email, point Metabase at your email provider's SMTP server. As metabase, store the SMTP password as a secret:
The passwords are generated with the Compose file in the next step and kept in a 0600 file under the app directory.
Then add MB_EMAIL_SMTP_PASSWORD=<the-smtp-password> to metabase.env, and these entries under app.environment in compose.yaml, with your own server, account and sender address:
MB_EMAIL_SMTP_HOST: smtp.example.com
MB_EMAIL_SMTP_PORT: "587"
MB_EMAIL_SMTP_SECURITY: starttls
MB_EMAIL_SMTP_USERNAME: metabase@example.com
MB_EMAIL_FROM_ADDRESS: metabase@example.com
MB_EMAIL_FROM_NAME: Metabase
uid=$(id -u metabase)
runuser -u metabase -- env HOME=/home/metabase XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/metabase/metabase && docker compose up -d --force-recreate app"
Port 587 uses STARTTLS; for port 465, which uses TLS from the start, set MB_EMAIL_SMTP_PORT=465 and MB_EMAIL_SMTP_SECURITY=ssl. Admin > Settings > Email then shows the settings as set by environment variables, and Send test email checks them. We tested these lines against a mail catcher on the server, not against a real provider: invitations and password resets arrived, with links to https://metabase.example.com. The emails show Metabase's logo from static.metabase.com and a font from Google Fonts, which the reader's mail program loads when it shows images.
12. Back up
As metabase:
uid=$(id -u metabase)
runuser -u metabase -- env HOME=/home/metabase XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash <<'SH'
cd /home/metabase/metabase
umask 077
mkdir -p ~/backup
docker compose exec -T db pg_dump -U metabase metabase > ~/backup/metabase-db.sql
sed -n 's/^MB_ENCRYPTION_SECRET_KEY=//p' /home/metabase/metabase/metabase.env > ~/backup/encryption-key.txt
SH
Metabase's database holds the users, questions, dashboards, permissions and settings, and the connection details of your databases, encrypted with the key. The dump runs while Metabase keeps working. Your business data is not in it: it stays in your own database, which the PostgreSQL guide backs up. Copy ~/backup to another machine, for example with restic, and keep it private.
To restore into an empty pod, as metabase, with the backup in ~/backup:
docker compose down
docker compose down -v
docker compose up -d db
docker compose exec -T db psql -q -U metabase -d metabase < ~/backup/metabase-db.sql
uid=$(id -u metabase)
runuser -u metabase -- env HOME=/home/metabase XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/metabase/metabase && docker compose up -d app"
Starting only the database first loads the backup before Metabase sets up an empty one. On a new server, create the key from the backup instead of a new one in step 3:
The passwords are generated with the Compose file in the next step and kept in a 0600 file under the app directory.
13. Update
The weekly docker-update.timer checks once a day for new images of Metabase 0.64 and PostgreSQL 18, and restarts the pod when one has changed. To update now:
uid=$(id -u metabase)
runuser -u metabase -- env HOME=/home/metabase XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash <<'SH'
cd /home/metabase/metabase
docker compose pull && docker compose up -d
SH
Each new version of Metabase, such as 0.65, changes its database when it first starts. Move to it by hand, after a backup (step 12): change v0.64.x to v0.65.x in compose.yaml, then
uid=$(id -u metabase)
runuser -u metabase -- env HOME=/home/metabase XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/metabase/metabase && docker compose up -d --force-recreate app"
The first start downloads the new image and updates the database; docker compose logs app shows Database Migrations Current. Our update from 0.63 to 0.64 took 7 seconds for the database, and kept all questions and dashboards. Metabase cannot move its database back to an older version, so the backup from before the update is your way back, with the old tag. We did not test going back. Read the release notes on Metabase's GitHub before you update.
Troubleshooting
Adding the database fails with role "metabase_ro" does not exist. Host is 127.0.0.1 or localhost, which inside the pod is Metabase's own PostgreSQL. Use 169.254.1.3.
Adding the database fails with Connection refused, or times out. The extra_hosts line in compose.yaml is missing, or the project has not been recreated since you added it: docker compose up -d --force-recreate. PostgreSQL must also listen on an address the container can reach. Check that PostgreSQL runs on the server with pg_lsclusters.
password authentication failed for user "metabase_ro". The password is wrong. Set a new one as root with sudo -u postgres psql -c '\password metabase_ro', then use it under Edit connection details for the database in Admin > Databases.
A question fails with permission denied for table .... The table was created by another login than appuser, so step 1's default rights do not cover it. As root: sudo -u postgres psql -d appdb -c 'GRANT SELECT ON ALL TABLES IN SCHEMA public TO metabase_ro'.
Metabase says an invitation was sent, but nothing arrives. Metabase sends in the background, and keeps trying when the SMTP server cannot be reached. docker compose logs app 2>&1 | grep -i 'failed to send' shows the error.
https://metabase.example.com gives 502 for a minute after a restart. Metabase takes a minute or two to start. curl -s http://127.0.0.1:8131/api/health prints {"status":"ok"} when it is ready.