Member-only story

How to backup and restore large Django data on PostgreSQL faster and more efficiently

Taiwo Kareem
3 min readJan 6, 2023

--

It can be really frustuating when using the Django loaddata command to backup and restore a large amount of data on Django which usually take a lot of time.

I needed to restore data from a PostgreSQL database containing about 75,000 rows of data and after hours of unsuccessful attempt due to django constraint errors, speed and so many other issues, I figured out there was no point trying to tweak the load data output file which was now almost 1GB in size. If you are facing a similar issue like this, then read on as I wrote this blog for you.

The solution was to manually do the backup and restore using the PostgreSQL database commands pg_dump and psql .

Steps

1. Install postgres

First make sure you have Postgres installed on your computer and ensure pg_dump and psql are accessible from the terminal (command line).

2. Backing up your old database data

To back up your data, run the command below

pg_dump -f "dump_file.sql" -h "<db_host_name>" -U <db_username> "<database_name>"

This method works for both local django data as well as database hosted on AWS RDS as…

--

--

No responses yet