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.
Overview
Section titled “Overview”Provisioning an instance and wiring it into your deployment touches four files across two repositories:
- Define the instance in
config/runtimes/eks/rds/managed.yml(provisioner): engine, version, region, database name, per-environment sizing, and labels. - Link it to your workload in
config/runtimes/eks/workloads.yml(provisioner): references the instance by itsnamevia anrds_instanceslist. Steps 1 and 2 go in one MR. - Declare the dependency in your Fairway manifest (
fairway.yaml):spec.infrastructure.postgresql. - 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.
Step 1: Define the instance
Section titled “Step 1: Define the instance”File an MR to add your instance to
config/runtimes/eks/rds/managed.yml
in the Runway provisioner:
- 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-categoryField reference
Section titled “Field reference”| 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. |
Sizing tiers
Section titled “Sizing tiers”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.
Step 2: Link the instance to your workload
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:
- runway_service_id: example-service-eks regions: - us-east-1 rds_instances: - runway-db-exampleThis 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:
spec: infrastructure: postgresql: presence: REQUIREDDo 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:
apiVersion: runway/v2kind: RunwayManifestmetadata: name: example-service-eks
spec: infrastructure: rds_instance: name: runway-db-examplerunwayctl 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.
What gets created
Section titled “What gets created”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 userrunway. -
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,regionplatform/<runway_service_id>/postgres/<name>/<environment>-passwordpasswordplatform/<runway_service_id>/postgres/<name>/<environment>-exporter-passwordpasswordof 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.
Consuming the instance
Section titled “Consuming the instance”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.
Monitoring
Section titled “Monitoring”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.
What you get
Section titled “What you get”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.
Getting a dashboard and database metrics
Section titled “Getting a dashboard and database metrics”Two steps are needed after your instance is created:
- 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. - Create the metrics role in the database.
postgres_exporterconnects as a dedicated read-only role,runway_pg_exporter, whose password is the<environment>-exporter-passwordsecret. 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_runwayto 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.
-
The service definition.
teamandfeatureCategoryare 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',)) -
An import of it in
metrics-catalog/services/all.jsonnet, in alphabetical order:metrics-catalog/services/all.jsonnet import '<name>.jsonnet', -
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() -
An entry in
services/service-catalog.yml:services/service-catalog.yml - name: <name>tier: dbfriendly_name: My service database (Postgres on RDS)label: RunwayRdsMyServiceowner: my_teamteams:- my_teamtechnical:documents:architecture: https://docs.runway.gitlab.com/runtimes/kubernetes/managed-services/rds/service:- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.htmlobservability: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>/.
Creating the metrics role (SRE only)
Section titled “Creating the metrics role (SRE only)”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.
-
Set the variables once. The commands below use them. You need
aws,kubectl, andjq. SetKUBE_CONTEXTto yourkubectlcontext for the EKS cluster of the same environment:Terminal window export AWS_PROFILE=runway-production # runway-staging for stagingexport AWS_REGION=us-east-1 # the region of the instance in managed.ymlexport KUBE_CONTEXT=<eks-cluster-context> # the EKS cluster of the same environmentNAME=runway-db-example # instance name from managed.ymlENVIRONMENT=production # staging or productionRUNWAY_SERVICE_ID=example-service-eks # runway_service_id of the workload that owns the instancePREFIX=platform/${RUNWAY_SERVICE_ID}/postgres/${NAME}EXPORTER_SECRET=${PREFIX}/${ENVIRONMENT}-exporter-password -
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 rightrunway_service_id:Terminal window aws secretsmanager list-secrets --filters Key=all,Values=${NAME} --query 'SecretList[].Name' -
Read the connection details into variables. They are not secret: the host, the database, and the master user name.
exporterUsernamein 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") -
Open a
psqlsession 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 asmonitoring. Start the pod, wait for it, and thenexecinto it, so that the password prompt is visible.psqlasks for the master password:Terminal window kubectl --context ${KUBE_CONTEXT} -n monitoring run psql-tmp --image=postgres:18 --restart=Never -- sleep 3600kubectl --context ${KUBE_CONTEXT} -n monitoring wait --for=condition=Ready pod/psql-tmpkubectl --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 -
Create the role. In the second terminal, get the exporter password. The secret is
{"password": "..."}, andjqtakes out the value:Terminal window aws secretsmanager get-secret-value --secret-id ${EXPORTER_SECRET} \--query SecretString --output text | jq -r .passwordIn the
psqlsession, 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_monitoris 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_exporterGRANT pg_monitor TO runway_pg_exporter;If the role already exists, skip the
CREATE ROLEline. -
Check the role, still in
psql. The second query returnst:\du runway_pg_exporterSELECT pg_has_role('runway_pg_exporter', 'pg_monitor', 'member');Then leave the session with
\qand delete the pod, which does not delete itself:Terminal window kubectl --context ${KUBE_CONTEXT} -n monitoring delete pod psql-tmp -
Check the metrics. Within a few minutes
pg_up{type="<name>", environment="<environment>"}is1in Mimir (Grafana Explore, datasourcemimir-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.
Rotating the metrics password
Section titled “Rotating the metrics password”-
Increase
exporter_password_versionfor the environment inmanaged.ymland merge. The provisioner writes a new password to the<environment>-exporter-passwordsecret. -
Straight after the apply, open a
psqlsession 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 andexecinto it (step 4). Get the new password from${EXPORTER_SECRET}with the command in step 5. -
The role and its
pg_monitormembership 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_exporterDo not run
CREATE ROLEor theGRANTagain. -
Leave the session with
\qand delete the pod, as in step 6. -
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.
Rotating the password
Section titled “Rotating the password”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
Section titled “Removing an instance”Removing an instance, or one of its environments, takes two MRs, because RDS deletion protection blocks the destroy while it is on:
- Set
prevent_db_deletion: falsefor the environment(s) you are removing, merge, and let the apply run. - In a follow-up MR, remove the entry (or the environment key) from
managed.ymltogether with therds_instancesreference inworkloads.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.
Troubleshooting
Section titled “Troubleshooting”-
The deploy fails with “did not find RDS configuration despite the application declaring Postgres”:
fairway.yamlhaspresence: REQUIREDbutdeployment.yamlhas nords_instance. Add it, or change the presence toOPTIONAL. -
The transactions, tuples, locks, or cache panels are empty but the instance panels work: the
runway_pg_exporterrole 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.