Databases - jejellyroll-fr/fpdb-3 GitHub Wiki

Databases

fpdb stores everything it imports in a relational database of your own. Three backends are supported, all three configured from File → Databases…, and you can move your data between them without exporting anything by hand.

A populated session report backed by the fpdb database

Backend Good for Notes
SQLite Getting started, small to medium archives The default. One file, no server, no configuration.
PostgreSQL Large archives, multi-tabling, a HUD that must stay responsive The recommended destination once SQLite starts to drag.
MySQL / MariaDB Same, if you already run one Needs the .[mysql] extra when installing from source.

The PostgreSQL driver ships with the application — including in the prebuilt binaries — so choosing PostgreSQL in the GUI never requires a second install step. MySQL does.

When to leave SQLite

SQLite is not a toy and a few hundred thousand hands are no trouble. What it does not do is concurrency: the importer writes while the HUD reads, and SQLite serialises them. The symptoms of having outgrown it, in the order they usually appear:

  1. Reports take noticeably longer to open than they used to.
  2. The HUD lags behind the table by a hand or more when you are multi-tabling.
  3. Auto-import falls behind and never catches up.

If you recognise those, move to PostgreSQL. If you do not, there is nothing to gain by moving.

The database dialog

File → Databases… lists your Configured databases with their name, backend, host or path, user, and which one is the default. The buttons:

Button Does
Add… / Edit… Define a connection: name, backend, host, port, user, password
Test connection Try it before committing to it — do this first, always
Set as default Which database fpdb opens on startup
Create database Create the database itself on the server
Create tables Create the fpdb schema inside it
Migrate to… Copy everything from the current database into another
Delete database Drop it

A name is required; a host is required for PostgreSQL and MySQL; the port must be a number between 1 and 65535. The dialog will tell you if it is not.

Setting up PostgreSQL

Create a role and a database on the server first:

sudo -u postgres psql
CREATE USER fpdb WITH PASSWORD 'choose-something';
CREATE DATABASE fpdb OWNER fpdb;

Then in File → Databases…: Add…, backend postgresql, host localhost, port 5432, the user and password you just created. Test connection. Then Create tables to lay down the schema.

At this point the new database is empty. Either Set as default and start importing into it, or migrate what you already have — next section.

Migrating between backends

Migrate to… copies every table from the current database into another one, row for row.

What it does, precisely, because the details matter:

  • It preserves primary keys. No ids are remapped, so foreign keys stay valid and nothing is silently re-linked.
  • It clears the destination first. Migration replaces the destination's contents with the source's. That is by design, not a side effect.
  • The destination must already have the fpdb schema — run Create tables on it before migrating.
  • PostgreSQL sequences are reset afterwards, so the next import continues from the right ids instead of colliding.

The destination is wiped. If it holds hands that are not in the source, they are gone. Migration is one-way and destructive on the destination.

Once the migration reports its row counts, Set as default on the new database and restart fpdb.

Maintenance

Database → holds the operations you run occasionally rather than daily.

Entry What it is for
Statistics How many hands, players, tournaments the database holds. The first thing to check when a report looks empty.
Create or Recreate Tables Lay down the schema. Recreating destroys existing data — this is for a fresh database, not a repair.
Rebuild HUD Cache Recompute the aggregated statistics the HUD reads. Run it if HUD numbers disagree with the reports.
Rebuild DB Indexes Rebuild the indexes. Worth doing after a very large bulk import.
Dump Database to Textfile Export the whole database as text. Slow, and rarely what you want — for a backup, copy the SQLite file or use pg_dump.

Backing up

  • SQLite: close fpdb and copy the .db3 file. That is the whole backup.
  • PostgreSQL: pg_dump -U fpdb fpdb > fpdb-backup.sql
  • MySQL: mysqldump -u fpdb -p fpdb > fpdb-backup.sql

Do this before Create or Recreate Tables, before a migration, and before an upgrade that changes the schema.

Using more than one database

Databases are defined in HUD_config.xml, so a second configuration file gives you a completely separate setup — a demo database for screenshots, a scratch database for testing a parser, your real one for playing:

python fpdb_3_legacy/fpdb.pyw -c /path/to/other/HUD_config.xml

tools/make_demo_db.py builds exactly that: an isolated database, its own configuration, and hands that are safe to publish. See Screenshots and privacy.