DEV Community

Artem
Artem

Posted on

How to backup Postgresql

If your Postgres in docker container use pg_dumpall to backup:

docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Enter fullscreen mode Exit fullscreen mode

and then restore it:

cat dump_24-04-2021_20_50_17.sql | docker exec -i some-postgres  psql -U postgres
Enter fullscreen mode Exit fullscreen mode

If you want to play with the current command we can run a new docker container with postgres, create table, and check how a command is working.

Start a container:

docker run --name some-postgres -e POSTGRES_PASSWORD=pass -d postgres
Enter fullscreen mode Exit fullscreen mode

Go inside the container:

docker exec -it some-postgres bash
Enter fullscreen mode Exit fullscreen mode

Start psql console:

psql -U postgres
Enter fullscreen mode Exit fullscreen mode

Create table:

CREATE TABLE first_table (column1 int);
Enter fullscreen mode Exit fullscreen mode

And then you can do anything you want :)

Top comments (0)

Billboard image

Try REST API Generation for MS SQL Server.

DreamFactory generates live REST APIs from database schemas with standardized endpoints for tables, views, and procedures in OpenAPI format. We support on-prem deployment with firewall security and include RBAC for secure, granular security controls.

See more!

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️