Help us shape the future of Go! Take the 2026 Go Developer Survey

popgres

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 22 Imported by: 0

README

popgres logo
popgres

The PocketBase experience on PostgreSQL.

popgres is a fork of PocketBase v0.40.6 that runs on PostgreSQL 17+ instead of SQLite.

It keeps the PocketBase experience (a single binary with the REST API, realtime, auth, files and the dashboard UI) and the compatibility with the official JS and Dart SDKs, and adds what Postgres makes possible:

  • Multiple instances behind a load balancer, coordinated only through Postgres (CLUSTER.md).
  • Row level security: the collection API rules are compiled to Postgres RLS policies, so they also apply to direct SQL clients (RLS.md).
  • Realtime from the database: optionally, the realtime events come from the Postgres logical replication, including the changes made outside of the API (REALTIME.md).
  • Vector search with a pgvector vector field and a similarity search endpoint (VECTOR.md).
  • MCP server for AI agents, with tools generated from the collections and the same API rules (MCP.md).
  • Embedded Postgres for development: popgres serve --dev without a database starts a local Postgres (DEV.md).

The differences with PocketBase are listed in COMPATIBILITY.md.

Quick start

Docker

docker build -t popgres .

docker run -d -p 8090:8090 \
  -e DATABASE_URL="postgres://user:pass@db-host:5432/popgres" \
  -v popgres_data:/app/popgres_data \
  popgres

Open http://localhost:8090/_/ to create the first superuser. The image includes the Postgres client tools for the backups and the popgres-import command.

Binary

Download the popgres archive for your platform from the releases page and run:

DATABASE_URL="postgres://user:pass@localhost:5432/popgres" ./popgres serve

The database needs the pgcrypto extension (and vector for the vector fields). The app role needs the CREATEROLE attribute for the RLS roles (see RLS.md).

Development

./popgres serve --dev

Without a DATABASE_URL, the dev mode downloads and starts an embedded Postgres in popgres_data/.pg.

Migrating from PocketBase

DATABASE_URL="postgres://..." popgres-import -dir ./popgres_data ./pb_data

The collections, records, settings, logs and files are imported, and the report lists what needs manual changes (eg. SQLite specific view queries). Your SDK clients and their auth tokens keep working. See MIGRATING.md.

Benchmarks

On the same machine, a single popgres instance handles about 2 to 2.6 times the concurrent writes of PocketBase (SQLite has a single writer), and 3 instances more than double the reads of a single one. See BENCHMARKS.md for the setup, the results and their limitations.

Use as a Go framework

popgres is a Go library with the same API as PocketBase (hooks, routes, migrations, the JS VM plugin):

package main

import (
    "log"

    "github.com/Robernetes/popgres"
    "github.com/Robernetes/popgres/core"
)

func main() {
    app := popgres.New()

    app.OnServe().BindFunc(func(se *core.ServeEvent) error {
        se.Router.GET("/hello", func(re *core.RequestEvent) error {
            return re.String(200, "Hello world!")
        })

        return se.Next()
    })

    if err := app.Start(); err != nil {
        log.Fatal(err)
    }
}

The raw SQL of the hooks and migrations must be Postgres SQL (see COMPATIBILITY.md).

Development of popgres

# Postgres 18 + pgvector for development (credentials in .env)
docker compose -f docker-compose.dev.yml up -d

# the test suite (POPGRES_TEST_URL is the template database of the tests)
POPGRES_TEST_URL="postgres://user:pass@localhost:5433/popgres_test" go test ./...

# the JS SDK compatibility tests against a server built from the sources
DATABASE_URL="postgres://..." ./scripts/sdk-test.sh

# the dashboard UI (Node 25+)
npm --prefix ui ci && npm --prefix ui run build

License

popgres is distributed under the MIT license, the same as PocketBase. PocketBase is created and maintained by Gani Georgiev; popgres is not affiliated with the PocketBase project.

Documentation

Index

Constants

View Source
const (
	// DevPostgresDirName is the name of the data directory subfolder of the embedded Postgres.
	DevPostgresDirName = ".pg"
)

Variables

View Source
var Version = "(untracked)"

Version of PocketBase

Functions

func ResetDevPostgres

func ResetDevPostgres(dataDir string) error

ResetDevPostgres deletes the embedded Postgres directory content of the specified data directory (the downloaded binaries archive is still cached in the user cache directory, so the next start doesn't download it again). The server must be stopped.

Types

type Config

type Config struct {
	// hide the default console server info on app startup
	HideStartBanner bool

	// optional default values for the console flags
	DefaultDev           bool
	DefaultDataDir       string // if not set, it will fallback to "./popgres_data"
	DefaultEncryptionEnv string
	DefaultQueryTimeout  time.Duration // default to core.DefaultQueryTimeout (in seconds)

	// optional DB configurations
	DatabaseURL      string             // default to the DATABASE_URL env variable
	LogsDatabaseURL  string             // default to the POPGRES_LOGS_URL env variable (or DatabaseURL)
	DataMaxOpenConns int                // default to core.DefaultDataMaxOpenConns
	DataMaxIdleConns int                // default to DataMaxOpenConns
	AuxMaxOpenConns  int                // default to core.DefaultAuxMaxOpenConns
	AuxMaxIdleConns  int                // default to AuxMaxOpenConns
	DBConnect        core.DBConnectFunc // default to core.DefaultDBConnect
}

Config is the PocketBase initialization config struct.

type PocketBase

type PocketBase struct {
	core.App

	// RootCmd is the main console command
	RootCmd *cobra.Command
	// contains filtered or unexported fields
}

PocketBase defines a PocketBase app launcher.

It implements core.App via embedding and all of the app interface methods could be accessed directly through the instance (eg. PocketBase.DataDir()).

func New

func New() *PocketBase

New creates a new PocketBase instance with the default configuration. Use NewWithConfig if you want to provide a custom configuration.

Note that the application will not be initialized/bootstrapped yet, aka. DB connections, migrations, app settings, etc. will not be accessible. Everything will be initialized when PocketBase.Start is executed. If you want to initialize the application before calling PocketBase.Start, then you'll have to manually call [PocketBase.Bootstrap].

func NewWithConfig

func NewWithConfig(config Config) *PocketBase

NewWithConfig creates a new PocketBase instance with the provided config.

Note that the application will not be initialized/bootstrapped yet, aka. DB connections, migrations, app settings, etc. will not be accessible. Everything will be initialized when PocketBase.Start is executed. If you want to initialize the application before calling PocketBase.Start, then you'll have to manually call [PocketBase.Bootstrap].

func (*PocketBase) Execute

func (pb *PocketBase) Execute() error

Execute initializes the application (if not already) and executes the pb.RootCmd with graceful shutdown support.

This method differs from pb.Start() by not registering the default system commands!

func (*PocketBase) Start

func (pb *PocketBase) Start() error

Start starts the application, aka. registers the default system commands (serve, superuser, version) and executes pb.RootCmd.

Directories

Path Synopsis
mcp
Package mcp implements the popgres MCP (Model Context Protocol) server.
Package mcp implements the popgres MCP (Model Context Protocol) server.
Command bench is the load generator of the popgres benchmarks (see bench/run.sh).
Command bench is the load generator of the popgres benchmarks (see bench/run.sh).
cmd
popgres-import command
Command popgres-import imports a PocketBase pb_data directory (data.db, auxiliary.db and the local storage files) into a popgres database.
Command popgres-import imports a PocketBase pb_data directory (data.db, auxiliary.db and the local storage files) into a popgres database.
popgres-import/internal/importer
Package importer copies the collections and the data of a PocketBase SQLite pb_data directory into a popgres (Postgres) app.
Package importer copies the collections and the data of a PocketBase SQLite pb_data directory into a popgres (Postgres) app.
Package core is the backbone of PocketBase.
Package core is the backbone of PocketBase.
cluster
Package cluster implements the coordination of the popgres app instances (nodes) that share the same Postgres database.
Package cluster implements the coordination of the popgres app instances (nodes) that share the same Postgres database.
validators
Package validators implements some common custom PocketBase validators.
Package validators implements some common custom PocketBase validators.
examples
base command
Package mails implements various helper methods for sending common emails like forgotten password, verification, etc.
Package mails implements various helper methods for sending common emails like forgotten password, verification, etc.
plugins
ghupdate
Package ghupdate implements a new command to selfupdate the current PocketBase executable with the latest GitHub release.
Package ghupdate implements a new command to selfupdate the current PocketBase executable with the latest GitHub release.
jsvm
Package jsvm implements pluggable utilities for binding a JS goja runtime to the PocketBase instance (loading migrations, attaching to app hooks, etc.).
Package jsvm implements pluggable utilities for binding a JS goja runtime to the PocketBase instance (loading migrations, attaching to app hooks, etc.).
migratecmd
Package migratecmd adds a new "migrate" command support to a PocketBase instance.
Package migratecmd adds a new "migrate" command support to a PocketBase instance.
update
Package update implements a new command to replace the current PocketBase executable with the one from the latest BugStage releases.
Package update implements a new command to replace the current PocketBase executable with the one from the latest BugStage releases.
Package tests provides common helpers and mocks used in PocketBase application tests.
Package tests provides common helpers and mocks used in PocketBase application tests.
cmd/parity command
Command parity compares the output of "go test -json ./..." with the list of the passing tests of PocketBase v0.40.6 (tests/golden/pocketbase-v0.40.6-tests.txt).
Command parity compares the output of "go test -json ./..." with the list of the passing tests of PocketBase v0.40.6 (tests/golden/pocketbase-v0.40.6-tests.txt).
cmd/testclean command
Command testclean drops the leftover test databases ("popgres_t_*" and "popgres_fx_*") and test roles ("popgres_t_*") of the POPGRES_TEST_URL server.
Command testclean drops the leftover test databases ("popgres_t_*" and "popgres_fx_*") and test roles ("popgres_t_*") of the POPGRES_TEST_URL server.
tools
auth/internal/jwk
Package jwk implements some common utilities for interacting with JWKs (mostly used with OIDC providers).
Package jwk implements some common utilities for interacting with JWKs (mostly used with OIDC providers).
cron
Package cron implements a crontab-like service to execute and schedule repeative tasks/jobs.
Package cron implements a crontab-like service to execute and schedule repeative tasks/jobs.
filesystem/blob
Package blob defines a lightweight abstration for interacting with various storage services (local filesystem, S3, etc.).
Package blob defines a lightweight abstration for interacting with various storage services (local filesystem, S3, etc.).
filesystem/internal/fileblob
Package fileblob provides a blob.Bucket driver implementation.
Package fileblob provides a blob.Bucket driver implementation.
filesystem/internal/s3blob
Package s3blob provides a blob.Bucket S3 driver implementation.
Package s3blob provides a blob.Bucket S3 driver implementation.
filesystem/internal/s3blob/s3
Package s3 implements a lightweight client for interacting with the REST APIs of any S3 compatible service.
Package s3 implements a lightweight client for interacting with the REST APIs of any S3 compatible service.
filesystem/internal/s3blob/s3/tests
Package tests contains various tests helpers and utilities to assist with the S3 client testing.
Package tests contains various tests helpers and utilities to assist with the S3 client testing.
template
Package template is a thin wrapper around the standard html/template and text/template packages that implements a convenient registry to load and cache templates on the fly concurrently.
Package template is a thin wrapper around the standard html/template and text/template packages that implements a convenient registry to load and cache templates on the fly concurrently.
tokenizer
Package tokenizer implements a rudimentary tokens parser of buffered io.Reader while respecting quotes and parenthesis boundaries.
Package tokenizer implements a rudimentary tokens parser of buffered io.Reader while respecting quotes and parenthesis boundaries.
types
Package types implements some commonly used db serializable types like datetime, json, etc.
Package types implements some commonly used db serializable types like datetime, json, etc.
Package ui handles the PocketBase Superuser frontend embedding.
Package ui handles the PocketBase Superuser frontend embedding.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL