在Heroku中查看数据库

在Heroku中查看数据库

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

问题描述

我在Heroku上设置了一个Django应用,数据库开始收集数据。要更容易地调试事情,我想将我的开发机器直接连接到数据库。这可能与Heroku有关吗?

I have a Django app on Heroku set up and the database is starting to collect data. To debug things more easily I would like to connect my development machine directly to the database. Is this possible to do with Heroku?

推荐答案

如Kirsten所言,共享数据库计划目前无法从Heroku平台之外进行访问(这是为生产Postgres服务预留的东西)。但是,还有其他一些选择。

As Kirsten says, the shared database plans are not currently accessible from outside the Heroku platform (that's something reserved for the 'production' Postgres service). However, there are a few other options.

主要的一个是将数据拉低并在本地进行查看。 ,这很幸运很简单:

One of the main ones is to pull your data down and look at it locally. By using the Taps rubygem this is luckily very very simple:

$ heroku db:pull
...
Receiving schema
Receiving data
8 tables, 591 records
users:         100% |==============================================| Time: 00:00:00
pages:         100% |==============================================| Time: 00:00:00
comments:      100% |==============================================| Time: 00:00:00
tags:          100% |==============================================| Time: 00:00:00
Receiving indexes
Resetting sequences

有如果您使用大型数据集,可以使其他任务更轻一些:

There are a few other options available which can make this task lighter if you're using a large dataset:

# -c, --chunksize SIZE # specify the number of rows to send in each batch
# -d, --debug          # enable debugging output
# -e, --exclude TABLES # exclude the specified tables from the push
# -f, --filter REGEX   # only push certain tables
# -r, --resume FILE    # resume transfer described by a .dat file
# -t, --tables TABLES  # only push the specified tables

所有这些都可以在。

水龙头也可以在Heroku上下文中使用。 。

Taps can also be used outside of the Heroku context. See the README for more information..

第二个选项,对于较大的数据集更为可取的是使用 Heroku pgbackups add-on 。这将允许您创建数据库的转储,然后在本地下载文件以导入干净的数据库。由于Taps的工作原理,这比Taps快得多。

A second option, and one which is much more preferable with larger datasets is to use the Heroku pgbackups add-on. This will let you create a dump of your database, and then download the file locally to import against a clean DB. This is significantly quicker than Taps due to the way that Taps works.

使用方法很好,简单:

$ heroku update

$ heroku addons:add pgbackups
Adding pgbackups to myapp... done

$ heroku pgbackups:capture

DATABASE_URL  ----backup--->  b003

Dump... 2.6MB, done
Upload... 2.6MB, done

$ heroku pgbackups
ID   | Backup Time         | Size    | Database
-----+---------------------+---------+----------------------
b003 | 2010/10/22 15:16.01 |   2.6MB | SHARED_DATABASE_URL
b004 | 2010/10/22 15:18.12 | 424.7MB | HEROKU_POSTGRESQL_URL

$ heroku pgbackups:url b004
"http://s3.amazonaws.com/hkpgbackups/[email protected]/b004.dump?AWSAccessKeyId=ABCD1234&Expires=1289261668&Signature=3mMBeKISewgEUDT%2FL5mRz4EYS4M%3D"

可以下载并导入最后一个URL。

That last URL can be downloaded and imported.

这篇关于在Heroku中查看数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 21:40