Heroku won't reset my database - ruby-on-rails

I have been trying to run $ heroku pg:reset from the command line but I believe I'm not putting in the database correctly. I've tried a number of variations.
I ran $ heroku config | grep POSTGRESQL to get the database name which prints as
HEROKU_POSTGRESQL_PINK_URL: postgres://naknaswvxfvuup:QK2dHYNMZ_va10lDgMDo4S0BIM#ec2-23-21-161-255.compute-1.amazonaws.com:5432/db7eute4gu4mcb
I've tried running everything from
#1
$ heroku pg:reset HEROKU_POSTGRESQL_PINK_URL: postgres://naknaswvxfvuup:QK2dHYNMZ_va10lDgMDo4S0BIM#ec2-23-21-161-255.compute-1.amazonaws.com:5432/db7eute4gu4mcb
#2
$ heroku pg reset postgres://naknaswvxfvuup:QK2dHYNMZ_va10lDgMDo4S0BIM#ec2-23-21-161-255.compute-1.amazonaws.com:5432/db7eute4gu4mcb
#3
$ heroku pg:reset db7eute4gu4mcb
and other variations. Please let me know how to correctly note this as I keep getting either an error or this text from the commmand line " ! Unknown database: db7eute4gu4mcb. Valid options are: DATABASE_URL, HEROKU_POSTGRESQL_PINK_URL"
I'm currently at 10.4 on the Ruby on Rails tutorial. Thanks!

You should specify a DATABASE when run heroku pg:reset. This is the syntax:
heroku pg:reset <DATABASE>
To know the value of , you can run:
heroku pg:info
It will return DATABASE_URL, something like: HEROKU_POSTGRESQL_GRAY_URL
Then you can reset your database:
heroku pg:reset HEROKU_POSTGRESQL_GRAY_URL
In your case, to reset database run:
heroku pg:reset HEROKU_POSTGRESQL_PINK_URL

this is how it worked for me
(replace app-staging with your app's name, do not replace DATABASE_URL, this is how heroku now finds the app's db)
heroku pg:reset DATABASE_URL --confirm app-staging
hope it helps

Assuming you have your authentication information exported to the shell environment, you should be fine with just passing the name of the database. For example:
PGPASSWORD='foobarbaz'
export PGPASSWORD
heroku pg:reset pink
There are certainly other ways to use the reset command, but IMHO this is the easiest.

Related

How to push local postgresql database built on rails to heroku?

I have some data in my postgresql database that I entered using a very simple rails app. I deployed it to heroku and now am trying to send my local database to heroku because its very empty right now.
At first I thought doing heroku run rake db:migrate would actually do this but turns out it only creates tables in heroku?
These are the steps I took to transfer my local database to heroku.
1: heroku run rake db:migrate ( I did this to create tables which should be empty right?)
2: heroku pg:push my_db DATABASE_URL --app my-herokuapp-98989 (the actual syntax to transfer database)
Here, it said
"Remote database is not empty. Please create a new database or use heroku pg:reset"
4: heroku pg:reset DATABASE
"WARNING: Destructive action" "postgresql-amorphous-59192 will
lose all of its data" "To proceed, type my-herokuapp-98989 or
re-run this command with --confirm my-herokuapp-98989
5: my-herokuapp-98989
"Resetting postgresql-amorphous-59192... done"
After this I try to open my app but it gives off an error saying
"ActionView::Template::Error (PG::UndefinedTable: ERROR: relation
"drinks" does not exist" "2017-07-29T04:50:20.697828+00:00
app[web.1]: LINE 1: SELECT "drinks".* FROM "drinks""
"drinks" is the name of my table and I think it is giving this error because I just reset my database so there is no table or columns and rows?
So again I try pushing my database to heroku and it just freezes at this point
6: heroku pg:push my_db DATABASE_URL --app my-herokuapp-98989
"heroku-cli: Pushing my_db ---> postgresql-amorphous-59192"
...and it freezes here
What am I doing wrong? Please help.
are you sure it's freezing? or its just loading, because you need to upload the dumpfile to heroku.
you also can try this command
heroku pg:backups:restore 'https://url/where/heroku/can/download/yourdbdump.dump' DATABASE_URL
more about import export you can read here. https://devcenter.heroku.com/articles/heroku-postgres-import-export#import

Rake db:reset 'user does not have CONNECT privilege'

So I'm using Heroku Postgres in my Rails app, but I'm not hosting my app on Heroku itself. I used the Active Record connection details from Heroku in my database.yml, and it looks like this:
development:
adapter: postgresql
encoding: unicode
pool: 5
database: [database]
username: [username]
password: [password]
host: ec2-54-227-243-78.compute-1.amazonaws.com
port: 5432
However, now I'm trying to rake db:migrate my app so the database gets all set up with my models. Running that command doesn't do anything, so I tried rake db:reset and I get this:
Couldn't drop df2cokjfj0k4vu : #<PG::Error: FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
df2cokjfj0k4vu already exists
-- initialize_schema_migrations_table()
-> 1.3997s
-- assume_migrated_upto_version(20130924040351, ["/home/action/braindb/db/migrate"])
-> 0.0882s
Any idea what I'm doing wrong. I'm still pretty new to Rails so sometimes I forget how to get my Postgres database setup properly when migrating hosts.
Use heroku pg:reset DATABASE instead as noted in https://devcenter.heroku.com/articles/rake
You cannot drop databases in Heroku with rake db:reset because user has no privileges.
You can't drop your PG database on Heroku.
I recently had this problem and resolved it through the following steps.
heroku pg --help gets the name of commands for using postgres
heroku pg:reset DATABASE # resets the db
Answer the prompt to confirm
Like others I had a similar problem but running pg:reset did not help: that's where I ran into the user does not have CONNECT privilege issue.
1) heroku pg:reset you will be prompted to enter the project name to confirm.
2) From Heroku's docs run heroku rake db:schema:load
I had the same problem. I fixed it by running:
heroku pg:reset DATABASE
(note: must specify DATABASE as above)
If you got this because you were running rake db:create, instead, simply skip to the migration. For whatever reason, postgresql on heroku doesn't require the rake db:create step as may be required on local installations.
In other words, instead of
heroku run rake db:create db:migrate db:seed
run this instead
heroku run rake db:migrate db:seed
The solution to me was to just go straight to migration because the database is already created (don't go on "heroku run rails db:create")
heroku run rails db:migrate -a YOURAPPNAME
For one of my apps, upgrading to the first paid tier of a Heroku database seemed to work for me: https://devcenter.heroku.com/articles/upgrade-heroku-postgres-with-pgbackups#provision-new-plan
Reason was that 'heroku pg:info' revealed that I was over my row limit as shown here:
Rows: 12392/10000 (Write access revoked)

How to get shared database url in heroku

How to get SHARED_DATABASE_URL in heroku.. while am trying to migrate it is asking for SHARED_DATABASE_URL how can i get it.. ??
heroku pg:reset --db SHARED_DATABASE_URL
What should i add in the place of SHARED_DATABASE_URL?? am working in ruby on rails
could anyone help me on this.
You can use command: heroku pg:info or just heroku pg to get information about your database. You will get something like this:
HEROKU_POSTGRESQL_GRAY_URL (DATABASE_URL)
Then run: heroku pg:reset HEROKU_POSTGRESQL_GRAY_URL
to reset database on heroku.
The instruction below worked for me :
$ heroku pg:credentials YOUR_DATABASE_NAME
It returns the informations ( url, port, dbname, user, password ) :
Connection info string:
"dbname=xxxxxxx host=dc2-103-73-245-224.shhdtdr-1.amazonaws.com port=6212 user=user31231 password=dyzjur sslmode=require"

Heroku and Rails: transferring db to staging and db:migrate

I've been working on a Heroku app for several months. We've recently set up a staging server and occasionally sync the staging db with the production db. The three main commands in use are:
$ heroku pgbackups:capture --app myapp
$ heroku pg:reset DATABASE --app myapp-staging --confirm myapp-staging"
$ heroku pgbackups:restore DATABASE `heroku pgbackups:url --app myapp` --app myapp-staging
The problem is that after running the third command, I need to run heroku run rake db:migrate --app myapp-staging. We have a few dozen migrations now, including some that refer to Ruby classes that we've deleted or renamed.
This causes the migrations to fail to fully run. What's the solution here? Should I delete the old migrations that fail and commit these changes to the git repo?
Re-running this script fixed the error, so it seems like the schema should just copy over. For anyone seeing a failing migration like I did, the pgbackups:restore command probably failed for you, so re-run that.
You can also checkout the transfer command now as part of pgbackups .. see this post
How do I transfer production database to staging on Heroku using pgbackups? Getting error

Does Heroku pgbackups:restore rebuild the database or just repopulate it?

I'm trying to copy my production database on Heroku across to my staging server.
My staging server has been ahead of my production server with a migration that creates an extra table. I now want to dry-run the migration to add that table on the production database and so would like to revert my staging's database in order to do so.
The problem is that each time I restore the staging database to the production one the table sticks around. I was expecting the database to be destroyed and repopulated but it only seems to be being repopulated.
heroku pgbackups:url b104 --app production
# 'http://s3.amazonaws.com/...'
heroku pgbackups:restore DATABASE 'http://s3.amazonaws.com/...' --app staging
Every time I do this I find that the "newer" table is still remaining.
Does pgbackups:restore actually restore table structure or simply data - what's going on here?
A restore is a simple Postgres restore, so essentially a scripted version of your data.
In order to do this, you need to nuke your database first, and then rebuild it from the database script:
heroku pg:reset
heroku pgbackups:restore blah...
as neil said, the pgbackups:restore only moves the data and does not change the actual db structure.
for complete db restore (change app-production, app-staging and migration_number to fit your app):
first, get the current migration from your production.
heroku run rake db:version --app app-production
reset staging db (naturally, back it up if needed)
heroku pg:reset DATABASE_URL --confirm app-staging
run the migrations until migration_number to fit the production db structure
heroku run rake db:migrate VERSION=current_migration_number --app app-staging
capture the production app
heroku pgbackups:capture --app app-production
push the data to the staging app
EDIT - in case you're using the heroku toolbelt, the syntax pattern
has changed from pgbackups:action_name to pg:backups action_name
heroku pgbackups:restore DATABASE "heroku pgbackups:url --app app-production" --app app-staging
the staging db should now match the production data and structure
heroku run rake db:migrate --app app-staging
hope that helps.

Resources