Due to this change by heroku, I am not able to restore my Heroku Postgres backup.
Following errors are thrown while restoring:
pg_restore: error: could not execute query: ERROR: extension "pg_stat_statements" must be installed in schema "heroku_ext"
Command was: CREATE EXTENSION IF NOT EXISTS "pg_stat_statements" WITH SCHEMA "public";
pg_restore: error: could not execute query: ERROR: extension "pg_stat_statements" does not exist
Command was: COMMENT ON EXTENSION "pg_stat_statements" IS ‘track planning and execution statistics of all SQL statements executed’;
Command was: CREATE EXTENSION IF NOT EXISTS "postgis" WITH SCHEMA "public";
Any many such errors.
I contacted Heroku support, and they have provided the following step to try fix the issue manually.
Here are the steps in detail:
- Download a backup of your database.
- Convert the dump file to a .sql file with: pg_restore -f
- Modify the CREATE EXTENSION commands to use CREATE EXTENSION IF NOT EXISTS
extension_name WITH SCHEMA heroku_ext. You can do this by using sed or a text editor
of your choice. - Restore the backup using pg_restore to Heroku Postgres from your app. The extensions
in your production database will now be owned by the correct schema; future
migrations, backups, and restores should proceed without needing to repeat this
process.
I have modified the .sql file as per step3, but I am not able to figure hot how to convert this .sql file to a .dump file to be restored on the Heroku app.
I have tried heroku pg:psql --app <app> <sql_file>
but it does not work and throws errors.
Can someone help me in importing this .sql file to Heroku?
5
Answers
Steps followed to solve the issue:
You can ignore the error and manually create the extension in the required schema. If you want to avoid the error message, drop the extension in the database before dumping it. That should not be a problem, because nothing else in your database should depend on that extension.
How to restore a Heroku database dump in a non-Heroku environment
Here comes the important part
heroku_ext
schema inside the newly created databaseheroku_ext
schemasearch_path
Finally…
I had the same issue and found the answer in this question.
https://stackoverflow.com/a/73773443/17517157
Just add
--extensions 'postgis'
to your restore command.Ran across the same issue when trying to restore a Heroku db locally, solved it by running these two commands:
then proceed to restore: