Rails import database on heroku - ruby-on-rails

I am trying to import a database from my computer to heroku but it keep on saying unknown command for that.Even I am confuse about it which command to use .I have a postgre sql database.I want to know how to import a database
push from SOURCE_DATABASE to REMOTE_TARGET_DATABASE
REMOTE_TARGET_DATABASE must be empty.
SOURCE_DATABASE must be either the name of a database
existing on your localhost or the fully qualified URL of
a remote databas
So what will be the remote_target_database ???
and do i need to specify my full path to source database ?

Try the following.
heroku pg:push your_app_name_development DATABASE_URL

PG Backups can be used as a convenient tool to import database dumps from other sources into your Heroku Postgres database.
https://devcenter.heroku.com/articles/heroku-postgres-import-export
How to import a Heroku PG dump into local machine

Related

Rails - importing Postgres production database to local development database

I have a database dump named dump.sql from production DB and when I try to import it to my local development DB I get an error
ERROR: role "petdoctors_prod" does not exist
\connect: FATAL: database "petdoctors_prod" does not exist
It looks like the name of the production database is petdoctors_prod and my local development db is called petdoctors_development. Is it possible to import prod DB to dev?
What's the best way of dumping the db from prod?
The following steps should help in importing the dump.sql to your local machine:
Run rake db:drop from on your local machine to drop the existing database
Run rake db:create. This would create the database mentioned in your database.yml file as per the environment. In this case, it would create a database called petdoctors_development
Import the dump to petdoctors_development. This syntax of this step would vary depending on the database you're using. For example, to import a dump in PostgreSQL, we use psql <db_name> < <Path to dump file>
Run rake db:migrate, in order to run all the migrations in your app
Post this, the app will run on development, with the same data as that of the dump taken from production.

Importing table dump to Heroku Postgres

I've created a dump file of one table on my local db using pg_dump and want to import it to my production db on Heroku to replace the current production version of the table.
I was looking at these instructions: https://devcenter.heroku.com/articles/heroku-postgres-import-export#import-to-heroku-postgres
Should I use pg_restore or can I use heroku pg:backups:restore? Does using heroku pg:backups:restore drop the entire db and replace it with the contents of the dump file or will it only drop and replace what is in the dump file? I am concerned about data other than what's in the dump file being dropped (since my dump file is only one table). I will of course create a backup of production before doing this, but am curious what the best approach is. Thanks!

Unable to upgrade heroku database

I've just upgraded my heroku database. I'm now trying to copy the data from my old database to my new database, however I keep getting this error. Could it be that I'm unable to copy it because write access is revoked?
Why not just import and export a backup using PG Backups, your issue here is that your databases are in different apps(environments), so from the console using --app earthedhub will just let you use the DATABASE_URL.
use a PG Backups take a look to this post

Heroku remote database must be empty error after pg:reset

I have an app on Heroku and I'm trying to replace the database on Heroku with the database on my local machine.
I was under the impression that
heroku pg:reset DATABASE
would clear the remote database and allow me to push. However, after running pg:reset, I run
heroku pg:push
and I stil get this error:
Usage: heroku pg:push <LOCAL_SOURCE_DATABASE> <REMOTE_TARGET_DATABASE>
push from LOCAL_SOURCE_DATABASE to REMOTE_TARGET_DATABASE
REMOTE_TARGET_DATABASE must be empty.
Couple of questions:
1. do I have to specify local db and remote db? [I am in the root directory of my application on my local machine]
2. if so, how do I find what my local database name is? I know that heroku can divine the remote database via DATABASE_URL?
You have to specify BOTH the local database(where the data is coming from) and the remote database(where the data is going). The part about REMOTE_TARGET_DATABASE must be empty. is just a reminder to make sure you clear the Heroku database before you push.
You should be able to find your database from your database.yml file.
You can also find the heroku database by heroku pg:info
Reminder: Heroku runs PostgreSQL so you should be using PostgreSQL locally as well.

How do I check the records of my heroku database?

I've just deployed my application to heroku and pointed my custom domain to the heroku servers. How can I check the records in my heroku database?
You can use heroku run rails console and look at your records with Model.all or any other method.
If you want to backup the database look at heroku PG backups, you then can import your database on your local machine and look at it there. Depending on your db adapter you could use sqlite browser for sqlite3 or phpmyadmin for MySQL.
I found a similar question like this and here is what #Chowlett says:
"You could run heroku pg:psql to fire up a Postgres console, then issue \d to see all tables, and \d tablename to see details for a particular table."
You can also type select * from tablename; to view the table contents.
How to view current database schema for Heroku app in Terminal?
heroku db:pull to pull your production DB locally to take a peek in it.
I'll give the method for connecting via a GUI tool
Run the following command to get the database credentials from Heroku:
heroku pg:credentials DATABASE_URL
Then you can use a GUI tool like PG Commander or PGAdmin to connect to the db
Heroku now has an add-on named PostgreSQL Studio (currently free & in beta) that would let you access your database from within the browser, without having to use CLI, much like PHP MyAdmin.
To attach this add-on to your application,
heroku addons:create pgstudio
Then go to the list of add-ons on Heroku, select PostgreSQL Studio, authorize it, select the database to connect with from the dropdown list of all databases and it will take you to the web-based interface to handle your selected database.
You may refer to this official article on Heroku:
https://devcenter.heroku.com/articles/pgstudio
The easy answer is:
heroku pg:info
You can also download a client side Postgres, like Postico, and using the information provided in that URL to enter password and database name etc, then you can create locally, just like phpMyAdmin.
I use the admin_data gem, works well in Heroku.
You can use heroku dataclips that allows to run queries online. Here you can find documentation https://devcenter.heroku.com/articles/dataclips.
Connect to the database using Sequel Pro. You can find your ClearDB url using heroku config command. The structure for connecting is as follows:
CLEARDB_DATABASE_URL => mysql://[username]:[password]#[host]/[database name]?reconnect=true

Resources