Download partial database from heroku

后端 未结 2 1869
刺人心
刺人心 2021-01-06 15:04

I have a ruby on rails application hosted on heroku using postgresql as its database. Since the database is getting pretty large, I was wondering if there\'s a way to downlo

2条回答
  •  暖寄归人
    2021-01-06 16:07

    Using the DATABASE_URL config setting you can use pg_dump to access your database and use the -t switch to specify a certain table.

    For example, to export the table my_table into file called db.sql:

    pg_dump -t my_table `heroku config:get DATABASE_URL` > db.sql
    

    If you need to limit the download to certain rows then I don't think pg_dump will do the job on it's own. You could create another table in your Heroku database to first define the subset of rows that you want to download and then have pg_dump dump only that table. See this question for some ideas about how to do that: Export specific rows from a PostgreSQL table as INSERT SQL script

提交回复
热议问题