Herkou pg_restore 到一个已经改变的数据库
Herkou pg_restore to a database that has changed
我想知道如果我正在使用 Heroku Postgres 并且我想转储一个 App 1.0
的数据,然后我想 pg_restore
数据到一个新版本我该怎么办应用程序,App 2.0
。问题是 App 2.0
有新的字段和表,并且 pg_restore documentation 写道:
... will issue the commands necessary to reconstruct the database to
the state it was in at the time it was saved.
我不想重建数据库到原来的状态App 1.0
,我只想把数据拿到新的数据库上,我添加的表和字段应该不会冲突与转储文件中的数据。
一个选择是 pg_restore
和 "reconstruct the database to the state it was in at the time it was saved" 然后 运行 再次迁移。这是最好的方法吗?可能有更好的方法,谢谢你的建议。
您可以尝试 pg_dump --data-only
,它将跳过 table 创建并仅转储数据行。然后当您恢复时,您的数据将进入现有 tables。因此,您需要确保它们已存在于新数据库中。我不确定如果 table 定义不同会发生什么。
或者,您可以只对要保留的 table 执行 pg_dump --table <table>
。
我想知道如果我正在使用 Heroku Postgres 并且我想转储一个 App 1.0
的数据,然后我想 pg_restore
数据到一个新版本我该怎么办应用程序,App 2.0
。问题是 App 2.0
有新的字段和表,并且 pg_restore documentation 写道:
... will issue the commands necessary to reconstruct the database to the state it was in at the time it was saved.
我不想重建数据库到原来的状态App 1.0
,我只想把数据拿到新的数据库上,我添加的表和字段应该不会冲突与转储文件中的数据。
一个选择是 pg_restore
和 "reconstruct the database to the state it was in at the time it was saved" 然后 运行 再次迁移。这是最好的方法吗?可能有更好的方法,谢谢你的建议。
您可以尝试 pg_dump --data-only
,它将跳过 table 创建并仅转储数据行。然后当您恢复时,您的数据将进入现有 tables。因此,您需要确保它们已存在于新数据库中。我不确定如果 table 定义不同会发生什么。
或者,您可以只对要保留的 table 执行 pg_dump --table <table>
。