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.