Tags

advanced js
youtube
Web development
vue css
social share buttons
real-life-example
react datetime picker
progra
Online
MathJax
jsfiddle
jquery chart library
instant search using vue
handlebars
event loop
Design
console.log
best practices
Array
yeoman

Show All

How to Backup and Restore Database in Postgres Docker

author-avatar
Anurag Kumar Thu Sep 03 2020
thumbnail

So, what is docker and Postgres ?

Docker : Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.

PostgreSQL:  PostgreSQL is a free and open-source relational database management system emphasizing extensibility and SQL compliance. 

1. Run Postgres in docker 

docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres

2. Check docker container status

docker ps 

Now you can see your docker container id like this :

lets go inside docker as a bash shell

docker exec -it <CONTAINER ID> bash
docker exec -it d909cca76479 bash

3. Connect to Postgres and create database with user

Lets first, create database  

create database newdb;

create user with password

create user newuser with encrypted password 'mynewpassword';

add user to database 

 grant all privileges on database newdb to newuser;

4. Backup and Restore are same you just need to change  "  " direction for backup and " < " for restore. 

pg_dump -C -h [Hostname] -d [dbname] -p [port] -U [username] -W > backup.sql
OR

Restore your databases

cat backup.sql | docker exec -i <CONTAINER ID> psql -U newuser newdb

 

That's how simple it is to manage postgres in docker!

postgrespostgresqldocker

Written By

Anurag Kumar

1

Collections

  • E

    ES6

  • R

    React JS

  • C

    CSS

    Cascading style sheets only

  • S

    SEO

    Search engine optimization

  • E

    ES7

  • C

    CMS

    wordpress, drupal, jumla, magento and more


Show All

Tags

advanced js
youtube
Web development
vue css
social share buttons
real-life-example
react datetime picker
progra
Online
MathJax
jsfiddle
jquery chart library
instant search using vue
handlebars
event loop
Design
console.log
best practices
Array
yeoman

Show All

Collections

  • E

    ES6

  • R

    React JS

  • C

    CSS

    Cascading style sheets only

  • S

    SEO

    Search engine optimization

  • E

    ES7

  • C

    CMS

    wordpress, drupal, jumla, magento and more


Show All