Skip to content

Commit

Permalink
Add db maintenance docs
Browse files Browse the repository at this point in the history
  • Loading branch information
krzlabrdx committed Jul 5, 2024
1 parent 6510a5a commit 93ec79f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ While all three main system parts are technically independent of each other it i
**Note:** Babylon Network Gateway is **NOT** compatible with previous Olympia version. Brand-new, clean database must be used.
If you're upgrading from Olympia and deploying for the very first time you may want to run Database Migrations application with `WIPE_DATABASE=true` configuration parameter to drop existing database and recreate it. This is irreversible operation. **Proceed with caution!**

Read more about [database maintenance](./docs/database-maintenance.md) and [database migrations](./docs/database-migrations.md).

## Dependencies

Mandatory dependencies:
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ In this folder are the following docs:
* [API Specifications](./api-specifications.md)
* [Configuration](./configuration.md)
* [Monitoring](./monitoring.md)
* [Database migrations](./database_migrations.md)
* [Database Maintenance](./database-maintenance.md)
* [Database Migrations](./database-migrations.md)

Other useful docs in this codebase:

Expand Down
39 changes: 39 additions & 0 deletions docs/database-maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Database Maintenance

Network Gateway relies on a PostgreSQL database and some basic tuning is highly recommended for most operations and use cases.

> [!NOTE]
> Be advised that the exact configuration setup is heavily dependent on your infrastructure and intended use case.
### Automatic Vacuuming

If your instance of the Network Gateway is expected to operate predominantly on the recently added or modified data it is crucial to ensure PostgreSQL vacuums and analyzes all the tables frequently.

Here's a suggested auto-vacuum configuration:

```ini
autovacuum = true
autovacuum_vacuum_insert_threshold = 1000 # or lower
autovacuum_vacuum_insert_scale_factor = 0.001 # or lower
autovacuum_analyze_threshold = 1000 # or lower
autovacuum_analyze_scale_factor = 0.001 # or lower
```

Read more on automatic vacuuming in PostgreSQL documentation: [20.10. Automatic Vacuuming](https://www.postgresql.org/docs/current/runtime-config-autovacuum.html).

### Connection String Parameters

Data Aggregator component pushes significant volume of data over the wire, especially while catching up with the network.
Thus, it may be beneficial to configure connection string parameter `Write Buffer Size` to at least 64 KiB.

Read more on Npgsql connection performance-related settings: [Npgsql: Connection String Parameters](https://www.npgsql.org/doc/connection-string-parameters.html#performance).

Gateway API on the other hand is used is almost exclusively relying on database reads, many of them. Ensure database connection pooling is enabled.

Read more on Npgsql connection pool settings: [Npgsql: Connection String Parameters](https://www.npgsql.org/doc/connection-string-parameters.html#pooling).

### Permissions

- Database Migrations connection requires essentially unrestricted access to the database including DDL-related operations (think: `CREATE TABLE`, `ALTER VIEW`).
- Data Aggregator requires read-write permissions to all the tables.
- Gateway API requires read-only permissions to all the tables with the exception of `pending_transactions_*` tables where write permissions are needed.
File renamed without changes.

0 comments on commit 93ec79f

Please sign in to comment.