Skip to content

Instantly share code, notes, and snippets.

@ricjcosme
Created September 13, 2017 17:33
Show Gist options
  • Star 92 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
  • Save ricjcosme/cf576d3d4272cc35de1335a98c547da6 to your computer and use it in GitHub Desktop.
Save ricjcosme/cf576d3d4272cc35de1335a98c547da6 to your computer and use it in GitHub Desktop.
DUMP / RESTORE PostgreSQL Kubernetes
DUMP
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
kubectl exec [pod-name] -- bash -c "pg_dump -U [postgres-user] [database-name]" > database.sql
RESTORE
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
cat database.sql | kubectl exec -i [pod-name] -- psql -U [postgres-user] -d [database-name]
@ayoubhakik
Copy link

@sudonewdev try this
kubectl exec -i [pod-name] -- psql -U [postgres-user] -d [database-name] -f database.sql
or install psql client with :

sudo apt install postgresql-client-common
sudo apt-get install -y postgresql-client

then :
psql -U [postgres-user] -p [database-port] -h [postgres-ip] -d [database-name] -f database.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment