Pushing a single table to Heroku

前端 未结 3 600
我在风中等你
我在风中等你 2021-02-06 00:27

I am aware of the heroku pg:push command which pushes an entire database up to Heroku.

Now that I am launching my product, I would like to be able to push u

3条回答
  •  后悔当初
    2021-02-06 00:42

    My suggestion is to use PostgreSQL dump/restore capabilities directly using the pg_dump and psql commands.

    With pg_dump you can dump a specific table from your local database

    $ pg_dump --data-only --table=products sourcedb > products.sql
    

    Then grab the Heroku PostgreSQL connection string from the configs

    $ heroku config | grep HEROKU_POSTGRESQL
    
    # example
    # postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398
    

    and restore the table in the remote database, using the information retrieved from Heroku.

    $ psql -h ec2-117-21-174-214.compute-1.amazonaws.com -p 6212 -U user3123 db982398 < products.sql
    

    You will need to customize the -p, -h and -U parameters, as well as the database name. The password will be prompted by psql.

    You can also use the pg_restore to filter a dump and restore the table, but I personally prefer psql.

    Note that Heroku is recommending the use of PostgreSQL tools in several documentations, such as Importing and Exporting for large data, or whenever the provided CLI commands don't cover specific cases like the one in this question.

提交回复
热议问题