mirror of
https://github.com/tiennm99/db-keepalive.git
synced 2026-06-27 13:04:50 +00:00
main
2d16bb5ca6
build(deps): bump go.opentelemetry.io/otel (#7)
Bumps the security group with 1 update in the / directory: [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go). Updates `go.opentelemetry.io/otel` from 1.40.0 to 1.41.0 - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.40.0...v1.41.0) --- updated-dependencies: - dependency-name: go.opentelemetry.io/otel dependency-version: 1.41.0 dependency-type: indirect dependency-group: security ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
db-keepalive
Pluggable Go daemon that performs a periodic counter increment to prevent free-tier database clusters (Redis Cloud, Valkey, Aiven, Neon, Supabase, MongoDB Atlas, Couchbase Capella, etc.) from being auto-paused for inactivity.
Successor to the *-keepalive family: one binary, one image, six adapters.
Supported drivers
DB_TYPE |
Driver | Env vars |
|---|---|---|
redis |
github.com/redis/go-redis/v9 |
REDIS_URL |
valkey |
github.com/valkey-io/valkey-go |
VALKEY_URL |
postgresql |
github.com/lib/pq |
SERVICE_URI |
mysql |
github.com/go-sql-driver/mysql |
DATA_SOURCE_NAME |
mongodb |
go.mongodb.org/mongo-driver/v2 |
MONGODB_URI, MONGODB_DATABASE, MONGODB_COLLECTION |
couchbase |
github.com/couchbase/gocb/v2 |
COUCHBASE_CONNECTION_STRING, COUCHBASE_USERNAME, COUCHBASE_PASSWORD, COUCHBASE_BUCKET_NAME, COUCHBASE_SCOPE_NAME, COUCHBASE_COLLECTION_NAME |
Optional: INTERVAL (e.g. 30s, 5m; default 1m), COUNTER_KEY (default counter).
Quick start (Docker)
docker run -d --name db-keepalive --restart unless-stopped \
-e DB_TYPE=redis \
-e REDIS_URL='redis://default@host:6379' \
ghcr.io/tiennm99/db-keepalive:latest
Quick start (local)
git clone https://github.com/tiennm99/db-keepalive
cd db-keepalive
cp .env.example .env # then edit DB_TYPE + the driver's env vars
go run .
How it works
On every tick the chosen adapter performs the cheapest write that proves the cluster is alive:
- Redis/Valkey —
INCR counter - PostgreSQL —
UPDATE keepalive SET value = value + 1 WHERE key = 'counter' RETURNING value - MySQL —
UPDATE+SELECTinside a transaction - MongoDB —
FindOneAndUpdate({_id: "counter"}, {$inc: {count: 1}}, upsert) - Couchbase —
GET counter→++→UPSERT counter
The PostgreSQL and MySQL adapters expect a table:
CREATE TABLE keepalive (key TEXT PRIMARY KEY, value BIGINT NOT NULL DEFAULT 0);
INSERT INTO keepalive (key, value) VALUES ('counter', 0);
(MySQL uses backticked identifiers — see adapter/mysql.go.)
Adding a new database
- Create
adapter/<name>.go. - Implement the
Adapterinterface inadapter/adapter.go(Connect,Increment,Close). - Register the factory in
init():func init() { Registry["<name>"] = func() (Adapter, error) { return &myAdapter{}, nil } } - Add an
import _ "your driver"if needed, and the env vars to.env.exampleand the table above.
Migrated from
This repo replaces six single-database repos. All are archived with a pointer here:
- redis-keepalive
- valkey-keepalive
- postgresql-keepalive
- mysql-keepalive
- mongodb-keepalive
- couchbase-keepalive
License
Apache-2.0 — see LICENSE.
Description
Pluggable Go keepalive daemon for free-tier DB clusters — Redis, Valkey, PostgreSQL, MySQL, MongoDB, Couchbase. Successor to *-keepalive family.
⚠️ ARCHIVED: Original GitHub repository no longer exists. Preserved as backup on 2026-06-27T14:51:04.767Z
Readme
Apache-2.0
192 KiB
Languages
Go
97.1%
Dockerfile
2.9%