DocumentationNeuronDB Documentation
Documentation Branch: You are viewing documentation for the main branch (3.0.0-devel). Select a branch to view its documentation:

Upgrade and Rollback Guide

Upgrade and Rollback Guide

Complete procedures for upgrading and rolling back NeuronDB

Upgrade Status


[!WARNING] Always back up your database before upgrading. Test upgrades in a development environment first.


Pre-Upgrade Checklist

Pre-Upgrade Checklist
TaskCommandRequired
Review release notesCheck CHANGELOG.mdCritical
Backup databaseSee Backup GuideCritical
Verify current versionhelm list -n neurondbYes
Check migration statuskubectl get jobs -n neurondb | grep migrationYes
Ensure resourcesCheck cluster capacityYes
Review values.yamlCheck for deprecated optionsHigh

Upgrade Procedure

Step 1: Backup

# Ensure backup is recent
kubectl get cronjob neurondb-backup -n neurondb
kubectl create job --from=cronjob/neurondb-backup manual-backup-$(date +%s) -n neurondb

Step 2: Review Changes

# Dry-run upgrade
helm upgrade neurondb ./helm/neurondb \
  --version <new-version> \
  --dry-run --debug \
  -f values-production-external-postgres.yaml \
  -n neurondb

Step 3: Run Migrations

Migrations run automatically via pre-upgrade hooks. Monitor:

# Watch migration job
kubectl get jobs -n neurondb -w | grep migration
kubectl logs -f job/neurondb-migration-<revision> -n neurondb

Step 4: Upgrade Chart

helm upgrade neurondb ./helm/neurondb \
  --version <new-version> \
  -f values-production-external-postgres.yaml \
  -n neurondb

Step 5: Monitor Upgrade

# Watch pods
kubectl get pods -n neurondb -w

# Check rollout status (PostgreSQL/NeuronDB)
kubectl rollout status statefulset/neurondb-neurondb -n neurondb

# Check logs
kubectl logs -f statefulset/neurondb-neurondb -n neurondb

Step 6: Verify Upgrade

# Check versions
helm list -n neurondb
kubectl get pods -n neurondb -o jsonpath='{.items[*].spec.containers[*].image}'

# Test database and extension
kubectl port-forward svc/neurondb-neurondb 5432:5432 -n neurondb
# In another terminal:
psql -h localhost -p 5432 -U neurondb -d neurondb -c "SELECT neurondb.version();"

Rollback Procedure

Step 1: Identify Previous Revision

# List release history
helm history neurondb -n neurondb

# Note the revision number to rollback to

Step 2: Rollback Helm Release

# Rollback to previous revision
helm rollback neurondb <revision> -n neurondb

# Or rollback to previous version
helm rollback neurondb -n neurondb

Step 3: Database Rollback (if needed)

If database migrations were applied, rollback them:

# Connect to database
kubectl exec -it statefulset/neurondb-neurondb -n neurondb -- \
  psql -U neurondb -d neurondb

# Run rollback script (if provided)
\i /path/to/rollback.sql

Step 4: Verify Rollback

# Check pod versions
kubectl get pods -n neurondb -o jsonpath='{.items[*].spec.containers[*].image}'

# Verify database and extension
kubectl port-forward svc/neurondb-neurondb 5432:5432 -n neurondb
# In another terminal:
psql -h localhost -p 5432 -U neurondb -d neurondb -c "SELECT neurondb.version();"

Zero-Downtime Upgrades

StatefulSet Rolling Update

Configure update strategy:

neurondb:
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: null # Update all pods
maxUnavailable: 1

Canary Deployment

Gradual rollout using partition:

neurondb:
replicas: 3
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 2 # Only update pod 2 and 3

After verification, reduce partition:

helm upgrade neurondb ./helm/neurondb \
  --set neurondb.updateStrategy.rollingUpdate.partition=1 \
  -n neurondb

Migration Management

Check Migration Status

# View migration history
kubectl get jobs -n neurondb | grep migration

# Check database migration version
kubectl exec -it statefulset/neurondb-neurondb -n neurondb -- \
  psql -U neurondb -d neurondb -c \
  "SELECT version, name, applied_at FROM neurondb_agent.schema_migrations ORDER BY version DESC;"

Manual Migration

If automatic migration fails:

# Create migration job manually
kubectl create job --from=cronjob/neurondb-migration manual-migration -n neurondb

# Or run migration script directly
kubectl exec -it statefulset/neurondb-neurondb -n neurondb -- \
  psql -U neurondb -d neurondb -f /path/to/migration.sql

Troubleshooting

Upgrade Fails

  1. Check migration job:
kubectl describe job neurondb-migration-<revision> -n neurondb
kubectl logs job/neurondb-migration-<revision> -n neurondb
  1. Check pod status:
kubectl describe pod <pod-name> -n neurondb
kubectl logs <pod-name> -n neurondb
  1. Rollback if needed:
helm rollback neurondb -n neurondb

Migration Fails

  1. Check migration logs:
kubectl logs job/neurondb-migration-<revision> -n neurondb
  1. Fix migration issues and retry:
# Delete failed job
kubectl delete job neurondb-migration-<revision> -n neurondb

# Retry upgrade
helm upgrade neurondb ./helm/neurondb --version <version> -n neurondb

Rollback Fails

  1. Check release history:
helm history neurondb -n neurondb
  1. Manual rollback:
# Delete current resources
helm uninstall neurondb -n neurondb

# Reinstall previous version
helm install neurondb ./helm/neurondb \
  --version <previous-version> \
  -f values-production-external-postgres.yaml \
  -n neurondb

Best Practices

[!IMPORTANT] Follow these practices for safe upgrades.

Upgrade Best Practices
PracticeDescriptionPriority
Always backupBackup before upgradeCritical
Test in stagingTest upgrades in staging firstCritical
Review changesReview breaking changes in release notesCritical
MonitorMonitor during and after upgradeCritical
Rollback planKeep rollback plan readyCritical
Document migrationsDocument custom migrationsHigh
Canary deploymentsUse canary deployments for major upgradesHigh

DocumentDescription
Production InstallationProduction setup guide
Backup and RestoreBackup procedures
TroubleshootingCommon issues
CHANGELOGVersion history