<p>The replication using the <code>--wallet=sqlite3:///file1.db:/file2.db</code> works by applying the SQL statements against both databases in sequence. The main replica gets is executed first, followed by the identical statement being executed on the second database. So the first difference in the file is that any internal timestamps will differ slightly between the two copies.</p>
<p>Secondly, while we execute the exact same queries on both replicas, the secondary will not be read, i.e., when selecting rows from the database, only the first row is actually read from disk. This may cause on-disk caches and self-optimizing structures in the DB to differ, since the access patterns differ between the two. Despite this we can be sure that the two replicas would match since we implement an optimistic locking mechanism and versioning scheme using the <code>data_version</code> in the <code>vars</code> table. These will match as long as the DB has not been modified manually and both DBs have seen the same statements.</p>
<p>Furthermore <code>sqlite3</code> may implement some FS-specific logic to ensure optimal performance, so if you have the main and secondary replicas on separate media (highly suggested as that is what gives you resilience), they might have different filesystems, causing different optimizations to be used.</p>

CC BY-SA 4.0
2023-01-27T10:27:26.383Z
2023-01-27T10:27:26.383Z
cdecker
<p>In the <a href="https://lightning.readthedocs.io/BACKUP.html#sqlite3-wallet-main-backup-and-remote-nfs-mount" rel="nofollow noreferrer">backing up page</a> of C-Lightning, it says:</p>
<pre><code>The main and backup files will not be identical at every byte, but they will still contain the same data.
</code></pre>
<p>Is there any specific reason this happens? Wouldn't a backup work if I copied the exact same lightningd.sqlite3 elsewhere myself?</p>

<backup><core-lightning><database>
Why isn't the backed up sqlite3 exactly same as the lightningd.sqlite3?
Angelo
# Why isn't the backed up sqlite3 exactly same as the lightningd.sqlite3?

(Asked by: username_0 on 2023-01-26)

In the [backing up page](https://lightning.readthedocs.io/BACKUP.html#sqlite3-wallet-main-backup-and-remote-nfs-mount) of C-Lightning, it says:

```
The main and backup files will not be identical at every byte, but they will still contain the same data.

```

Is there any specific reason this happens? Wouldn't a backup work if I copied the exact same lightningd.sqlite3 elsewhere myself?

**Tags:** backup, core-lightning, database


---

## 1 answers

### Answer by username_1 on 2023-01-27. Score: 3 | Accepted answer

The replication using the `--wallet=sqlite3:///file1.db:/file2.db` works by applying the SQL statements against both databases in sequence. The main replica gets is executed first, followed by the identical statement being executed on the second database. So the first difference in the file is that any internal timestamps will differ slightly between the two copies.

Secondly, while we execute the exact same queries on both replicas, the secondary will not be read, i.e., when selecting rows from the database, only the first row is actually read from disk. This may cause on-disk caches and self-optimizing structures in the DB to differ, since the access patterns differ between the two. Despite this we can be sure that the two replicas would match since we implement an optimistic locking mechanism and versioning scheme using the `data_version` in the `vars` table. These will match as long as the DB has not been modified manually and both DBs have seen the same statements.

Furthermore `sqlite3` may implement some FS-specific logic to ensure optimal performance, so if you have the main and secondary replicas on separate media (highly suggested as that is what gives you resilience), they might have different filesystems, causing different optimizations to be used.


---

