This guide helps you migrate from deprecated configuration fields to their current replacements. Deprecated fields continue to work but will be removed in future versions.
StackGres occasionally deprecates fields when better alternatives are introduced. This ensures:
Recommendation: Migrate to new fields as soon as possible to avoid issues during future upgrades.
| Resource | Deprecated Field | Replacement | Removed In |
|---|---|---|---|
| SGCluster | spec.pods.disableMetricsExporter |
spec.configurations.observability.disableMetrics |
Future |
| SGCluster | spec.initialData.scripts |
spec.managedSql with SGScript |
Future |
| SGCluster | spec.initialData.restore.fromBackup.uid |
spec.initialData.restore.fromBackup.name |
Future |
| SGShardedCluster | spec.shards |
spec.workers |
Future |
| SGShardedCluster | spec.postgresServices.shards |
spec.postgresServices.workers |
Future |
| SGShardedCluster | spec.metadata.annotations.shardsPrimariesService |
spec.metadata.annotations.workersPrimariesService |
Future |
| SGShardedCluster | spec.metadata.labels.shardsPrimariesService |
spec.metadata.labels.workersPrimariesService |
Future |
The spec.pods.disableMetricsExporter field has been moved to the observability configuration section for better organization.
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: my-cluster
spec:
instances: 3
postgres:
version: '16'
pods:
persistentVolume:
size: '50Gi'
disableMetricsExporter: true # DEPRECATED
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: my-cluster
spec:
instances: 3
postgres:
version: '16'
pods:
persistentVolume:
size: '50Gi'
configurations:
observability:
disableMetrics: true # New location
Identify clusters using deprecated field:
kubectl get sgcluster -A -o yaml | grep -B20 "disableMetricsExporter: true"
Update cluster spec:
kubectl edit sgcluster my-cluster
Remove spec.pods.disableMetricsExporter and add spec.configurations.observability.disableMetrics.
Verify configuration:
kubectl get sgcluster my-cluster -o jsonpath='{.spec.configurations.observability}'
The new location provides more observability settings:
configurations:
observability:
disableMetrics: true
prometheusAutobind: false
receiver: my-otel-receiver # OpenTelemetry Collector
The spec.initialData.scripts field has been replaced by the more powerful managedSql system with SGScript resources.
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: my-cluster
spec:
instances: 3
postgres:
version: '16'
pods:
persistentVolume:
size: '50Gi'
initialData:
scripts: # DEPRECATED
- name: create-database
script: |
CREATE DATABASE myapp;
- name: create-user
scriptFrom:
secretKeyRef:
name: db-credentials
key: create-user.sql
Step 1: Create an SGScript resource:
apiVersion: stackgres.io/v1
kind: SGScript
metadata:
name: my-cluster-init
spec:
scripts:
- name: create-database
script: |
CREATE DATABASE myapp;
- name: create-user
scriptFrom:
secretKeyRef:
name: db-credentials
key: create-user.sql
Step 2: Reference the SGScript in the cluster:
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: my-cluster
spec:
instances: 3
postgres:
version: '16'
pods:
persistentVolume:
size: '50Gi'
managedSql:
scripts:
- sgScript: my-cluster-init
Export existing scripts:
kubectl get sgcluster my-cluster -o jsonpath='{.spec.initialData.scripts}' > scripts.json
Create SGScript resource:
apiVersion: stackgres.io/v1
kind: SGScript
metadata:
name: my-cluster-init
spec:
scripts:
# Convert your scripts here
Apply SGScript:
kubectl apply -f sgscript.yaml
Update cluster to use managedSql:
kubectl patch sgcluster my-cluster --type=merge -p '
spec:
managedSql:
scripts:
- sgScript: my-cluster-init
'
Remove deprecated field (after verifying scripts work):
kubectl patch sgcluster my-cluster --type=json -p '[
{"op": "remove", "path": "/spec/initialData/scripts"}
]'
The new managedSql system provides:
continueOnSGScriptError and continueOnError optionsWith managedSql, you can track script execution:
kubectl get sgcluster my-cluster -o jsonpath='{.status.managedSql}' | jq
Example output:
{
"scripts": [
{
"id": 0,
"startedAt": "2024-01-15T10:00:00Z",
"completedAt": "2024-01-15T10:00:05Z",
"scripts": [
{"id": 0, "version": 1},
{"id": 1, "version": 1}
]
}
]
}
The spec.initialData.restore.fromBackup.uid field is deprecated in favor of name.
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: restored-cluster
spec:
initialData:
restore:
fromBackup:
uid: a1b2c3d4-e5f6-7890-abcd-ef1234567890 # DEPRECATED
apiVersion: stackgres.io/v1
kind: SGCluster
metadata:
name: restored-cluster
spec:
initialData:
restore:
fromBackup:
name: my-backup # Use backup name instead
Find backup name from UID:
kubectl get sgbackup -A -o custom-columns='NAME:.metadata.name,UID:.metadata.uid'
Update cluster spec to use name instead of uid.
Since StackGres 1.19.0 the SGShardedCluster CRD version has been bumped to stackgres.io/v1beta1 and the shards concept has been renamed to workers. The following fields have been renamed:
spec.shards is now spec.workersspec.postgresServices.shards is now spec.postgresServices.workersspec.metadata.annotations.shardsPrimariesService is now spec.metadata.annotations.workersPrimariesServicespec.metadata.labels.shardsPrimariesService is now spec.metadata.labels.workersPrimariesServiceThe deprecated fields continue to work but will be removed together with the stackgres.io/v1alpha1 version in a future release.
Also, the service exposing the primaries of the workers is now named after the SGShardedCluster name plus the -workers suffix (previously the -shards suffix). The service with the -shards suffix is still created for backward compatibility but applications should migrate their connection configuration to the -workers service.
apiVersion: stackgres.io/v1alpha1
kind: SGShardedCluster
metadata:
name: my-sharded-cluster
spec:
type: citus
database: mydatabase
postgres:
version: '16'
coordinator:
instances: 2
pods:
persistentVolume:
size: '10Gi'
shards: # DEPRECATED
clusters: 4
instancesPerCluster: 2
pods:
persistentVolume:
size: '10Gi'
postgresServices:
shards: # DEPRECATED
primaries:
enabled: true
metadata:
annotations:
shardsPrimariesService: # DEPRECATED
my-annotation: my-value
apiVersion: stackgres.io/v1beta1
kind: SGShardedCluster
metadata:
name: my-sharded-cluster
spec:
type: citus
database: mydatabase
postgres:
version: '16'
coordinator:
instances: 2
pods:
persistentVolume:
size: '10Gi'
workers: # New name
clusters: 4
instancesPerCluster: 2
pods:
persistentVolume:
size: '10Gi'
postgresServices:
workers: # New name
primaries:
enabled: true
metadata:
annotations:
workersPrimariesService: # New name
my-annotation: my-value
Identify sharded clusters using deprecated fields:
kubectl get sgshardedcluster -A -o yaml | grep -E "^\s+(shards|shardsPrimariesService):"
Update sharded cluster spec:
kubectl edit sgshardedcluster my-sharded-cluster
Rename spec.shards to spec.workers, spec.postgresServices.shards to spec.postgresServices.workers and shardsPrimariesService to workersPrimariesService under spec.metadata.annotations and spec.metadata.labels.
Update YAML manifests stored in your GitOps repositories to use apiVersion: stackgres.io/v1beta1 and the new field names.
Update applications connecting to the service with the -shards suffix to use the service with the -workers suffix.
Verify configuration:
kubectl get sgshardedcluster my-sharded-cluster -o jsonpath='{.spec.workers}'
Check all clusters for deprecated fields:
#!/bin/bash
echo "Checking for deprecated fields..."
for cluster in $(kubectl get sgcluster -A -o jsonpath='{range .items[*]}{.metadata.namespace}/{.metadata.name}{"\n"}{end}'); do
ns=$(echo $cluster | cut -d'/' -f1)
name=$(echo $cluster | cut -d'/' -f2)
# Check disableMetricsExporter
if kubectl get sgcluster -n $ns $name -o jsonpath='{.spec.pods.disableMetricsExporter}' 2>/dev/null | grep -q "true"; then
echo "[$ns/$name] Uses deprecated: spec.pods.disableMetricsExporter"
fi
# Check initialData.scripts
if kubectl get sgcluster -n $ns $name -o jsonpath='{.spec.initialData.scripts}' 2>/dev/null | grep -q "."; then
echo "[$ns/$name] Uses deprecated: spec.initialData.scripts"
fi
# Check fromBackup.uid
if kubectl get sgcluster -n $ns $name -o jsonpath='{.spec.initialData.restore.fromBackup.uid}' 2>/dev/null | grep -q "."; then
echo "[$ns/$name] Uses deprecated: spec.initialData.restore.fromBackup.uid"
fi
done
for cluster in $(kubectl get sgshardedcluster -A -o jsonpath='{range .items[*]}{.metadata.namespace}/{.metadata.name}{"\n"}{end}'); do
ns=$(echo $cluster | cut -d'/' -f1)
name=$(echo $cluster | cut -d'/' -f2)
# Check shards
if kubectl get sgshardedcluster -n $ns $name -o jsonpath='{.spec.shards}' 2>/dev/null | grep -q "."; then
echo "[$ns/$name] Uses deprecated: spec.shards"
fi
# Check postgresServices.shards
if kubectl get sgshardedcluster -n $ns $name -o jsonpath='{.spec.postgresServices.shards}' 2>/dev/null | grep -q "."; then
echo "[$ns/$name] Uses deprecated: spec.postgresServices.shards"
fi
# Check shardsPrimariesService
if kubectl get sgshardedcluster -n $ns $name -o jsonpath='{.spec.metadata.annotations.shardsPrimariesService}{.spec.metadata.labels.shardsPrimariesService}' 2>/dev/null | grep -q "."; then
echo "[$ns/$name] Uses deprecated: spec.metadata.annotations.shardsPrimariesService or spec.metadata.labels.shardsPrimariesService"
fi
done
The operator logs warnings when deprecated fields are used:
kubectl logs -n stackgres -l app=stackgres-operator | grep -i deprecated
Test migrations in non-production before applying to production clusters
Keep both fields temporarily during migration if supported
Document changes in your GitOps repositories
Monitor after migration to ensure functionality is preserved
Update automation scripts and Helm values that use deprecated fields