Back

Blog Image
author-img

Restore .sql File into PostgreSQL configured using Docker

March 19, 2025, 3:35 a.m.


Note: In docker "5000:80" - 5000 is the port we should open in browser (i.e) localhost:5000

  1. Extract the tarball in to folder bash tar -zxvf <file_name>.tar.gz -C /path/to/target/folder
  2. Copy the .sql to docker bash docker cp ~/path/to/<file_name>.sql <container-name>:/var/lib/postgresql/data/
  3. To go to docker bash (shell) bash docker exec -it <container-name> /bin/bash
  4. Go to postgres sql shell using below command bash psql -U <username> -d <dbname>
  5. Create Dummay database in POSTGRESQL bash CREATE DATABASE <name-of-your-db>;
  6. Now Quit the postgres shell bash \q
  7. Final Restoration steps: bash psql -U selva -d usa -a -f /var/lib/postgresql/data/usda.sql
  8. Go to psql shell again
  9. Check if the DB exists using below query sql SELECT datname FROM pg_database; or bash \l

Last updated: Dec. 31, 2025, 9:53 p.m.