在没有Postgis功能的情况下转储或恢复Postgresql数据库

时间:2014-03-04 18:24:11

标签: postgresql postgresql-9.1 postgis postgresql-8.4

我想从postgresql 8.4转储4个数据库以迁移到Postgresql 9.1。

我在PgRouting的旧Postgresql 8.4上使用PostGis,因此每个数据库有大约1000个函数。每次导出所有数据库时,所有函数都写在转储中。当我恢复备份文件时,我在Postgresql 9.1上创建postgis或pgrouting的扩展时会出现一些冲突

无论如何都要转储数据库8.4(创建数据库,创建模式,创建表和数据)而不导出功能?或者无论如何都要在9.1上恢复数据库而不在备份文件上创建功能?

1 个答案:

答案 0 :(得分:7)

使用PostGIS的数据库需要遵循特定的更新程序。您需要遵循“硬升级”程序documented here

在您的8.4数据库中:

pg_dump -h localhost -p 5432 -U postgres -Fc -b -v -f "/somepath/olddb.backup" olddb

在9.1数据库中,可能从这些开始(如果你还没有这样做):

createdb [yourdatabase]
psql -d [yourdatabase] -c "CREATE EXTENSION postgis;"

然后使用特殊的postgis_restore.pl脚本恢复数据:

perl utils/postgis_restore.pl "/somepath/olddb.backup" | psql -h localhost -p 5432 -U postgres newdb 2> errors.txt