Upgrading Built-in PostgreSQL
The following doc contains detailed instructions for upgrading the built-in PostgreSQL databases. Via our postgresql-16
and postgresql-16-codeinsights
image entrypoint script. This doc assumes an admin is attempting to upgrade to Sourcegraph 6.0.0
from an older version (usually pre 5.10.0
) using one of our "deploy" repos. For more general info see Upgrading PostgreSQL.
WARNING: Upgrading the PostgreSQL database requires stopping your Sourcegraph deployment which will result in downtime.
Additionally, once the upgrade process is started via the database container, interrupting the container before the upgrade is complete could result in corrupting the underlying Postgres database. We strongly advise taking a backup before the upgrade.
Docker Compose
Docker compose supports standard and multi-version upgrades to Postgres 16 versions! However, if you prefer to upgrade your DBs independent of a Sourcegraph version upgrade see the following procedure.
- Bring down your containers
BASHdocker-compose down --remove-orphans
- Change the
image:
in yourdocker-compose.yaml
to the release ofpgsql
,codeinsights-db
, andcodeintel-db
. Or merge in changes from the tagged sourcegraph release you're planning to upgrade to. Example:
YAMLpgsql: container_name: pgsql image: 'index.docker.io/sourcegraph/postgresql-16:6.0.0' ... codeintel-db: container_name: codeintel-db image: 'index.docker.io/sourcegraph/postgresql-16:6.0.0' ... codeinsights-db: container_name: codeintel-db image: 'index.docker.io/sourcegraph/postgresql-16-codeinsights:6.0.0'
- Bring up your deployments
BASHdocker-compose up -d pgsql codeintel-db codeinsights-db
Wait for the database containers to come up healthy. If for some reason the database containers fail to come up healthy, please check their logs and reach out to us for support at [email protected].
Kubernetes Kustomize
Kubernetes Kustomize supports standard and multi-version upgrades to Postgres 16 versions! However, if you prefer to upgrade your DBs independent of a Sourcegraph version upgrade see the following procedure.
- Disable Connections to the Database:
- The following services must have their replicas scaled to 0:
- Deployments (e.g.,
kubectl scale deployment <name> --replicas=0
)- precise-code-intel-worker
- repo-updater
- searcher
- sourcegraph-frontend
- sourcegraph-frontend-internal
- symbols
- worker
- Stateful sets (e.g.,
kubectl scale sts <name> --replicas=0
):- gitserver
- indexed-search convenience command:
- Deployments (e.g.,
- The following services must have their replicas scaled to 0:
SH$ kubectl scale deployment precise-code-intel-worker repo-updater searcher sourcegraph-frontend sourcegraph-frontend-internal symbols worker --replicas=0 && kubectl scale sts gitserver indexed-search --replicas=0
- Update base files for the database statefulSets:
- Update the
image
field in yourpgsql
,codeintel-db
andcodeinsights-db
StatefulSets tosourcegraph/postgresql-16:6.0.0
andsourcegraph/codeinsights-db:6.0.0
respectively. Example:
YAML# deploy-sourcegraph-k8s/base/sourcegraph/codeinsights-db/codeinsights-db.StatefulSet.yaml containers: - name: codeinsights image: index.docker.io/sourcegraph/postgresql-16-codeinsights:6.0.0 # deploy-sourcegraph-k8s/base/sourcegraph/codeintel-db/codeintel-db.StatefulSet.yaml containers: - name: pgsql image: index.docker.io/sourcegraph/postgresql-16:6.0.0 # deploy-sourcegraph-k8s/base/sourcegraph/pgsql/pgsql.StatefulSet.yaml containers: - name: pgsql image: index.docker.io/sourcegraph/postgresql-16:6.0.0
- Apply the new container images to the database statefulsets:
SH$ kubectl apply -f deploy-sourcegraph-k8s/base/sourcegraph/pgsql/pgsql.StatefulSet.yaml deploy-sourcegraph-k8s/base/sourcegraph/codeintel-db/codeintel-db.StatefulSet.yaml deploy-sourcegraph-k8s/base/sourcegraph/codeinsights-db/codeinsights-db.StatefulSet.yaml
- Wait until the containers come up, and complete their migration to Postgresql 16
Helm
To upgrade builtin containers in Helm admins must update their instance to v5.11.6271 via the helm multi-version upgrade procedure or standard upgrade procedure. This is because helm upgrade
doesn't support just the DBs in a chart.
upgrade
command.