zerocactusSearch guides

PocketBase: a one-file backend for small apps, set up properly

PocketBase packs a database, auth, file storage, realtime and an admin UI into one file. How to set up collections, rules, backups and a small VPS, and its limits.

PocketBase: a one-file backend for small apps, set up properly

PocketBase is the backend I reach for when a small app needs logins, a database and an admin screen, and I do not want to rent three services to get them. It is a single executable: you download it, run it, and you have a SQLite database, user authentication, file uploads, realtime updates, a REST-style API and a web admin dashboard. For an internal tool, a club membership app or a prototype that might turn into something, that is a lot of backend for very little setup. This guide covers what it is, how I set up collections and access rules, how to run it on a small VPS with backups, and where it stops being the right tool.

What PocketBase actually is

Under the hood it is a Go application with an embedded SQLite database. Everything it stores goes into a pb_data folder next to the binary: the database files, uploaded files (unless you point storage elsewhere) and logs. There is no separate database server to install and no container required, though you can run it in one if you prefer.

Out of the box you get:

  • Collections, which are tables you define in the admin UI or through migrations.
  • Auth collections with email and password login, plus OAuth2 providers you configure.
  • API rules on every collection that decide who can list, view, create, update and delete records.
  • File fields with uploads stored locally or on S3-compatible storage.
  • Realtime updates pushed to clients over server-sent events.
  • An admin dashboard for browsing data, editing schema, viewing logs and managing backups.

There are official client SDKs for JavaScript and Dart, and the API is plain HTTP, so anything that can make a request can talk to it. You can also extend it, either with JavaScript hooks dropped into a pb_hooks folder or by using it as a Go library and compiling your own binary.

First run on your laptop

Download the build for your operating system from the project's official site or its GitHub releases, unzip it, and start it:

./pocketbase serve

By default it listens on port 8090. The API lives under /api/ and the admin dashboard under /_/. On first start you are asked to create the first superuser account (older releases called these admins), and that account is the only one that can change the schema. Treat its password like a database root password.

Designing collections: a worked example

Say a small community garden wants an app where members book shared tools (a tiller, a wheelbarrow, a pressure sprayer) and coordinators approve the bookings. The data model is three collections plus the built-in users:

users       (auth collection)
  name        text
  role        select: member | coordinator

tools       (base collection)
  name        text, required
  notes       text
  available   bool

bookings    (base collection)
  tool        relation -> tools, required
  member      relation -> users, required
  starts_on   date, required
  ends_on     date, required
  status      select: pending | approved | declined

The role field lives on the users collection, which keeps permission checks simple. Relations work like foreign keys: a booking points to one tool and one member, and the API can expand those relations so the client gets the tool name in the same response.

API rules: the part to get right

Every collection has five rules: list, view, create, update and delete. Each rule is either locked (only superusers can do it), empty (anyone can do it, including people who are not logged in) or a filter expression. The difference between locked and empty is the most important thing to understand in PocketBase, because an empty rule means public. When I review someone's PocketBase app, that is the first thing I check.

For the garden example, I would set the booking rules like this:

List/View:  @request.auth.id != "" && (member = @request.auth.id || @request.auth.role = "coordinator")
Create:     @request.auth.id != "" && member = @request.auth.id && status = "pending"
Update:     @request.auth.role = "coordinator"
Delete:     @request.auth.role = "coordinator"

Members can see their own bookings, coordinators see all of them. A member can create a booking only for themselves and only with a pending status, so nobody approves their own request by sending "status": "approved" from the browser. Only coordinators can change or delete bookings. The tools collection would allow list and view to any logged-in user and leave create, update and delete locked, so tools are managed in the admin UI.

Two habits help. First, test rules by logging in as an ordinary member in a private browser window and trying things you should not be able to do. Second, remember that list rules act as filters: a member listing bookings simply gets their own back rather than an error.

Schema changes and migrations

You can build everything by clicking in the dashboard, which is fine for a prototype. Once there is a second environment (your laptop and a server), you want schema changes recorded. PocketBase can write migration files to a pb_migrations folder when you change collections in the dashboard while running locally, and it applies pending migrations on start. Commit that folder to git and deploy it with the binary. Check the documentation for the exact behaviour of automatic migrations in the release you run, since this is an area that has changed between versions.

Hosting on a small VPS

A small Linux VPS is plenty for most apps that suit PocketBase. My usual layout is one folder, one system user, a systemd service and a reverse proxy in front for HTTPS.

/opt/garden/
  pocketbase          the binary
  pb_data/            database, uploads, logs
  pb_migrations/      schema history from git
  pb_hooks/           optional server-side JavaScript

The service file below runs PocketBase as an unprivileged user, restarts it if it crashes, and binds it to localhost so only the proxy can reach it:

[Unit]
Description=Garden PocketBase
After=network.target

[Service]
User=garden
WorkingDirectory=/opt/garden
ExecStart=/opt/garden/pocketbase serve --http=127.0.0.1:8090
Restart=on-failure
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target

Then a reverse proxy handles certificates. With Caddy the whole config for one domain is short:

garden.example.org {
    reverse_proxy 127.0.0.1:8090
}

PocketBase can also serve HTTPS itself and fetch certificates if you give it a domain, which is handy on a box that runs nothing else. I still prefer a proxy, because it lets me put other things on the same server later and keeps certificate handling in one familiar place.

Lock down the server the usual way: firewall open only for SSH, HTTP and HTTPS, SSH keys instead of passwords, and automatic security updates. Change the superuser password from the default you typed at 11 at night on your laptop.

Backups

Because everything is in pb_data, backups are conceptually simple, but do not just copy the SQLite files while the server is writing to them. PocketBase has a backup feature in the admin dashboard that creates a consistent archive of pb_data, can run on a schedule, and can store archives on S3-compatible storage. Use it, and send the archives somewhere other than the same server.

Then do the part most people skip: restore one. On a spare machine or your laptop, download a backup, unpack it next to a fresh PocketBase binary, start it and log in. If you can see last night's bookings, your backups work. I put a reminder in the calendar to repeat that test every few months, because a backup nobody has restored is a hope rather than a plan.

Where PocketBase stops scaling

PocketBase is honest about its design, and its limits follow from it.

It runs on one server. SQLite handles reads very well and is fast for the write loads of most small apps, but it has a single writer at a time, and PocketBase is not built to run as several instances behind a load balancer. You scale up, with a bigger machine, not out.

It is not a managed service. Uptime, updates, backups and security patches are yours. For a team with no one who is comfortable on a Linux server, that is a real cost.

The project has made breaking changes between releases before, so read the changelog before every upgrade and test it on a copy of your data first. Pin the version you run and upgrade on purpose.

Heavy reporting is awkward. You can create view collections from SQL queries, which covers a lot of small dashboards, but if the business starts asking for complex analytics across years of data, Postgres is the better home.

My rule of thumb: PocketBase is a strong fit when one server is clearly enough, the data fits comfortably on one disk, and a few minutes of downtime during an upgrade would not upset anyone. If you need several regions, a hosted service with someone else on call, or a team of developers working against shared staging databases, look at a hosted Postgres option instead. My Supabase vs Firebase comparison covers the two big hosted choices, and the no-code backend guide covers options where you never touch a server at all.

Questions people ask

Can I move from PocketBase to Postgres later?

Yes, with work. The data is in SQLite tables you can export, but your access rules, hooks and client SDK calls are PocketBase-specific and will need rewriting. Keep business logic in a small number of well-named places so the move is a project rather than an archaeology dig.

Is it safe for real user data?

It can be, if you set rules carefully, keep the server patched, serve over HTTPS and test backups. Most problems I have seen were empty rules that should have been locked, not flaws in PocketBase itself.

Do I need to know Go?

No. Most apps never touch Go. JavaScript hooks cover custom logic such as sending an email when a booking is approved.

For more on choosing between small backends, the backends section collects related pieces. If you try PocketBase this week, start with the garden example above, set the five rules on bookings, and try to approve a booking as an ordinary member. If that request fails, you are off to a good start.

Stacks: Backends & Data

More from this stack