Django的“dumpdata”或Postgres的“pg_dump”?

时间:2021-08-19 02:53:21

I'm unsure as to whether this question should be posted in the Database Administrators' section or here, so please advise if I got it wrong.

我不确定这个问题是应该发布在数据库管理员部分还是这里,所以请告知我是否错了。

I have a Django-based website which doesn't change much. I use python manage.py dumpdata --all --indent=2 > backup.json and reload the data with loaddata if I need to redeploy or the db gets corrupted. (I'm aware about integrity errors that have occurred when not excluding auth and content_types)

我有一个基于Django的网站,它没有太大变化。我使用python manage.py dumpdata --all --indent = 2> backup.json并使用loaddata重新加载数据,如果我需要重新部署或数据库损坏。 (我知道在不排除auth和content_types时发生的完整性错误)

Since I'm using PostgreSQL on the backend, is it "best practise" or "wiser" for me to use pg_dump instead, and then pg_restore if something goes wrong or if I need to redeploy?

由于我在后端使用PostgreSQL,对我来说,使用pg_dump是“最佳实践”还是“更明智”,如果出现问题或者我需要重新部署,那么pg_restore是什么?

So dumpdata dumps all data associated with the selected apps (and/or models), and pg_dump performs a full dump of the db. Is this the same thing or is there a fundamental difference that I've missed (mind you I have 0 experience with DBA)?

因此,dumpdata转储与所选应用程序(和/或模型)关联的所有数据,并且pg_dump执行db的完全转储。这是同一件事还是我错过了一个根本的区别(请注意,我有100次DBA经验)?

Which option do I go for and why?

我选择哪个选项以及为什么?

1 个解决方案

#1


1  

it is both best practice and wiser for you to use pg_dump instead of dumpdata. pg_dump is faster, the output is more compact (particularly with the -Fc option) and it can be loaded faster with pg_restore than loaddata. Last but not least the integrity errors that you spoke of will not happen with pg_dump/pg_restore.

使用pg_dump而不是dumpdata是最好的做法和明智之举。 pg_dump更快,输出更紧凑(特别是使用-Fc选项)并且可以使用pg_restore比loaddata更快地加载它。最后但并非最不重要的是,pg_dump / pg_restore不会发生您所说的完整性错误。

Generally pg_dump is used to dump the entire database however the -t option allows you to dump one or few tables at a time

通常,pg_dump用于转储整个数据库,但-t选项允许您一次转储一个或几个表

#1


1  

it is both best practice and wiser for you to use pg_dump instead of dumpdata. pg_dump is faster, the output is more compact (particularly with the -Fc option) and it can be loaded faster with pg_restore than loaddata. Last but not least the integrity errors that you spoke of will not happen with pg_dump/pg_restore.

使用pg_dump而不是dumpdata是最好的做法和明智之举。 pg_dump更快,输出更紧凑(特别是使用-Fc选项)并且可以使用pg_restore比loaddata更快地加载它。最后但并非最不重要的是,pg_dump / pg_restore不会发生您所说的完整性错误。

Generally pg_dump is used to dump the entire database however the -t option allows you to dump one or few tables at a time

通常,pg_dump用于转储整个数据库,但-t选项允许您一次转储一个或几个表