Database maintenance
Keeping your Postgres at its best
Lago relies a lot on Postgres. If you’re hosting your own instance, you must ensure Postgres is correctly configured.
First, we recommend installing PgHero and keeping an eye on slow queries: https://github.com/ankane/pghero.
ANALYZE
and VACCUM
Postgres needs to analyze and vacuum regularly for optimal performance.
Postgres can do it automatically for you. Make sure the autovacuum_analyze_scale_factor
and autovacuum_vacuum_scale_factor
are set to a sensible value. We recommend 0.1
by default,
but it depends on the size of your tables.
Some tables need extra attention and usually much lower values: events
, invoices
, charges
and fees
.
Configure custom override values for these tables.
For example, the events
table should use a value lower than 0.01
.
Because this factor is a ratio, it’s expected to lower it from time to time as your table size grows.
The most important table to monitor is events
. Depending on your implementation, this table can receive big
burst of data and should be analyzed and vacuumed often.
When to run manually
If you send events in batch, it’s recommended to analyze and vacuum your events
table after the batch is ingested:
Most subscriptions are billed on the first of the month, therefore it’s also recommended to analyze and vacuum all tables before and after billing day.
Monitor your tables
Check the state of your tables with the following query.