StackGres can cache PostgreSQL extensions locally to speed up cluster deployments and reduce external network dependencies.
Note: The extensions cache is an experimental feature.
Without caching, each cluster pod downloads extensions from the repository when starting. The extensions cache stores downloaded extensions locally, providing:
Configure the cache in the SGConfig resource:
apiVersion: stackgres.io/v1
kind: SGConfig
metadata:
name: stackgres-config
namespace: stackgres
spec:
extensions:
cache:
enabled: true
persistentVolume:
size: 10Gi
storageClass: fast-storage
Enable during operator installation:
# values.yaml
extensions:
cache:
enabled: true
persistentVolume:
size: 10Gi
helm install stackgres-operator stackgres-charts/stackgres-operator \
-f values.yaml
Use a PersistentVolumeClaim for cache storage:
spec:
extensions:
cache:
enabled: true
persistentVolume:
size: 20Gi
storageClass: standard
For testing only, use a host path:
spec:
extensions:
cache:
enabled: true
hostPath: /var/cache/stackgres/extensions
Warning: Host path is not suitable for production as it doesn’t survive node failures.
Pre-load commonly used extensions into the cache:
spec:
extensions:
cache:
enabled: true
preLoadedExtensions:
- postgis
- pgvector
- timescaledb
persistentVolume:
size: 20Gi
Use patterns to pre-load multiple extensions:
preLoadedExtensions:
- postgis # Specific extension
- pg* # All extensions starting with 'pg'
- "*vector*" # All extensions containing 'vector'
First Request: When a cluster needs an extension:
Subsequent Requests: For the same extension:
Cache Invalidation: Extensions are cached by version
# View cache pod
kubectl get pods -n stackgres -l app=stackgres-extensions-cache
# Check cache PVC
kubectl get pvc -n stackgres | grep extensions-cache
# View cache logs
kubectl logs -n stackgres -l app=stackgres-extensions-cache
Monitor cache disk usage:
kubectl exec -n stackgres -l app=stackgres-extensions-cache -- \
du -sh /var/cache/extensions
For air-gapped environments:
On a connected environment:
spec:
extensions:
cache:
enabled: true
preLoadedExtensions:
- postgis
- pgvector
- timescaledb
- pg_stat_statements
persistentVolume:
size: 30Gi
Export the cache volume contents:
kubectl cp stackgres/extensions-cache-pod:/var/cache/extensions ./extensions-backup
Import the cache to the isolated environment:
kubectl cp ./extensions-backup stackgres/extensions-cache-pod:/var/cache/extensions
When using a custom extensions repository:
spec:
extensions:
repositoryUrls:
- https://my-company.example.com/extensions/repository
cache:
enabled: true
persistentVolume:
size: 10Gi
The cache works with any configured repository.
Size appropriately: Estimate cache size based on extensions used
Use persistent storage: Always use PersistentVolume for production
Pre-load common extensions: Reduce initial deployment time
Monitor disk usage: Set up alerts for cache volume capacity
Use fast storage: SSD-backed storage improves performance