External Database

Connect Insights Plus to an external PostgreSQL instance for production deployments.

Requirements

  • PostgreSQL 14+
  • DDL privileges - the user must be able to create tables, indexes, and extensions

Database Setup

Create the user and database on your PostgreSQL server:

CREATE USER unifi WITH PASSWORD 'your_strong_password';
CREATE DATABASE unifi_logs OWNER unifi;

Connection Configuration

Set the following environment variables in your docker-compose.yml:

VariableDescription
DB_HOSTExternal PostgreSQL host. When set to a non-localhost address, the embedded database is disabled
DB_PORTPostgreSQL port (default: 5432)
DB_NAMEDatabase name (default: unifi_logs)
DB_USERDatabase user (default: unifi)
DB_PASSWORDDatabase password (falls back to POSTGRES_PASSWORD)
DB_SSLMODESSL mode: require, verify-ca, verify-full

Deployment Topologies

ScenarioDB_HOSTNotes
Same Docker Composepostgres (service name)Easiest setup - both services share a Docker network
Different Docker ComposeContainer IP or shared network aliasCreate an external Docker network shared between stacks
Docker Desktop (macOS/Windows)host.docker.internalBuilt-in DNS alias for the host machine
Linux Docker172.17.0.1 or host.docker.internalUse gateway IP or add host.docker.internal via extra_hosts
Cloud DatabaseCloud provider hostnameUse DB_SSLMODE=require or higher for production

SECRET_KEY Requirement

When using an external database, you should set the SECRET_KEY environment variable explicitly. Without it, stored API keys are encrypted using POSTGRES_PASSWORD as a fallback - which may not be set in external DB configurations. If the secret changes, stored keys become unrecoverable.

Migration from Embedded Database

The built-in Migration Wizard in Settings → Data & Backups can help you move data between databases.

For step-by-step migration instructions, see the External PostgreSQL Migration Guide on our GitHub wiki.