Running multiple Eclair processes connected to the same database can lead to data corruption and loss of funds.
That's why Eclair supports database locking mechanisms to prevent multiple Eclair instances from accessing one database together.
Use `postgres.lock-type` parameter to set the locking schemes.
Lock type | Description
---|---
`lease` | At the beginning, Eclair acquires a lease for the database that expires after some time. Then it constantly extends the lease. On each lease extension and each database transaction, Eclair checks if the lease belongs to the Eclair instance. If it doesn't, Eclair assumes that the database was updated by another Eclair process and terminates. Note that this is just a safeguard feature for Eclair rather than a bulletproof database-wide lock, because third-party applications still have the ability to access the database without honoring this locking scheme.
`none` | No locking at all. Useful for tests. DO NOT USE ON MAINNET!
For more information about backup refer to the official PostgreSQL documentation: https://www.postgresql.org/docs/current/backup.html
#### Replication
For busier nodes it isn't practical to use `pg_dump`. Fortunately, PostgreSQL provides built-in database replication which makes the backup/restore process more seamless.
To set up database replication you need to create a main database, that accepts all changes from the node, and a replica database.
Once replication is configured, the main database will automatically send all the changes to the replica.
In case of failure of the main database, the node can be simply reconfigured to use the replica instead of the main database.
PostgreSQL supports [different types of replication](https://www.postgresql.org/docs/current/different-replication-solutions.html).
The most suitable type for an Eclair node is [synchronous streaming replication](https://www.postgresql.org/docs/current/warm-standby.html#SYNCHRONOUS-REPLICATION),
because it provides a very important feature, that helps keep the replicated channel's state up to date:
> When requesting synchronous replication, each commit of a write transaction will wait until confirmation is received that the commit has been written to the write-ahead log on disk of both the primary and standby server.
Follow the official PostgreSQL high availability documentation for the instructions to set up synchronous streaming replication: https://www.postgresql.org/docs/current/high-availability.html
### Safeguard to prevent accidental loss of funds due to database misconfiguration
Using Eclair with an outdated version of the database or a database created with another seed might lead to loss of funds.
but accidental configuration changes to come into effect.
Eclair stores the latest database settings in the `${data-dir}/last_jdbcurl` file, and compares its contents with the database settings from the config file.
The node operator can force Eclair to accept new database
connection settings by removing the `last_jdbcurl` file.
Eclair supports migrating your existing node from Sqlite to Postgres. Note that the opposite (from Postgres to Sqlite) is not supported.
:warning: Once you have migrated from Sqlite to Postgres there is no going back!
To migrate from Sqlite to Postgres, follow these steps:
1. Stop Eclair
2. Edit `eclair.conf`
1. Set `eclair.db.postgres.*` as explained in the section [Connection Settings](#connection-settings).
2. Set `eclair.db.driver=dual-sqlite-primary`. This will make Eclair use both databases backends. All calls to sqlite will be replicated in postgres.
3. Set `eclair.db.dual.migrate-on-restart=true`. This will make Eclair migrate the data from Sqlite to Postgres at startup.
4. Set `eclair.db.dual.compare-on-restart=true`. This will make Eclair compare Sqlite and Postgres at startup. The result of the comparison is displayed in the logs.
3. Delete the file `~/.eclair/last_jdbcurl`. The purpose of this file is to prevent accidental change in the database backend.
4. Start Eclair. You should see in the logs:
1.`migrating all tables...`
2.`migration complete`
3.`comparing all tables...`
4.`comparison complete identical=true` (NB: if `identical=false`, contact support)
5. Eclair should then finish startup and operate normally. Data has been migrated to Postgres, and Sqlite/Postgres will be maintained in sync going forward.
6. Edit `eclair.conf` and set `eclair.db.dual.migrate-on-restart=false` but do not restart Eclair yet.
7. We recommend that you leave Eclair in dual db mode for a while, to make sure that you don't have issues with your new Postgres database. This a good time to set up [Backups and replication](#backups-and-replication).
8. After some time has passed, restart Eclair. You should see in the logs:
1.`comparing all tables...`
2.`comparison complete identical=true` (NB: if `identical=false`, contact support)
9. At this point we have confidence that the Postgres backend works normally, and we are ready to drop Sqlite for good.
10. Edit `eclair.conf`
1. Set `eclair.db.driver=postgres`
2. Set `eclair.db.dual.compare-on-restart=false`
11. Restart Eclair. From this moment, you cannot go back to Sqlite! If you try to do so, Eclair will refuse to start.