2

I have a dev version and a production version running in django.

I recently started populating it with a lot of data and found that the django loaddata tries to load everything into memory before adding it into the db and my files will be too big for that.

What is the proper way to push my data from my dev machine to my production?

I did...

pg_dump -U user -W db ./filename.sql

and then on the production server I did...

psql dbname < filename.sql

It seems like it worked, all the data is there, but it came up with some errors such as

relation xxx already exists
constrain xxx for relation xxx already exists

and there were quite a few of them, but like I said everything appears to be there. Is this the right way to do it?

Edit: I have in the production machine the database with information and I don't want truncate the tables before import.

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Joff
  • 11,247
  • 16
  • 60
  • 103

1 Answers1

1

This is the script that I use:

 pg_dump -d DATABASE_NAME -U postgres --format plain --inserts > /FILE.sql

Edit: As you says in comments that you don't want truncate the tables before import, you can't do this type of import into your production database. I suggest empty your production database before import the dev database dump.

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
  • if I am not mistaken, that only takes care of the dump side and not the loading into the other machine, right? – Joff Dec 04 '15 at 05:22
  • @deltaskelta yes, do you verify that you have an empty database before import? – Adrian Cid Almaguer Dec 04 '15 at 05:26
  • no, that is the thing. I would like to be able to write over a database with stuff already in it. I could empty it out, but that would be a bit of a pain everytime I wanted to update my production environment – Joff Dec 04 '15 at 05:37
  • @deltaskelta in this case you can't do the import like you try to do it. Because you don't know wich rows have your production database at the moment of the import – Adrian Cid Almaguer Dec 04 '15 at 05:41
  • @deltaskelta I edit your question with the last information providad by you in comments – Adrian Cid Almaguer Dec 04 '15 at 05:44
  • thank you for the edits, should I empty my database of data or drop all the tables as well? What is the command you recomment to load the backup file into the now clean db? – Joff Dec 04 '15 at 07:25
  • so then in this case I should add something to my deploy script that completely wipes the production db every time I want to deploy? Am I getting you correctly? – Joff Dec 04 '15 at 07:28
  • Also, I think it goes without saying, but it is definitely worth figuring out why you have the need to do this in the first place. There should be a way to get the data directly into production or whatever.. @deltaskelta – karns Dec 10 '19 at 19:47