This question already has answers here:
pg_restore: error: could not execute query: ERROR: extension "pg_stat_statements" must be installed in schema "heroku_ext"
(4 answers)
Closed 5 months ago.
I am following this set of instructions provided by Heroku to export a copy of my local postgis database and restore it to my Heroku postgres instance. I further followed this set of instructions to provision the postgis extension for my database on Heroku.
The provisioning worked as expected.
climbville::DATABASE=> CREATE EXTENSION postgis;
CREATE EXTENSION
climbville::DATABASE=> \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+------------------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 3.2.3 | heroku_ext | PostGIS geometry and geography spatial types and functions
I then ran the restore using the following command:
heroku pg:backups:restore '<presigned url>' DATABASE_URL --app climbville
However, the restore failed with the following error message:
pg_restore: creating EXTENSION "postgis"
pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 2; 3079 18546 EXTENSION postgis (no owner)
pg_restore: error: could not execute query: ERROR: Extensions can only be created on heroku_ext schema
The restore seems to be failing when it checks for and tries to install the postgis extension. I noticed that when I logged into the Heroku postgres instance after the attenmpted resotre, the postgis extension was gone. This leads me to believe that the pg:restore deleted the extension and then tried to reinstall it but failed.
Any ideas how I can install the postgis extension on my Heroku postgres instance at the time of restore?
Ok, I have discovered how to fix the above issue. Instead of using the above restore command, I added --extensions 'postgis' to the command. That is:
heroku pg:backups:restore '<presigned url>' DATABASE_URL --extensions 'postgis' --app climbville
According to this support post from Heroku, they changed how the postgis extension is stored in the database, and it seems the --extensions flag correctly adds the extension prior to the restore.
Related
I am trying to pg:push my database to heroku server but
still getting the remote database is not empty error although
I am resetting/ the db with pg:reset
heroku pg:reset remote_database_name
heroku pg:push dev_database remote_database
Still getting the error.
For the remote database name I am using the name my-database-7121::pink
I had this problem and it took me a while to solve.
The trick is making sure Postgres is set up properly. To check that it is, type the following into your Terminal:
$ which psql
If you're on a Mac and you're using Postgres.app, this should return something the directory where Postgres.app can be found, e.g.:
$ /Applications/Postgres.app/Contents/Versions/9.3/bin/psql
If the 'which psql' command returns nothing, restart the Terminal and type in the following:
$ export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
Check that this command now works (i.e. returns a directory):
$ which psql
If it does, you should be able to carry on with the 'heroku pg:reset' and 'heroku pg:push' - only this time it will (hopefully) work
I created a nice little Rake task to backup our Mysql database on ClearDB to a remote Google storage bucket. Works great locally but running it on Heroku I get this error:
sh: mysqldump: not found
Of course, Heroku doesn't have mysqldump, how silly of me, but is there any way to do this?
The command I'm using is something like this:
system "mysqldump -h host.cleardb.com -u user -p'password' --single-transaction database | gz > #{backup_directory}/#{file_name}"
Of course gzip doesn't exist either on Heroku.
I know there are a couple of gems to backup PostgreSQL databases but I haven't seen anything for Mysql.
This is for a Rails 3.2 app.
Any ideas would be appreciated.
I'd say your best option would be a custom build pack that adds the mysql binaries that you need.
https://devcenter.heroku.com/articles/buildpacks
I need to use some PostgreSQL proprietary features such as rules and triggers for table partitioning. As long as I know, these kind of features cannot be dump to schema.rb so I have changed my schema_format configuration parameter to :sql.
Now, when I try to load rake db:structure:load to load the generated structure.sql into the heroku database, it fails saying: sh: psql: not found
How can I do it?
You can use pg:psql to run the script from your development machine against the database:
cd your-rails-project
heroku pg:psql -a your-app-name <db/structure.sql
Just make sure that the branch you have checked out locally is the same as the one you have deployed.
I'm trying to use heroku pg:transfer to transfer my local database to Heroku.
Here is the command that I'm running
heroku pg:transfer -f postgres://<username>:<password>#localhost:5432/<db_name> -t postgres://<app_path>.compute-1.amazonaws.com:5432/<stuff> --app <app_name> --confirm <app_name>
and I'm getting the following error messages
pg_restore: [archiver] did not find magic string in file header
pg_dump: [custom archiver] could not write to output file: Invalid argument
pg_dump: *** aborted because of error
I'm using Postgres on Windows. Does anyone know how to fix this?
Import
PG Backups can be used as a convenient tool to import database dumps from other sources to your Heroku Postgres database.
Dump your local database in compressed format using the open source pg_dump tool:
$ PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
Import to Heroku Postgres
In order for PG Backups to access and import your dump file you will need to upload it somewhere with an HTTP-accessible URL. We recommend using Amazon S3.
Use the raw file URL in the pgbackups:restore command:
Be sure to use single quotes around the temporary S3 URL, as it
contains ampersands and other characters that will confuse your shell
otherwise.
I am beginner on Heroku.
I push my exist ruby on rails application into heroku and that was fine.
Next i push my mysql data into heroku with 'push' command as following.
$heroku config:add DATABASE_URL='mysql2://<my CLEARDB_DATABASE_URL>#<myapp>.herokuapp.com/heroku_db?reconnect=true'
$heroku db:push mysql2://<my CLEARDB_DATABASE_URL>#<myapp>.herokuapp.com/<my dump file>
But i got error as following.
Failed to connect to database:
Sequel::DatabaseConnectionError -> Mysql2::Error: Can't connect to MySQL server on '<myapp>.herokuapp.com' (110)
I am confusing what should i do.
Someone tell me how to resolve it.
Many thanks.
-Ono
Don't use db:push or db:pull. Please export a sql file locally and either pipe it in like so:
$ heroku pg:psql DATABASE_URL -a app_name < file.sql
Or better, use Postgres locally and use pgbackups to import/export like so: Importing and Exporting Heroku Postgres Databases with PG Backups