Database
Arbinel uses Forgejo’s [database] settings.
The Forgejo configuration cheat sheet describes them, and the Forgejo database preparation guide covers setting up PostgreSQL or MySQL.
Arbinel adds a connection timeout, failover between several hosts, consistent reads with replicas, table retention tasks, and a few performance changes.
Connection timeout
Section titled “Connection timeout”| Key | Default | Meaning |
|---|---|---|
CONNECT_TIMEOUT |
10s |
How long a new PostgreSQL connection may take before Arbinel gives up on that host. 0 turns it off. |
Without it, a connection to a host that does not answer waits for the operating system’s TCP timeout, often about two minutes.
Arbinel adds the value to the PostgreSQL connection string as connect_timeout, in whole seconds.
If NAME already contains a connect_timeout parameter, for example NAME = arbinel?connect_timeout=5, Arbinel uses that value instead.
MySQL and SQLite ignore the setting.
Multiple hosts
Section titled “Multiple hosts”HOST_PRIMARY and HOST_REPLICA are Forgejo settings for a primary with read replicas.
Both accept a comma-separated list of PostgreSQL hosts:
Each list becomes one PostgreSQL connection string with several hosts.
The driver tries the hosts in order and uses the first one that answers within CONNECT_TIMEOUT.
An unreachable host delays the connection by at most that time and never blocks queries.
Forgejo instead opens a separate connection pool for each replica host. If one of those hosts is down, Forgejo can keep sending reads to it and hang.
A multi-host connection has these limits:
- The driver does not spread load across the hosts in a list. It uses the first reachable one. To spread reads across replicas, put a load balancer such as HAProxy or PgBouncer in front of them.
- With a single replica connection string,
LOAD_BALANCE_POLICYandLOAD_BALANCE_WEIGHTShave no effect. - Every host in
HOST_PRIMARYmust accept writes when it answers. List endpoints that always lead to the current primary, for example the read-write endpoint of your PostgreSQL cluster manager. - With MySQL, list only one replica host. A comma-separated list does not work there.
Read consistency with replicas
Section titled “Read consistency with replicas”| Key | Default | Meaning |
|---|---|---|
REPLICA_STICKY_DURATION |
5s |
How long a client keeps reading the primary after it writes, on every node. 0 turns this off. |
Replicas lag behind the primary. In Forgejo, every read that is not part of a transaction can go to a replica, so a read right after a write can miss the new row. Arbinel sends reads to the replicas only where a short delay is safe:
GET,HEADandOPTIONSrequests read from the replicas.- Other requests, such as form submissions and API calls that change data, read from the primary.
- Queues, cron tasks, command-line tools and the internal API that Git hooks use read from the primary.
- The first request of a Git push over HTTP reads from the primary, so a push to a user, organization or repository created moments ago finds it.
- Requests from Actions runners and jobs, including artifact uploads and downloads, read from the primary. The exception is the check for new tasks in each runner poll, which reads from the replicas. A replica that lags delays a new task by one poll, and the task is still assigned on the primary.
- The statistics that
/metricsreports read from the replicas. - Sign-in checks read from the primary, so a new access token works at once and a revoked token or disabled account stops working at once.
- A request switches to the primary as soon as it writes or starts a transaction.
After a client writes, Arbinel keeps its reads on the primary for REPLICA_STICKY_DURATION, so the next page shows the change.
A browser gets a short-lived _db_primary cookie.
For a signed-in user, Arbinel also stores a marker in the cache, which covers API clients that do not keep cookies.
With several nodes, use a shared cache such as Redis, so every node sees the marker.
Some writes do not count, so the client keeps reading from the replicas: an access token’s last-used time, and the download counters of attachments and packages. The cookie is signed, so a client cannot move its reads to the primary without writing.
This applies only when HOST_REPLICA is set.
If no replica is available, reads fail.
Arbinel does not fall back to the primary by itself, so let your load balancer do it, for example with a backup server for the primary in HAProxy.
Table retention
Section titled “Table retention”Forgejo never deletes some rows of the action_artifact and commit_status tables.
Arbinel adds two cron tasks that delete them.
Both are off by default.
| Key | cleanup_artifact_rows |
cleanup_commit_statuses |
Meaning |
|---|---|---|---|
OLDER_THAN |
168h |
720h |
How old a row must be before the task deletes it. Arbinel uses 24h for a lower value. |
BATCH_SIZE |
1000 |
1000 |
How many rows or IDs one statement covers. |
cleanup_artifact_rows deletes these rows:
- Rows of artifacts that Forgejo already deleted from storage.
- Rows of uploads that never completed and have no file in storage.
- All rows but the first of an expired artifact that an older upload stored as one row per file. The first row keeps the total size, so the run page and the API still list the artifact as expired.
cleanup_commit_statuses deletes a commit status when a newer status with the same context exists for the commit.
It keeps every status of a commit that received a status within OLDER_THAN, and of a commit that is a branch tip.
Commit lists, pull request checks, branch protection and the combined status only read the newest status of each context, so they show the same result.
The API that lists all statuses of a commit no longer returns the replaced ones.
Activity feed
Section titled “Activity feed”Forgejo’s delete_old_actions task deletes activity feed entries older than OLDER_THAN.
Arbinel deletes them in batches of 5,000 rows.
Before it deletes a pushed commit, tag, mirror sync or release, it records that the user put content into the repository.
The account and the repository therefore do not turn idle.
The contribution heatmap only shows the last year, so an OLDER_THAN of a year or more leaves it as it is.
With FEED_MIRROR_SYNC = false, Arbinel records no feed entry when a pull mirror syncs.
Mirror syncs then no longer count as the owner’s contributions in the heatmap.
delete_old_actions also deletes the mirror sync entries recorded before, whatever their age.
Deleted rows free space for new rows.
To return the space to the operating system, run VACUUM FULL or pg_repack on PostgreSQL.
Performance changes
Section titled “Performance changes”These need no configuration.
- Two extra indexes on the
issuetable speed up issue and pull request lists. They cover(repo_id, is_closed, created_unix)and(repo_id, is_closed, is_pull)and are namedrepo_closed_createdandrepo_closed_pull. Arbinel creates them during its schema sync at startup, so the first start on a large database takes longer while Arbinel builds them. - The in-memory commit cache that Git tree listings use to find the last commit of each file is capped at 5,000 commits per open repository.
Forgejo’s cache had no limit and could grow with every commit it resolved.
The
[cache.last_commit]settings still control the shared last-commit cache as in Forgejo.
If you switch back to Forgejo, its schema sync removes the two indexes again. This causes no harm.