1

Can someone please help me how can i pull single table from heroku database.

I have tried the following way:

heroku db:pull --tables table_name

with no luck as heroku db:pull is deprecated now.

Thanks in Advance

anusha
  • 2,087
  • 19
  • 31

2 Answers2

0

Not sure if you can pull a single table from heroku but there are certainly some options to pull whole database.You can use Herokus PG Backups add-on to import or export your database. First you'll have to add it as add on in your app by

$ heroku addons:add pgbackups
$ heroku update

After that you can download your database by

$ heroku pgbackups:capture
$ curl -o latest.dump `heroku pgbackups:url`

You can also use pg:transfer Heroku CLI plugin to transfer the data in a single step.

From your app's directory, copy your production database locally (assuming a local PG db), by installing the plugin and execute the pg:transfer command.

$ heroku plugins:install https://github.com/ddollar/heroku-pg-transfer
$ heroku pg:transfer
Mandeep
  • 9,093
  • 2
  • 26
  • 36
  • Thanks for this but i have tried both approaches of the above, it worked fine but i am unable to fetch records from one of the table in the database(but we have records in heroku db) so i thought to pull single table from heroku but no luck.help me if any idea Thank you – anusha Jul 10 '14 at 06:06
  • @anusha checkout [this thread](http://stackoverflow.com/questions/19145642/heroku-dbpull-dbpull-is-not-a-heroku-command). You can use taps but again it can only import whole database. What's the problem with importing whole database and then using your table? – Mandeep Jul 10 '14 at 07:11
  • while i am importing whole database i am unable to get records of some tables thats why i thought pulling single table from heroku – anusha Jul 10 '14 at 07:13
  • @anusha you are getting records of other tables? – Mandeep Jul 10 '14 at 07:25
  • Yes, i am getting all other tables records but not one table(getting table with empty records but have records in heroku) – anusha Jul 10 '14 at 07:38
0

Not sure if this is still relevant, but you can achieve what you want pulling a CSV dump of a single table (or any other format) and then import it. The steps would be as follows:

# 1. Connect to psql on Heroku
$ heroku pg:psql --app your_app_name DATABASE

Then you can download a table like so:

# 2. Pull table_you_want_to_copy
your_app_name::DATABASE=> \COPY table_you_want_to_copy TO '~/local/path/your_table.csv' WITH (FORMAT csv, DELIMITER ',', HEADER true);

A simple version of an importer could look like this:

# 3. Seed local table from fetched CSV
CSV.foreach('~/local/path/your_table.csv, headers: true) do |row|
  YourModel.create(row.to_hash)
end

In this block you can ofc define whatever other logic you might require.

Severin
  • 8,508
  • 14
  • 68
  • 117