KKIMS on-site docs
Your workstation

Database tools (psql)

Install the PostgreSQL 18 client (psql) on Linux, macOS and Windows, and reach the private RDS database from a pod inside the cluster or through a Session Manager bastion, with useful read-only queries.

You will rarely need to query the database by hand: the CMS, the migrate Job and the load pod do the work. psql is for checking (did the migrations run, did the content load, what is the latest site build) and for diagnosing a stuck job. Treat the production database as read-only from psql unless a page tells you otherwise.

The RDS database is private: it has no public address and its security group allows only the EKS nodes and the Jenkins agent. So a psql on your laptop cannot reach it directly. Three ways in, in order of preference:

  1. A psql pod inside the cluster, using the same Secret as the CMS. Needs only kubectl access to the namespace. No psql install needed on your laptop.
  2. Through a bastion with Session Manager, if KIMS has a managed EC2 instance in the VPC. Needs psql on your laptop.
  3. KIMS's own way (a VPN into the VPC, a jump host), if they have one.

#Install the psql client

Use the PostgreSQL 18 client to match RDS (a newer client also works against an 18 server; an older one mostly works but warns and may lack features).

Ubuntu or Debian, from the PostgreSQL project's own repository (PGDG), client only:

bash
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install -y postgresql-client-18

The second command asks you to press Enter to add the repository.

RHEL 9, Rocky 9, Alma 9 (x86_64; use EL-9-aarch64 on arm64, EL-8-... on version 8):

bash
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql18

psql is then at /usr/pgsql-18/bin/psql (and usually linked as psql).

Fedora 43 and later ship PostgreSQL 18 in their own repository: sudo dnf install -y postgresql.

Amazon Linux 2023 is not covered by the PGDG repository. Run dnf list --available 'postgresql*' and install the highest client version offered, or use psql in Docker.

bash
brew install postgresql@18
echo 'export PATH="$(brew --prefix postgresql@18)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

This installs the whole PostgreSQL 18, but nothing runs unless you start it (brew services start): you only use its psql. postgresql@18 is keg-only, hence the PATH line.

The lighter alternative is brew install libpq (client only), but it tracks the newest PostgreSQL (19 in November 2026). A 19 psql works against an 18 server. It is also keg-only: add $(brew --prefix libpq)/bin to PATH the same way.

The PostgreSQL 18 installer from EDB includes the client:

powershell
winget install -e --id PostgreSQL.PostgreSQL.18

This installs the PostgreSQL 18 server as well, as a Windows service. If you only want the client, run the EDB installer by hand instead (https://www.postgresql.org/download/windows/), and on "Select Components" tick only Command Line Tools. If the server was installed, you can stop and disable it: Stop-Service postgresql-x64-18; Set-Service postgresql-x64-18 -StartupType Disabled in an Administrator PowerShell.

psql is at C:\Program Files\PostgreSQL\18\bin\psql.exe. Add that folder to your user PATH (Settings, System, About, Advanced system settings, Environment Variables), then open a new window.

The Windows console shows a warning about the code page (Console code page (437) differs from Windows code page (1252)). Run chcp 1252 first, or ignore it: it only affects accented characters.

#Check

text
psql --version

You should see psql (PostgreSQL) 18.x (or 19.x with libpq).

#psql in Docker, on any system

If you have Docker and do not want to install anything, the official image has psql:

text
docker run --rm -it postgres:18 psql --version

You should see psql (PostgreSQL) 18.x. Replace psql --version with any psql command; to reach a port forwarded on your laptop use the host host.docker.internal instead of localhost (Docker Desktop on macOS and Windows; on Linux add --add-host host.docker.internal:host-gateway).

#A psql pod inside the cluster

The pod runs in the environment's namespace, reads the connection string from the kims-database Secret (so the password never touches your laptop), and reaches RDS the same way the CMS does.

#1. Save the pod spec

Save this as kims-psql-pod.yaml (as UTF-8; see Which shell to use). It meets the Kubernetes restricted Pod Security standard and deletes itself after an hour if forgotten.

yaml
apiVersion: v1
kind: Pod
metadata:
  name: kims-psql
  labels:
    app.kubernetes.io/name: kims
    app.kubernetes.io/component: psql
spec:
  restartPolicy: Never
  activeDeadlineSeconds: 3600
  automountServiceAccountToken: false
  securityContext:
    runAsNonRoot: true
    runAsUser: 999
    runAsGroup: 999
    seccompProfile:
      type: RuntimeDefault
  containers:
    - name: psql
      image: postgres:18
      command: ["sleep", "3600"]
      env:
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: kims-database
              key: url
        - name: HOME
          value: /tmp
      securityContext:
        allowPrivilegeEscalation: false
        readOnlyRootFilesystem: true
        capabilities:
          drop: ["ALL"]
      volumeMounts:
        - name: tmp
          mountPath: /tmp
      resources:
        requests: { cpu: 50m, memory: 64Mi }
        limits: { cpu: 500m, memory: 256Mi }
  volumes:
    - name: tmp
      emptyDir: {}

999 is the postgres user inside the official image.

Note

The cluster's nodes must be able to pull postgres:18 from Docker Hub. If KIMS's nodes can only pull from their registry, copy the image there once and change image: to <REGISTRY>/postgres:18: docker pull --platform linux/amd64 postgres:18, docker tag postgres:18 <REGISTRY>/postgres:18, docker push <REGISTRY>/postgres:18 (after logging in to the registry, and creating a postgres repository if it is ECR; use linux/arm64 for arm64 nodes).

#2. Start it and connect

Use the environment's namespace (kims for production, kims-uat for UAT). These lines are the same in every shell:

text
kubectl -n kims apply -f kims-psql-pod.yaml
kubectl -n kims wait --for=condition=Ready pod/kims-psql --timeout=120s
kubectl -n kims exec -it kims-psql -- sh -c 'exec psql $DATABASE_URL'

You should see pod/kims-psql created, pod/kims-psql condition met, then:

text
psql (18.x)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: postgresql)
Type "help" for help.

kims=>

The SSL connection line confirms TLS. Type \q to leave.

($DATABASE_URL is deliberately unquoted inside sh -c: the connection string has no spaces, and leaving out the inner quotes keeps the command identical in PowerShell 5.1, which would otherwise mangle them.)

#3. Delete it when done

text
kubectl -n kims delete pod kims-psql

#Through a bastion with Session Manager

Only if KIMS has an EC2 instance in the database's VPC that is managed by Systems Manager, that may reach RDS on 5432, and they give your IAM identity ssm:StartSession on it. You need the AWS CLI signed in and the Session Manager plugin.

#1. Open the tunnel

This forwards port 15432 on your laptop to RDS's 5432 through the instance. Leave the window open while you work.

bash
aws ssm start-session --region <REGION> --target <INSTANCE_ID> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters '{"host":["<RDS_ENDPOINT>"],"portNumber":["5432"],"localPortNumber":["15432"]}'
bash
aws ssm start-session --region <REGION> --target <INSTANCE_ID> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters '{"host":["<RDS_ENDPOINT>"],"portNumber":["5432"],"localPortNumber":["15432"]}'
powershell
aws ssm start-session --region <REGION> --target <INSTANCE_ID> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters "host=<RDS_ENDPOINT>,portNumber=5432,localPortNumber=15432"

You should see Port 15432 opened for sessionId ... and Waiting for connections....

#2. Connect

In a second window:

text
psql "host=localhost port=15432 dbname=kims user=kims sslmode=require"

psql asks for the password: type or paste it (nothing shows). It never enters your shell history this way. Use sslmode=require, not verify-full: the certificate names the RDS endpoint, not localhost.

Close the tunnel with Ctrl+C in the first window.

#Verifying the server certificate (optional)

sslmode=require encrypts the connection but does not check who answers. On a direct connection to the endpoint (from a pod, or on a VPN), sslmode=verify-full with AWS's certificate bundle checks it too:

text
curl -fsSLo rds-global-bundle.pem https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem

then add &sslrootcert=rds-global-bundle.pem and change sslmode=require to sslmode=verify-full. The CMS uses sslmode=require, as the runbook sets it.

#Useful read-only queries

Run these at the kims=> prompt. Each ends with ;.

#Have the migrations run?

sql
select count(*) from schema_migrations;

8 at hand-over (one per file in db/migrations/, from 0001_foundation.sql to 0501_site_builds_jenkins_number.sql). relation "schema_migrations" does not exist means the migrate Job has not run.

#Is the content loaded?

sql
select count(*) from published_files;
select max(version) from publish_versions;

After the data bundle load: 2750 and 1. Both 0 (or null) means not loaded yet.

#The latest site builds

sql
select number, publish_version, cause, status, stage, queued_at, finished_at
from site_builds order by number desc limit 5;

status is queued, running, succeeded, failed, aborted or skipped.

#The job queue

sql
select kind, status, count(*) from jobs group by kind, status order by kind, status;

Many queued rows that never move means the worker is not running or cannot claim. Failed jobs keep their error:

sql
select kind, attempts, last_error, updated_at from jobs where status = 'failed' order by updated_at desc limit 10;

#Who is connected

sql
select application_name, state, count(*) from pg_stat_activity where datname = 'kims' group by 1, 2;

Each process names itself through KIMS_PROCESS_NAME: cms, worker, cron:<task>, migrate, site-build, data-bundle.

#If it goes wrong

What you see Cause Fix
psql: command not found / not recognized Not on PATH (keg-only on macOS; Program Files on Windows) Add the bin folder to PATH, open a new window
Pod stuck in ErrImagePull / ImagePullBackOff Nodes cannot pull from Docker Hub Mirror the image to KIMS's registry (note above)
Error from server (Forbidden): pods "kims-psql" is forbidden: violates PodSecurity "restricted:latest" The namespace enforces restricted and the spec was changed Use the spec as given; do not remove the securityContext lines
CreateContainerConfigError and secret "kims-database" not found Wrong namespace, or Secrets not created yet -n kims-uat for UAT; Kubernetes Secrets
connection to server at "..." port 5432 failed: Connection timed out Security group does not allow the pods or the bastion RDS PostgreSQL security group rules
FATAL: no pg_hba.conf entry for host ... no encryption Connected without TLS; RDS requires it Add sslmode=require
FATAL: password authentication failed for user "kims" Wrong password in the Secret, or a special character not URL-encoded in the connection string Recreate the Secret with the password percent-encoded (@ as %40, : as %3A, / as %2F, # as %23)
SessionManagerPlugin is not found Plugin missing Install it
An error occurred (TargetNotConnected) The instance is not managed by SSM, or is stopped Ask KIMS for a managed instance
server certificate for "..." does not match host name "localhost" verify-full through a tunnel Use sslmode=require through tunnels

#Sources

Built 2026-11-29. Commands are shown for the system picked at the top; every block has all three.