Electric: PostgreSQL Sync Engine
Electric is a PostgreSQL sync engine. It delivers database changes efficiently to frontend and edge applications.
Pigsty provides the app/electric template (conf/app/electric.yml). It configures the database, containers, and ingress in one workflow.
Quick Start
Default endpoints:
http://<IP>:8002http://elec.pigsty(default domain in the template)
The Prometheus endpoint is disabled by default and its port is not published. Enable ELECTRIC_PROMETHEUS_PORT only when regular scraping is configured: an enabled reporter that is never scraped retains metrics and can eventually exhaust memory.
Key Settings
conf/app/electric.yml writes apps.electric.conf into /opt/electric/.env. Common parameters:
DATABASE_URL: PostgreSQL connection string for Electric; requiresREPLICATIONprivilegesELECTRIC_PORT: port inside the container, default3000ELECTRIC_PUBLISH_PORT: published host port, default8002ELECTRIC_PERSISTENT_STATE: defaults toFILEto retain synchronization state across container recreationELECTRIC_STORAGE: defaults toFAST_FILE; Electric 1.7.12+ acceptsMEMORYorFAST_FILE, and the oldFILEvalue prevents startupELECTRIC_STORAGE_DIR: absolute persistence path inside the container, default/var/lib/electricELECTRIC_INSECURE: defaults totruefor development; set it tofalseand configureELECTRIC_SECRETbefore exposing a production deployment
The template follows the unpinned upstream electricsql/electric image (the verified snapshot uses sync-service 1.7.12). Pin an image version or digest for controlled production upgrades.
Cache and Persistence
Compose mounts the named volume electric-data at ELECTRIC_STORAGE_DIR (default /var/lib/electric). It retains shape handles and logs when a container is recreated at the same version and the PostgreSQL timeline is unchanged.
PostgreSQL holds the authoritative application data; the Electric cache volume does not replace database backups. Losing the volume or changing PostgreSQL instance identity or timeline invalidates cached shapes. Clients must handle 409 / must-refetch, discard their local cache, and synchronize again.
Operations
References
- Electric website: https://electric-sql.com/
- Electric docs: https://electric-sql.com/docs
- Pigsty template: https://github.com/pgsty/pigsty/blob/main/conf/app/electric.yml