Skip to content

Commit 98cae7d

Browse files
authored
chore(rel): add postgres collation mismatch to docs (#1168)
Add docs for Postgres collation mismatch known issue. Docs include release notes warnings and links to resolutions page as well as the resolutions page itself.
1 parent efe4435 commit 98cae7d

6 files changed

Lines changed: 331 additions & 0 deletions

File tree

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
# PostgreSQL Collation Version Mismatch Resolution
2+
3+
# Issue Summary
4+
5+
Customers whom initially deployed Sourcegraph versions prior to v6.2.2553 using the Sourcegraph provided PostgreSQL containers may encounter PostgreSQL collation version mismatch warnings after upgrading to more recent Sourcegraph versions due to an underlying glibc version update.
6+
7+
# Impact
8+
9+
Mismatched collation versions can lead to database index corruption if left unchecked.
10+
11+
# Affected Services
12+
13+
* `pgsql` container
14+
* `codeintel-db` container
15+
* `codeinsights-db` container
16+
17+
Only self-hosted customers using the Sourcegraph provided PostgreSQL container images are affected.
18+
19+
Self-hosted customers using external databases, such as AWS RDS, GCP CloudSQL, or another self-managed solution are **NOT** affected.
20+
21+
Sourcegraph Cloud customers are not affected.
22+
23+
# Symptoms
24+
25+
When logging into the database via `psql` or similar tools you may see the following warning:
26+
27+
```shell
28+
WARNING: database "sg" has a collation version mismatch DETAIL: The database was created using collation version 2.40, but the operating system provides version 2.41.
29+
```
30+
31+
# Backup Instructions (Required Before Proceeding)
32+
33+
Before performing any reindexing operations, it is critical to back up your data to prevent potential data loss. Use the method applicable to your deployment and your current environment.
34+
35+
Docker example:
36+
37+
```
38+
docker exec -t <database-container-name> pg_dumpall -U sg > backup_<container>.sql
39+
```
40+
41+
# Resolution Steps
42+
43+
Each affected database requires a reindex to be performed. This requires downtime, and should be done in the next available maintenance window.
44+
45+
Before reindexing, check the current collation versions. Run the following SQL to compare current and OS collation versions:
46+
47+
```
48+
SELECT
49+
datname,
50+
datcollversion,
51+
pg_database_collation_actual_version(oid) AS current_os_version
52+
FROM pg_database;
53+
```
54+
55+
`datcollversion` should not match `current_os_version`
56+
57+
## Docker Compose deployments
58+
59+
1. Stop all Sourcegraph containers
60+
61+
```
62+
docker compose down
63+
```
64+
65+
2. Start only the database containers
66+
67+
```
68+
docker compose up pgsql codeinsights-db codeintel-db -d
69+
```
70+
71+
3. Access each database container
72+
73+
```
74+
docker exec -it <database-container-name> bash
75+
```
76+
77+
4. Reindex the databases in the container
78+
79+
```
80+
reindexdb --no-password --username sg --verbose --echo --system
81+
reindexdb --no-password --username sg --verbose --echo --all
82+
```
83+
84+
5. Refresh the collation version for each database
85+
86+
```
87+
psql --no-password --username "sg" --tuples-only -c "SELECT 'ALTER DATABASE ' || datname || ' REFRESH COLLATION VERSION;' FROM pg_database WHERE datname != 'template0';" | psql --no-password --username "sg"
88+
```
89+
90+
\* For the above commands, replace `sg` with your custom username if one was configured in your environment.
91+
\*\* For the `codeinsights-db` container, the default username is `postgres` instead of `sg`.
92+
93+
Repeat steps 3 through 5 with all containers:
94+
95+
* `pgsql` container
96+
* `codeintel-db` container
97+
* `codeinsights-db` container
98+
99+
Once this is complete, you may start your Sourcegraph deployment
100+
101+
```
102+
docker compose up -d
103+
```
104+
105+
## Helm Deployments
106+
107+
1. Stop all non-database Sourcegraph pods (assuming a namespace of `sourcegraph`)
108+
109+
```
110+
kubectl get -n sourcegraph deploy --no-headers | awk '{print $1}' | xargs -n 1 -P 8 -I % kubectl -n sourcegraph scale deployment % --replicas=0
111+
```
112+
113+
```
114+
kubectl -n sourcegraph get sts --selector 'app.kubernetes.io/component!=codeinsights-db,app.kubernetes.io/component!=codeintel-db,app.kubernetes.io/component!=pgsql' --no-headers | awk '{print $1}' | xargs -n 1 -P 8 -I % kubectl -n sourcegraph scale sts % --replicas=0
115+
```
116+
117+
2. Access each database pod
118+
119+
```
120+
kubectl exec -it <database-pod-name> -n sourcegraph -- /bin/sh
121+
```
122+
123+
3. Reindex the databases in the container
124+
125+
```
126+
reindexdb --no-password --username sg --verbose --echo --system
127+
reindexdb --no-password --username sg --verbose --echo --all
128+
```
129+
130+
4. Refresh the collation version for each database
131+
132+
```
133+
psql --no-password --username "sg" --tuples-only -c "SELECT 'ALTER DATABASE ' || datname || ' REFRESH COLLATION VERSION;' FROM pg_database WHERE datname != 'template0';" | psql --no-password --username "sg"
134+
```
135+
136+
\* For the above commands, replace `sg` with your custom username if one was configured in your environment.
137+
\*\* For the `codeinsights-db` container, the default username is `postgres` instead of `sg`.
138+
139+
Repeat steps 2 through 4 with all pods:
140+
141+
* `pgsql-0` pod
142+
* `codeintel-db-0` pod
143+
* `codeinsights-db-0` pod
144+
145+
Once this is complete, you may start your Sourcegraph deployment, for example
146+
147+
```
148+
helm upgrade -n sourcegraph <your-helm-charts>
149+
```
150+
151+
## Kustomize Deployments
152+
153+
1. Stop all non-database Sourcegraph pods (assuming a namespace of `sourcegraph`). In your cluster Kustomization file (`instances/my-sourcegraph/kustomize.yaml`), uncomment the [multi-version-upgrade util](https://github.com/sourcegraph/deploy-sourcegraph-k8s/blob/main/instances/template/kustomization.template.yaml#L155). This will scale down all non-database deployments and statefulSets replicas to 0\.
154+
155+
```
156+
# - ../../components/utils/uid # -- Run all Postgres database with valid users on host
157+
- ../../components/utils/multi-version-upgrade # -- Scale down non-database pods to 0 for multi-version upgrade
158+
# - ../../components/utils/migrate-to-nonprivileged # -- Component for migrating from privileged to non-privileged
159+
#
160+
```
161+
162+
2. Generate and apply a new \`cluster.yaml\` file
163+
164+
```
165+
kubectl kustomize instances/my-sourcegraph -o cluster.yaml
166+
kubectl apply --prune -l deploy=sourcegraph -f cluster.yaml
167+
```
168+
169+
3. Access each database pod
170+
171+
```
172+
kubectl exec -it <database-pod-name> -n sourcegraph -- /bin/sh
173+
```
174+
175+
4. Reindex the databases in the container
176+
177+
```
178+
reindexdb --no-password --username sg --verbose --echo --system
179+
reindexdb --no-password --username sg --verbose --echo --all
180+
```
181+
182+
5. Refresh the collation version for each database
183+
184+
```
185+
psql --no-password --username "sg" --tuples-only -c "SELECT 'ALTER DATABASE ' || datname || ' REFRESH COLLATION VERSION;' FROM pg_database WHERE datname != 'template0';" | psql --no-password --username "sg"
186+
```
187+
188+
\* For the above commands, replace `sg` with your custom username if one was configured in your environment.
189+
\*\* For the `codeinsights-db` container, the default username is `postgres` instead of `sg`.
190+
191+
Repeat steps 3 through 5 with all pods:
192+
193+
* `pgsql-0` pod
194+
* `codeintel-db-0` pod
195+
* `codeinsights-db-0` pod
196+
197+
Once this is complete, you may start your Sourcegraph deployment.
198+
199+
Comment out the [multi-version-upgrade util](https://github.com/sourcegraph/deploy-sourcegraph-k8s/blob/main/instances/template/kustomization.template.yaml#L155) in your cluster Kustomization file (`instances/my-sourcegraph/kustomize.yaml`).
200+
201+
```
202+
# - ../../components/utils/uid # -- Run all Postgres database with valid users on host
203+
# - ../../components/utils/multi-version-upgrade # -- Scale down non-database pods to 0 for multi-version upgrade
204+
# - ../../components/utils/migrate-to-nonprivileged # -- Component for migrating from privileged to non-privileged
205+
```
206+
207+
Generate and apply a new \`cluster.yaml\` file
208+
209+
```
210+
kubectl kustomize instances/my-sourcegraph -o cluster.yaml
211+
kubectl apply --prune -l deploy=sourcegraph -f cluster.yaml
212+
```
213+
214+
## AMI/Machine Image based deployments
215+
216+
Our AMI and GCP machine image deployments run Kubernetes internally, and thus follow the same general directions as our Helm Deployments described above.
217+
218+
To access the deployment you must SSH into your AMI/Machine image first.
219+
220+
* For AWS AMIs, the default username is `ec2-user`
221+
* For GCP machine images, the default username is `sourcegraph`
222+
223+
Follow the directions laid out in the Helm Deployments section.
224+
225+
# Expected Downtime
226+
227+
* Reindexing may take 15-60 minutes in most cases, but depends on the database size, disk speed, and available CPU/RAM
228+
* For customers with larger databases \- greater than 100Gb \- or low resource allocation, reindexing may take longer
229+
230+
# Verification
231+
232+
Check that warnings no longer appear when connecting to the database:
233+
234+
```
235+
psql --no-password --username "$PGUSER" -d sg
236+
```
237+
238+
After Reindexing: Verify Collation Version:
239+
240+
```
241+
SELECT
242+
datname,
243+
datcollversion,
244+
pg_database_collation_actual_version(oid) AS current_os_version
245+
FROM pg_database;
246+
```
247+
248+
Ensure `datcollversion` matches `current_os_version` for all databases listed.
249+
250+
# Questions?
251+
252+
Contact Sourcegraph Support ([support@sourcegraph.com](mailto:support@sourcegraph.com)) if you encounter issues during this process.

docs/admin/updates/docker_compose.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@ For upgrade procedures or general info about sourcegraph versioning see the link
1111
>
1212
> ***If the notes indicate a patch release exists, target the highest one.***
1313
14+
## v6.2.2553
15+
16+
### Known issues
17+
18+
Customers running Sourcegraph versions prior to v6.2.2553 and using the Sourcegraph provided PostgreSQL containers may encounter PostgreSQL collation version mismatch warnings after upgrading to more recent Sourcegraph versions due to an underlying glibc version update.
19+
20+
When logging into the database via psql or similar tools you may see the following warning:
21+
22+
```shell
23+
WARNING: database "sg" has a collation version mismatch DETAIL: The database was created using collation version 2.40, but the operating system provides version 2.41.
24+
```
25+
26+
Mismatched collation versions can lead to database index corruption if left unchecked.
27+
28+
Affected Services
29+
- pgsql container
30+
- codeintel-db container
31+
- codeinsights-db container
32+
33+
Only self-hosted customers using the Sourcegraph provided PostgreSQL container images are affected.
34+
35+
Self-hosted customers using external databases, such as AWS RDS, GCP CloudSQL, or another self-managed solution are NOT affected.
36+
37+
See our [PostgreSQL Collation Version Mismatch Resolution](/admin/postgresql_collation_version_mismatch_resolution) notes for more details.
38+
1439
## v6.0.0
1540

1641
- Sourcegraph 6.0.0 no longer supports PostgreSQL 12, admins must upgrade to PostgreSQL 16. See our [postgres 12 end of life](/admin/postgres12_end_of_life_notice) notice! As well as [supporting documentation](/admin/postgres) and advisements on how to upgrade.

docs/admin/updates/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ If your instance has schema drift or unfinished oob migrations you may need to a
126126
- [**Sourcegraph AWS AMI instances**](/admin/deploy/machine-images/aws-ami#upgrade)
127127

128128
## Other helpful links
129+
- [PostgreSQL Collation Version Mismatch Resolution](/admin/postgresql_collation_version_mismatch_resolution)
129130
- [Postgres 12 End Of Life Notice](/admin/postgres12_end_of_life_notice)
130131
- [Migrator operations](/admin/updates/migrator/migrator-operations)
131132
- [Upgrading Early Versions](/admin/updates/migrator/upgrading-early-versions)

docs/admin/updates/kubernetes.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ For upgrade procedures or general info about sourcegraph versioning see the link
1717
- The repo-updater service is no longer needed and will be removed from deployment methods going forward.
1818
- The symbols service and searcher service have been merged and symbols will be removed from deployment methods going forward. Consider moving env vars set on symbols to the searcher deployment before upgrading and reallocating resources from symbols to searcher.
1919

20+
## v6.2.2553
21+
22+
### Known issues
23+
24+
Customers running Sourcegraph versions prior to v6.2.2553 and using the Sourcegraph provided PostgreSQL containers may encounter PostgreSQL collation version mismatch warnings after upgrading to more recent Sourcegraph versions due to an underlying glibc version update.
25+
26+
When logging into the database via psql or similar tools you may see the following warning:
27+
28+
```shell
29+
WARNING: database "sg" has a collation version mismatch DETAIL: The database was created using collation version 2.40, but the operating system provides version 2.41.
30+
```
31+
32+
Mismatched collation versions can lead to database index corruption if left unchecked.
33+
34+
Affected Services
35+
- pgsql container
36+
- codeintel-db container
37+
- codeinsights-db container
38+
39+
Only self-hosted customers using the Sourcegraph provided PostgreSQL container images are affected.
40+
41+
Self-hosted customers using external databases, such as AWS RDS, GCP CloudSQL, or another self-managed solution are NOT affected.
42+
43+
See our [PostgreSQL Collation Version Mismatch Resolution](/admin/postgresql_collation_version_mismatch_resolution) notes for more details.
44+
2045
## v6.0.0
2146

2247
- Sourcegraph 6.0.0 no longer supports PostgreSQL 12, admins must upgrade to PostgreSQL 16. See our [postgres 12 end of life](/admin/postgres12_end_of_life_notice) notice! As well as [supporting documentation](/admin/postgres) and advisements on how to upgrade.

docs/admin/updates/pure_docker.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,31 @@ Each section comprehensively describes the changes needed in Docker images, envi
99

1010
## Unreleased
1111

12+
## v6.2.2553
13+
14+
### Known issues
15+
16+
Customers running Sourcegraph versions prior to v6.2.2553 and using the Sourcegraph provided PostgreSQL containers may encounter PostgreSQL collation version mismatch warnings after upgrading to more recent Sourcegraph versions due to an underlying glibc version update.
17+
18+
When logging into the database via psql or similar tools you may see the following warning:
19+
20+
```shell
21+
WARNING: database "sg" has a collation version mismatch DETAIL: The database was created using collation version 2.40, but the operating system provides version 2.41.
22+
```
23+
24+
Mismatched collation versions can lead to database index corruption if left unchecked.
25+
26+
Affected Services
27+
- pgsql container
28+
- codeintel-db container
29+
- codeinsights-db container
30+
31+
Only self-hosted customers using the Sourcegraph provided PostgreSQL container images are affected.
32+
33+
Self-hosted customers using external databases, such as AWS RDS, GCP CloudSQL, or another self-managed solution are NOT affected.
34+
35+
See our [PostgreSQL Collation Version Mismatch Resolution](/admin/postgresql_collation_version_mismatch_resolution) notes for more details.
36+
1237
## v5.2.6 ➔ v5.2.7
1338

1439
As a template, perform the same actions as the following diff in your own deployment: [`Upgrade to v5.2.7`](https://github.com/sourcegraph/deploy-sourcegraph-docker/compare/v5.2.6...v5.2.7)

docs/technical-changelog.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,9 @@ Revert "[Backport 6.2.x] fix(agents): filter out empty diagnostic paths" `(PR #4
10101010

10111011
- [kustomize](https://github.com/sourcegraph/deploy-sourcegraph-k8s/releases/tag/v6.2.2553)
10121012

1013+
> Attention - This patch contains a known issue for self-hosted customers upgrading from previous versions of Sourcegraph whom are using the Sourcegraph provided PostgreSQL container images.
1014+
> Please see our [PostgreSQL Collation Version Mismatch Resolution](/admin/postgresql_collation_version_mismatch_resolution) notes for more details.
1015+
10131016
### Features
10141017

10151018
#### Source

0 commit comments

Comments
 (0)