Reputation: 139
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:
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?
Upvotes: 10
Views: 13394
Reputation: 81
Ran across the same issue when trying to restore a Heroku db locally, solved it by running these two commands:
psql <db> -c "CREATE SCHEMA IF NOT EXISTS heroku_ext"
psql <db> -c "ALTER database <db> SET search_path TO heroku_ext,public"
then proceed to restore:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d <db> latest.dump
Upvotes: 8
Reputation: 423
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.
Upvotes: 0
Reputation: 21
heroku pg:backups:download --app <app>
psql <db_url> -c "DROP DATABASE IF EXISTS <db_name>"
psql <db_url> -c "CREATE DATABASE <db_name> WITH ENCODING 'UTF8' TEMPLATE template0"
heroku_ext
schema inside the newly created databasepsql <db_url><db_name> -c "CREATE SCHEMA IF NOT EXISTS heroku_ext AUTHORIZATION <db_user>"
heroku_ext
schemapsql <db_url><db_name> -c "CREATE extension IF NOT EXISTS <extension> WITH schema heroku_ext"
psql <db_url><db_name> -c "GRANT ALL ON SCHEMA heroku_ext TO public"
psql <db_url><db_name> -c "GRANT USAGE ON SCHEMA heroku_ext TO public"
search_path
psql <db_url><db_name> -c "SET search_path TO heroku_ext,public"
psql <db_url><db_name> -c "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA heroku_ext TO <db_user>"
pg_restore --no-acl --no-owner -h <db_host> -U <db_user> -d <db_name> ./latest.dump
Upvotes: 2
Reputation: 139
Steps followed to solve the issue:
Upvotes: 3
Reputation: 247445
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.
Upvotes: -1