我正在尝试将 PostgreSQL 转储从 heroku 导入本地数据库(以模拟本地环境中的生产数据)。我在 OSX 上本地使用 postgres 9.2。以下是我在控制台中采取的步骤:
dropdb db_dev
createdb db_dev
heroku pgbackups:capture HEROKU_POSTGRESQL_MAROON_URL
curl -o latest.dump `heroku pgbackups:url`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U connorwarnock -d db-dev latest.dump
以及随后的错误:
pg_restore: connecting to database for restore
pg_restore: dropping COMMENT EXTENSION plpgsql
pg_restore: dropping EXTENSION plpgsql
pg_restore: dropping COMMENT SCHEMA public
pg_restore: dropping SCHEMA public
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 6; 2615 2200 SCHEMA public whgnwlkesexkyo
pg_restore: [archiver (db)] could not execute query: ERROR: cannot drop schema public because other objects depend on it
DETAIL: extension hstore depends on schema public
HINT: Use DROP ... CASCADE to drop the dependent objects too.
Command was: DROP SCHEMA public;
pg_restore: creating SCHEMA public
pg_restore: [archiver (db)] could not execute query: ERROR: schema "public" already exists
Command was: CREATE SCHEMA public;
pg_restore: creating COMMENT SCHEMA public
pg_restore: creating EXTENSION plpgsql
pg_restore: creating COMMENT EXTENSION plpgsql
pg_restore: setting owner and privileges for SCHEMA public
pg_restore: setting owner and privileges for COMMENT SCHEMA public
pg_restore: setting owner and privileges for EXTENSION plpgsql
pg_restore: setting owner and privileges for COMMENT EXTENSION plpgsql
WARNING: errors ignored on restore: 2
没有数据被导入。似乎公共架构引起了问题(我已经手动删除了架构并再次尝试,但无济于事)。也许 hstore 扩展正在引起麻烦?关于如何避免这些错误的任何其他想法?