Skip to content

RDS for PostgreSQL

Runway can provision a managed Amazon RDS for PostgreSQL instance for your EKS workload and wire the connection details into your service automatically. Runway owns the lifecycle of the instance and its credentials: it creates the instance in the Runway AWS accounts, generates the master password, publishes the connection details to Vault and AWS Secrets Manager, and injects them into your Helm chart through the Fairway infrastructure.postgresql contract. You do not create or manage the secret yourself.

This guide assumes you already have a working Runway for Kubernetes deployment. If you do not, start with Getting Started first.

Provisioning an instance and wiring it into your deployment touches four files across two repositories:

  1. Define the instance in config/runtimes/eks/rds/managed.yml (provisioner): engine, version, region, database name, per-environment sizing, and labels.
  2. Link it to your workload in config/runtimes/eks/workloads.yml (provisioner): references the instance by its name via an rds_instances list. Steps 1 and 2 go in one MR.
  3. Declare the dependency in your Fairway manifest (fairway.yaml): spec.infrastructure.postgresql.
  4. Reference the instance from your Runway deployment manifest (deployment.yaml): spec.infrastructure.rds_instance.

An instance belongs to a single service: each instance must be referenced by exactly one workload. One instance is created per environment you configure (staging, production, or both), each in its own AWS account and region, inside the Runway VPC and reachable only from the EKS cluster.

File an MR to add your instance to config/runtimes/eks/rds/managed.yml in the Runway provisioner:

config/runtimes/eks/rds/managed.yml
- name: runway-db-example
engine: postgres
engine_version: "18"
region: us-east-1
database_name: example
env_configuration:
staging:
instance_type: 2xsmall
disk_size_gb: 20
production:
instance_type: xsmall
disk_size_gb: 50
backup_retention_days: 14
labels:
gl_service: example-service-eks # required
owner_email_handle: my-team
department: eng-infra
department_group: eng-infra-my-group
product_category: my-category
Field Required Notes
name yes Must start with runway-db- (max 50 chars). Used as the RDS instance identifier and in the Vault and Secrets Manager paths.
engine yes Only postgres today.
engine_version yes PostgreSQL major version as a string, for example "18". Minor versions are applied automatically in the maintenance window.
region yes Must be an EKS region from config/runtimes/eks/regions.yml and one your workload is deployed to.
database_name yes The database created with the instance. Published to your workload as databaseName.
labels yes Infrastructure labels for cost attribution. gl_service is required; owner_email_handle, department, department_group, and product_category are optional. See the Infrastructure Standards.

Per environment under env_configuration:

Field Required Default Notes
instance_type yes Load category, one of 2xsmall, xsmall, small, medium, large, xlarge, 2xlarge. See Sizing tiers.
disk_size_gb yes Allocated gp3 storage. Minimum 20.
max_disk_size_gb no 2 × disk_size_gb Storage autoscaling cap. RDS grows the disk automatically when free space runs low. Set to 0 to disable autoscaling.
multi_az no true in production, false in staging Synchronous standby in a second availability zone.
backup_retention_days no 7 Automated backup retention; point-in-time recovery works within this window. 1 to 35.
prevent_db_deletion no true Deletion protection. See Removing an instance.
password_version no 1 Increase to rotate the master password. See Rotating the password.
exporter_password_version no 1 Increase to rotate the password of the database metrics role. The role has to be updated in the database too, see Rotating the metrics password.

Each instance_type maps to a Graviton instance class:

instance_type RDS class vCPU / memory
2xsmall db.t4g.medium 2 / 4 GiB (burstable; staging and tests)
xsmall db.m7g.large 2 / 8 GiB
small db.m7g.xlarge 4 / 16 GiB
medium db.m7g.2xlarge 8 / 32 GiB
large db.m7g.4xlarge 16 / 64 GiB
xlarge db.m7g.8xlarge 32 / 128 GiB
2xlarge db.m7g.16xlarge 64 / 256 GiB

Storage is always encrypted at rest with a dedicated KMS key, the instance is never publicly accessible, and unencrypted connections are rejected (rds.force_ssl). These are fixed and not configurable. Performance Insights and Enhanced Monitoring are enabled, and the maintenance window is Sunday 06:00 to 07:00 UTC, the same as Cloud SQL on GKE.

Create the MR and assign it to a Runway team member (see CODEOWNERS), and ensure the pipeline passes before requesting review.

Section titled “Step 2: Link the instance to your workload”

In config/runtimes/eks/workloads.yml, add an rds_instances key to your workload entry, referencing the instance by its name:

config/runtimes/eks/workloads.yml
- runway_service_id: example-service-eks
regions:
- us-east-1
rds_instances:
- runway-db-example

This is what tells the provisioner where to publish the connection details, and it grants your workload’s External Secrets role access to them. Inventory validation fails the MR if an instance is not linked to any workload, is linked to more than one, or is in a region the workload is not deployed to.

Step 3: Declare the dependency in your Fairway manifest

Section titled “Step 3: Declare the dependency in your Fairway manifest”

In your service’s fairway.yaml, declare that the service needs PostgreSQL:

.runway/fairway.yaml
spec:
infrastructure:
postgresql:
presence: REQUIRED

Do not set spec.values.infrastructure.postgresql.secretRef yourself for a Runway-managed instance. runwayctl sets the secret reference from the deployment manifest in Step 4 and overwrites anything you put there. Other postgresql settings such as clientName, maxConns, or queryExecMode are yours to set and are preserved.

Step 4: Reference the instance in your deployment manifest

Section titled “Step 4: Reference the instance in your deployment manifest”

In your service’s deployment.yaml, add the instance under spec.infrastructure.rds_instance, using the same name as in managed.yml:

.runway/deployment.yaml
apiVersion: runway/v2
kind: RunwayManifest
metadata:
name: example-service-eks
spec:
infrastructure:
rds_instance:
name: runway-db-example

runwayctl checks the two manifests against each other at deploy time:

Fairway presence rds_instance set Result
REQUIRED yes wired
REQUIRED no deploy fails
OPTIONAL yes or no wired when set
UNUSED yes deploy fails

rds_instance is only meaningful on EKS; a GKE deployment ignores it with a warning, the same way EKS ignores cloudsql_instance.

On apply, the provisioner creates, for each configured environment:

  • The RDS instance <name>, reachable only from the EKS cluster.

  • The database named database_name, owned by the master user runway.

  • A generated master password, applied to the instance through a write-only attribute. It is never stored in Terraform state.

  • Three secrets, published to both Vault (mount runway) and AWS Secrets Manager under the same paths:

    Path Contents
    platform/<runway_service_id>/postgres/<name>/<environment> host, port, databaseName, username, exporterUsername, region
    platform/<runway_service_id>/postgres/<name>/<environment>-password password
    platform/<runway_service_id>/postgres/<name>/<environment>-exporter-password password of the database metrics role, see Monitoring

Vault is where you look as a human. Secrets Manager is what External Secrets reads on the cluster, since the EKS clusters have no connectivity to Vault. The instance itself is not reachable from outside the EKS cluster.

Runway wires the connection details into your deployment automatically; nothing to configure. Your service reads them through LabKit’s v2/postgres package, the same way it would for any other postgresql dependency. postgres.New picks up the host, port, database, username, and password from the mounted contract, so no DSN or environment variables are needed:

import (
"context"
"log"
"gitlab.com/gitlab-org/labkit/v2/postgres"
)
func main() {
ctx := context.Background()
pg, err := postgres.New(ctx)
if err != nil {
log.Fatalf("postgres.New: %v", err)
}
// Opens the connection pool and pings the database.
if err := pg.Start(ctx); err != nil {
log.Fatalf("pg.Start: %v", err)
}
defer pg.Shutdown(ctx)
// pg.DB() is a *sql.DB; pg.Pool() exposes the underlying pgx pool.
rows, err := pg.DB().QueryContext(ctx, "SELECT id, name FROM users")
if err != nil {
log.Fatalf("query: %v", err)
}
defer rows.Close()
for rows.Next() {
var (
id int
name string
)
if err := rows.Scan(&id, &name); err != nil {
log.Fatalf("scan: %v", err)
}
log.Printf("user %d: %s", id, name)
}
}

See Declaring a PostgreSQL dependency in the Fairway guide for the full contract, and the LabKit postgres README for pool tuning and tracing.

Runway collects the metrics of the instance for you. To get a Grafana dashboard, an SLI, and alerts, register the instance in the Runway metrics catalog, as for Cloud SQL instances. See Getting a dashboard and database metrics.

Metrics come from two places:

  • CloudWatch and Enhanced Monitoring, for the instance itself: CPU, memory, storage, connections, IOPS, latency, network, and database load from Performance Insights.
  • postgres_exporter, for the database: transactions, rows read and written, locks, deadlocks, cache hit ratio, temporary files, and size.

The dashboard is at https://dashboards.gitlab.net/d/<name>-main/<name>-overview, with these rows:

Row Shows
Connections Client connections and database load (active sessions, split into CPU and other)
Disk Read and write operations, latency, queue depth, free storage, and transaction log usage
Network Receive and transmit throughput
Compute CPU utilization, freeable memory, and swap usage
Database activity Connections by state and per database, connections against max_connections, transactions, longest open transaction, locks, and deadlocks
Tuples Rows fetched, returned, and written, rows by operation, and live and dead rows
Cache and storage Cache hit ratio, database size, and temporary files and data

The transactions_primary SLI counts every commit and rollback as a request and every rollback as an error, as for Cloud SQL. Its alerts have severity s4.

Two steps are needed after your instance is created:

  1. Register the instance in the metrics catalog. Add it in an MR to gitlab-com/runbooks, as shown below. This creates the dashboard, the SLI, and the alerts. The instance panels (CloudWatch metrics) work as soon as it is registered.
  2. Create the metrics role in the database. postgres_exporter connects as a dedicated read-only role, runway_pg_exporter, whose password is the <environment>-exporter-password secret. Runway does not connect to your database as the master user to create it, so an SRE creates the role by hand, once per database, as described below. Ask in #f_runway to engage one. Until the role exists, the database panels (transactions, tuples, locks, cache) stay empty.

Registering the instance in the metrics catalog

Section titled “Registering the instance in the metrics catalog”

The MR to gitlab-com/runbooks adds four things. <name> is the instance name from managed.yml.

  1. The service definition. team and featureCategory are your stage group’s team and feature category:

    metrics-catalog/services/<name>.jsonnet
    local rdsArchetype = import 'service-archetypes/runway-rds-archetype.libsonnet';
    local metricsCatalog = import 'servicemetrics/metrics.libsonnet';
    metricsCatalog.serviceDefinition(
    rdsArchetype(
    team='my_team',
    type='<name>',
    descriptiveName='Postgres on RDS managed by Runway for my service',
    featureCategory='my_feature_category',
    )
    )
  2. An import of it in metrics-catalog/services/all.jsonnet, in alphabetical order:

    metrics-catalog/services/all.jsonnet
    import '<name>.jsonnet',
  3. The dashboard. Create this file before you generate. For an entry without a dashboard file, the generator creates a generic service dashboard, which has none of the RDS panels:

    dashboards/<name>/main.dashboard.jsonnet
    local runwayRdsCommon = import 'gitlab-dashboards/runway_rds_common_graphs.libsonnet';
    runwayRdsCommon.runwayRdsDashboard('<name>')
    .overviewTrailer()
  4. An entry in services/service-catalog.yml:

    services/service-catalog.yml
    - name: <name>
    tier: db
    friendly_name: My service database (Postgres on RDS)
    label: RunwayRdsMyService
    owner: my_team
    teams:
    - my_team
    technical:
    documents:
    architecture: https://docs.runway.gitlab.com/runtimes/kubernetes/managed-services/rds/
    service:
    - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html
    observability:
    monitors:
    primary_grafana_dashboard: <name>-main/<name>-overview

owner and teams must be teams from services/teams.yml, and label must be unique across the catalog, ignoring case.

Then run make generate and commit what it produces: the recording and alerting rules under mimir-rules/runway/<name>/ and the service page under docs/<name>/.

Only an SRE can create the role, because it needs access to the environment’s AWS account and EKS cluster. Ask in #f_runway to engage one. The steps below are for them. Do it once per instance and environment, with the account and cluster of the environment you are working on: staging and production have separate secrets and separate databases.

  1. Set the variables once. The commands below use them. You need aws, kubectl, and jq. Set KUBE_CONTEXT to your kubectl context for the EKS cluster of the same environment:

    Terminal window
    export AWS_PROFILE=runway-production # runway-staging for staging
    export AWS_REGION=us-east-1 # the region of the instance in managed.yml
    export KUBE_CONTEXT=<eks-cluster-context> # the EKS cluster of the same environment
    NAME=runway-db-example # instance name from managed.yml
    ENVIRONMENT=production # staging or production
    RUNWAY_SERVICE_ID=example-service-eks # runway_service_id of the workload that owns the instance
    PREFIX=platform/${RUNWAY_SERVICE_ID}/postgres/${NAME}
    EXPORTER_SECRET=${PREFIX}/${ENVIRONMENT}-exporter-password
  2. Check the secrets of the instance. Expect three names, which start with the prefix: ${ENVIRONMENT} (connection details), ${ENVIRONMENT}-password (the master password), and ${ENVIRONMENT}-exporter-password. If the prefix is wrong, the output shows the right runway_service_id:

    Terminal window
    aws secretsmanager list-secrets --filters Key=all,Values=${NAME} --query 'SecretList[].Name'
  3. Read the connection details into variables. They are not secret: the host, the database, and the master user name. exporterUsername in the same secret is the role name to create, runway_pg_exporter:

    Terminal window
    CONN=$(aws secretsmanager get-secret-value --secret-id ${PREFIX}/${ENVIRONMENT} \
    --query SecretString --output text)
    HOST=$(jq -r .host <<<"$CONN"); DB=$(jq -r .databaseName <<<"$CONN"); MASTER=$(jq -r .username <<<"$CONN")
  4. Open a psql session as the master user. The instance is private, so use a throwaway pod in the EKS cluster, in a namespace that can reach it, such as monitoring. Start the pod, wait for it, and then exec into it, so that the password prompt is visible. psql asks for the master password:

    Terminal window
    kubectl --context ${KUBE_CONTEXT} -n monitoring run psql-tmp --image=postgres:18 --restart=Never -- sleep 3600
    kubectl --context ${KUBE_CONTEXT} -n monitoring wait --for=condition=Ready pod/psql-tmp
    kubectl --context ${KUBE_CONTEXT} -n monitoring exec -it psql-tmp -- \
    psql "host=${HOST} port=5432 dbname=${DB} user=${MASTER} sslmode=require"

    Get the master password in a second terminal, with the same variables set:

    Terminal window
    aws secretsmanager get-secret-value --secret-id ${PREFIX}/${ENVIRONMENT}-password \
    --query SecretString --output text | jq -r .password
  5. Create the role. In the second terminal, get the exporter password. The secret is {"password": "..."}, and jq takes out the value:

    Terminal window
    aws secretsmanager get-secret-value --secret-id ${EXPORTER_SECRET} \
    --query SecretString --output text | jq -r .password

    In the psql session, create the role and set its password with \password. It asks for the password twice, without echoing it, and sends it hashed, so the cleartext password is not in the SQL, the terminal, or the server logs. pg_monitor is a built-in role that gives read-only access to the statistics views and nothing else:

    CREATE ROLE runway_pg_exporter WITH LOGIN CONNECTION LIMIT 5;
    \password runway_pg_exporter
    GRANT pg_monitor TO runway_pg_exporter;

    If the role already exists, skip the CREATE ROLE line.

  6. Check the role, still in psql. The second query returns t:

    \du runway_pg_exporter
    SELECT pg_has_role('runway_pg_exporter', 'pg_monitor', 'member');

    Then leave the session with \q and delete the pod, which does not delete itself:

    Terminal window
    kubectl --context ${KUBE_CONTEXT} -n monitoring delete pod psql-tmp
  7. Check the metrics. Within a few minutes pg_up{type="<name>", environment="<environment>"} is 1 in Mimir (Grafana Explore, datasource mimir-runway), and the database panels fill in. You do not need to restart the exporter if it was already running when the secret was published. It restarts on its own when its secret changes, so a restart is only needed if you want to force it:

    Terminal window
    kubectl --context ${KUBE_CONTEXT} -n monitoring rollout restart deploy prometheus-postgres-exporter

If pg_up stays 0, the password in the database does not match the secret: run \password runway_pg_exporter again with the value from the secret. For other symptoms, see Troubleshooting.

  1. Increase exporter_password_version for the environment in managed.yml and merge. The provisioner writes a new password to the <environment>-exporter-password secret.

  2. Straight after the apply, open a psql session as the master user the same way as when creating the role: set the variables (step 1), read the connection details (step 3), and start the pod and exec into it (step 4). Get the new password from ${EXPORTER_SECRET} with the command in step 5.

  3. The role and its pg_monitor membership already exist, so the database commands differ from step 5. Run only this, and enter the new password twice at the prompt:

    \password runway_pg_exporter

    Do not run CREATE ROLE or the GRANT again.

  4. Leave the session with \q and delete the pod, as in step 6.

  5. The exporter picks up the new password on its own: External Secrets refreshes its secret every ten minutes (the refresh interval of the ExternalSecret), and Reloader then rolls the pod.

Increase password_version for the environment in managed.yml and merge. In one apply, the provisioner generates a new password, applies it to the instance, and republishes it to Vault and Secrets Manager. External Secrets refreshes the Kubernetes Secret within ten minutes. Only ever increase the version.

The same bump is the recovery step if an apply fails between creating the instance and writing the secrets, so that all three places agree again.

Removing an instance, or one of its environments, takes two MRs, because RDS deletion protection blocks the destroy while it is on:

  1. Set prevent_db_deletion: false for the environment(s) you are removing, merge, and let the apply run.
  2. In a follow-up MR, remove the entry (or the environment key) from managed.yml together with the rds_instances reference in workloads.yml.

An MR that removes the entry while prevent_db_deletion is still true on the default branch fails inventory validation. On deletion, RDS takes a final snapshot named <name>-final-<timestamp> and the automated backups are kept for their retention period, so a mistaken removal is recoverable.

  • The deploy fails with “did not find RDS configuration despite the application declaring Postgres”: fairway.yaml has presence: REQUIRED but deployment.yaml has no rds_instance. Add it, or change the presence to OPTIONAL.

  • The transactions, tuples, locks, or cache panels are empty but the instance panels work: the runway_pg_exporter role has not been created in the database yet. An SRE creates it: ask in #f_runway, and see Creating the metrics role.

  • There is no dashboard for the instance: the instance is not registered in the metrics catalog yet. See Getting a dashboard and database metrics.

Ask the Runway team in #f_runway for help.