Created
September 13, 2017 17:33
-
-
Save ricjcosme/cf576d3d4272cc35de1335a98c547da6 to your computer and use it in GitHub Desktop.
DUMP / RESTORE PostgreSQL Kubernetes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Hi, I need to migrate a postgresql database from a k8s environment to an on-premise server. Can i do this by exporting .sql file from k8s and running this .sql file on the on-premise server ?
I think it's the same scenario, you can use the script above.
I'm facing authentication failed using RESTORE
@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
Hi, I need to migrate a postgresql database from a k8s environment to an on-premise server. Can i do this by exporting .sql file from k8s and running this .sql file on the on-premise server ?