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"
Related
After deploying rails project on Heroku,I tried to get into the database console but when i run:
$ heroku run rails db
it is asking for password:
Password:
I forget the password,now i want to create table in database, any solution to setup password again??
heroku pg:psql is the canonical (and faster!) way to connect to heroku db.
The reason heroku run rails db doesn't work is because what it does is it creates a one-off process on Heroku with your codebase and runs rails db command there. rails db depends on $RAILS_ENV environment variable to fetch db credentials from config/database.yml which doesn't work on Heroku.
If you must know your Heroku db password you can get it from heroku config:get DATABASE_URL
I have a db locally in my Rails app. The app is alreqady linked to Heroku through git. I want to totally replace my development db with the one in production on Heroku . How do it ? Are there a set of commands I can use locally to do the job for me ?
You can easily do it with help of heroku pg:backups:restore command. see the detail document here. If you do not have any s2 url for dump install ngrok and put your file in public folder and provide that ngrok url of dump. This will help.
There's a Heroku command for that:
heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb --app sushi,
where you replace each of those arguments with your app's information.
(https://devcenter.heroku.com/articles/heroku-postgresql)
You could write a short rake task to fully replace your local db with Heroku using that command:
lib/tasks/db.rake
desc 'replaces local database with Heroku production database'
task replace_local_with_production: :environment do
Rake::Task['db:drop'].invoke
system heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb --app sushi
Rake::Task['db:migrate'].invoke
end
I've just made some minor modifications to my rails app and now one route works perfectly locally, but raises an error on Heroku.
This is a simple route that directs to 'new' of my controller.
Everything works fine locally, but in prod: It raise the Heroku error
We're sorry, but something went wrong
There is nothing in the logs, I've also put some Rails.logger.warn in the method, but nothing appears.
How is it possible to get a specific error in production Heroku but not in local?
Can I get the same process in local to see the error and fix it?
You should definitely try to reproduce the issue locally by fetching the data to local database.
First make sure your current branch (most likely master) is same as heroku master where the app is deployed.
Then pull the database to local and try to re do the same steps. Follow commands will help you capture latest snapshot and store the database to local.
heroku pg:backups capture --app sushi
curl -o latest.dump `heroku pg:backups public-url --app sushi`
rake db:drop db:create
pg_restore --verbose --clean --no-acl --no-owner [-U user_name] -d database_name latest.dump
https://devcenter.heroku.com/articles/heroku-postgres-import-export
Did you migrate the database in Heroku? heroku run rake db:migrate
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.
After three evenings on this problem and reading all the posts about this, I have to ask this question finally!
I want to deploy the most simple Rails app to Heroku:
rails new test_appli
cd test_appli
git init
git add .
git commit -m "initial commit"
heroku create
git push heroku master
Everything's OK, the application works well on Heroku. After that, I'll create a SQLite3 database:
rails generate scaffold User name:string email:string
rake db:migrate
Everything's OK on the local machine. I can see localhost:3000/users well. Then I want to put the DB on Heroku. First I modify my Gemfile:
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
Then I send the whole thing to Heroku:
git init
git add .
git commit -m "with Database"
git push heroku master
heroku rake db:migrate
Then there are no errors in the batch, everything is OK, the DB is sent, but the page heroku.com/users gives the error
Rails 500, "We're sorry, but something went wrong"
I don't know more what to do. Can you help me?
I suspect you're trying to deploy a Rails 3.1 application to the bamboo stack (heroku create defaults to the 1.9.2 bamboo stack and doesn't run Rails 3.1 out of the box.). The Cedar stack is much better suited to Rails 3.1 sites -
try
heroku create --stack cedar
when creating your application on Heroku and repush it up. Also note your rake command on Heroku will become
heroku run rake db:migrate
Do:
heroku run rake db:schema:load
I had the same issue. It works for me after git push heroku master
Don't do the git init in the second set of commands - you only need to initialise your Git repo once.
Other than that this looks fine - are you seeing any errors anywhere?
Why would you use the pg gem in your production group, but the sqlite3 gem in your development group? Seems to me that your problem is likely due to the fact that you're developing with a different database then you're using in the production environment. If I were you, I would stick to one, which would make it much easier to debug.
If you really want/need to get the application running ASAP, then just run it in production with sqlite... Gemfile:
gem 'rails'
gem 'sqlite3'
Also, a quick way to figure out what the error is would be to run heroku logs from the unix console.
Which version of Rails?
Can you try creating the application running on the Cedar stack?
heroku create myapp --stack cedar
Given the application is running on cedar you need to modify the commands a bit, for example:
heroku run rake db:migrate
In any case you really need to checkout your logs, because your problem might not even be database related, but assets related.
Do you have the heroku shared 5mb database instance added?
When you create your heroku app (on cedar) it doesn't necessarily create the database automatically.
airlift:projects $ heroku create --stack cedar testapp9
Creating testapp9... done, stack is cedar
http://testapp9.herokuapp.com/ | git#heroku.com:testapp9.git
airlift:projects $ heroku addons --app testapp9
logging:basic
releases:basic
When you view your heroku config, you get nothing:
heroku config
airlift:projects $ heroku config --app testapp9
airlift:projects $
To add a database:
heroku addons:add shared-database:5mb
airlift:projects $ heroku addons:add shared-database:5mb --app testapp9
-----> Adding shared-database:5mb to testapp9... done, v3 (free)
airlift:projects $ heroku config
No app specified.
Run this command from an app folder or specify which app to use with --app <app name>
airlift:projects $ heroku config --app testapp9
DATABASE_URL => postgres://blah:blah#blah.compute-1.amazonaws.com/blah
SHARED_DATABASE_URL => postgres://blah:blah#blah.compute-1.amazonaws.com/blah
airlift:projects $
Then you should be able migrate your db.
Hey #redronin thanks for helping me find a way to connect to my postgres database on Heroku, however as a newbie to Heroku and postgresql I had to reverse engineer what "blah" was. So I figure I would break it down to help others as you helped me.
postgres://[user]:[password]#[servername].compute-1.amazonaws.com/[database]