Using PostgreSQL as backend database instead of SQLite

If you need to, CTFreak lets you migrate your database backend from SQLite to PostgreSQL.

See the procedure below.

Requirements

  • PostgreSQL >= 17, preferably installed on the same server as your CTFreak instance for best performance
  • A Business Edition license (or a Free Edition license if you plan to upgrade to a Business Edition license in the future, otherwise we recommend that you stick with SQLite)

Setting up

Shut down the CTFreak instance and open the config.json file located in the dedicated config folder. You should get something like this:

{
  ...
  ...
  "backendDatabaseType": "SQLITE",
  "sqliteBackendDatabase": {
    "useMemoryTempStoreFg": true
  }
}

Replace the SQLite parameters with those of your PostgreSQL database:

{
  ...
  ...
  "backendDatabaseType": "POSTGRESQL",
  "postgresqlBackendDatabase": {
    "host": "localhost",
    "port": 5432,
    "user": "user",
    "password": "password",
    "dbname": "dbname"
  }
}

Now, you can restart your CTFreak instance.

If your PostgreSQL database is empty, all data from your old SQLite database will be automatically imported (this may take a little time if you have a large history of executions: expect 2 min per million executions to be imported).

Once the import has been successfully completed, the files from the old SQLite backend database will be moved to the old_backend_db subfolder (you can delete it whenever you like), and your instance will continue its startup process.

NB: Should the import fail, you can always restore the old configuration file, delete the PostgreSQL database and restart your instance to return to your old SQLite database backend.