从heroku下载partial数据库 [英] Download partial database from heroku

查看:161
本文介绍了从heroku下载partial数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ruby在rails应用程序托管在heroku使用postgresql作为其数据库。由于数据库越来越大,我想知道是否有一种方法,只下载它的一个特定的部分从heroku。例如,可以只下载一个特定的表,或者只下载具有parent_id == x的行。

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 download only a specific part of it off of heroku. For example, is it possible to download only one specific table, or download only rows with parent_id == x.

推荐答案

到Steve的相当正确的答案,你还可以选择使用 psql 连接到 DATABASE_URL 并使用 \copy ,例如

In addition to Steve's quite correct answer, you also have the option of connecting using psql to the DATABASE_URL and using \copy, e.g.

$ psql "$(heroku config:get DATABASE_URL)"

mydb=> \copy mytable TO 'mytable.csv' WITH (FORMAT CSV, HEADER)

mydb=> \copy (SELECT col1, col2 FROM mytable2 WHERE ...) TO 'mytable2_partial.csv' WITH (FORMAT CSV, HEADER)

您可以提取整个表,或任意查询(包括连接等)的输出。表定义(DDL)不是以这种方式导出的,但可以使用 pg_dump --schema-only -t ... 转储。

You can extract whole tables, or the output of arbitrary queries (including joins etc). The table definition (DDL) is not exported this way, but can be dumped with pg_dump --schema-only -t ....

这篇关于从heroku下载partial数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆