Files
bbs/docs/wiki/Databases.md
T
Claude 2861ba44f0 Run on SQLite, PostgreSQL or MySQL
[general] database = takes SQLite's file as before, or a server's
address: postgres://... (pgx) or mysql://... / mysql:DSN
(go-sql-driver).  The store's SQL is written once; internal/store's
dialect gives each engine its forms of what differs: ? placeholders
($1 for PostgreSQL), ids returned by RETURNING or LastInsertId, upserts
(ON DUPLICATE KEY UPDATE), INSERT OR IGNORE, GREATEST, booleans, unique
violations, column checks for migrations, indexes.  The schema is one
list with types per engine: names match in any case (NOCASE, an ICU
collation made on PostgreSQL, utf8mb4_0900_as_ci), MySQL keeps indexed
text in VARCHARs and connects with the SQL mode the store wants (ANSI
quotes for "read" and "key", strict, rows matched not changed).
Existing SQLite databases are kept as they are.

bbs db copy DATABASE copies every table into a new database of any
engine, keeping ids (PostgreSQL's sequences set after).  Logs and bbs
check never show a server's password.

Under go test, BBS_TEST_DATABASE puts every test's store on a
PostgreSQL or MySQL server (a schema or database each, dropped after):
the whole suite passes on PostgreSQL 16 and MySQL 8.4 as on SQLite.
The store's own tests check what the engines do differently, and
copying from SQLite into each.

Also: the FTP tests' readiness probe now waits to be counted out, so the
per-address limit test no longer fails at random.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-12 09:09:42 +00:00

3.0 KiB

The BBS keeps its users, messages, mail, file records, FidoNet and news state, tokens and keys in one database: SQLite (the default, one file, nothing to run), PostgreSQL (12 or later) or MySQL (8.0 or later). File areas' files are kept on disk in every case (files_dir). Tested with PostgreSQL 16 and MySQL 8.4; MariaDB is not one of them (it lacks MySQL 8's collations).

[general]
database = /var/lib/bbs/bbs.db                                ; SQLite
;database = postgres://bbs:PASSWORD@db.example.org/bbs         ; PostgreSQL
;database = mysql://bbs:PASSWORD@db.example.org:3306/bbs       ; MySQL
database
a path (or sqlite:PATH) SQLite: the file is made (0600) if it is not there
postgres:// or postgresql:// PostgreSQL, in pgx's form: ?sslmode=require, ?search_path=bbs and the like after it
mysql://user:password@host:port/db MySQL; ?tls=true and go-sql-driver's other options after it
mysql:DSN MySQL in go-sql-driver's own form, for a unix socket: mysql:bbs:PASSWORD@unix(/run/mysqld/mysqld.sock)/bbs

The BBS makes its tables (and adds columns later versions bring) when it starts, or with bbs init. The database (PostgreSQL's, or MySQL's) must be there, and the user own it or have CREATE in it; on PostgreSQL the BBS also makes a collation, nocase, for names that match in any case.

Logs and bbs check show the address with its password as xxxxx. The configuration file has it in the clear: keep it 0640, the BBS's group's.

What differs

Little, by design: the BBS writes its SQL once, and each engine is given its own forms of what differs (ids, placeholders, upserts, booleans, what counts as a duplicate).

  • Names (users, areas, files) match in any case on all three; letters with accents are not their plain letters (René is not Rene). SQLite folds the case of ASCII letters only: RENÉ finds René on PostgreSQL and MySQL, not on SQLite.
  • MySQL keeps names, Message-IDs and other indexed text in VARCHAR(255), descriptions and the like in VARCHAR(1024), messages in MEDIUMTEXT (16 MB). The BBS's connection sets the SQL mode it needs (ANSI_QUOTES, strict), whatever the server's default.
  • SQLite uses one connection (it takes one writer at a time); the servers up to ten.

Moving to another engine

bbs db copy postgres://bbs:PASSWORD@db.example.org/bbs

copies the configured database, every table, into a new, empty one (made as bbs init would), keeping ids, then says so; then set database = to the new one. The BBS should be stopped while it copies. It goes any way: SQLite to PostgreSQL, MySQL to SQLite, PostgreSQL to MySQL.

Backups

  • SQLite: sqlite3 bbs.db ".backup bbs-backup.db" (or copy the file while the BBS is stopped); bbs db copy /path/to/backup.db does it too.
  • PostgreSQL: pg_dump; MySQL: mysqldump --single-transaction.

And files_dir, in every case.

See also: Configuration, Running, Development