gpt4 book ai didi

django - 在 Heroku 中查看数据库

转载 作者:行者123 更新时间:2023-11-29 14:24:05 25 4
gpt4 key购买 nike

我在 Heroku 上设置了一个 Django 应用程序,数据库开始收集数据。为了更轻松地调试,我想将我的开发机器直接连接到数据库。这可能与 Heroku 相关吗?

最佳答案

正如 Kirsten 所说,共享数据库计划目前无法从 Heroku 平台外部访问(这是为“生产”Postgres 服务保留的内容)。但是,还有一些其他选项。

其中一项主要任务是将您的数据拉下来并在本地查看。 By using the Taps rubygem 幸运的是,这非常非常简单:

$ 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

如果您使用的是大型数据集,还有一些其他选项可以让这项任务变得更轻松:

# -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 gem source 中看到。

Taps 也可以在 Heroku 上下文之外使用。 See the README for more information. .

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

使用起来非常简单:

$ 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/app1234567@heroku.com/b004.dump?AWSAccessKeyId=ABCD1234&Expires=1289261668&Signature=3mMBeKISewgEUDT%2FL5mRz4EYS4M%3D"

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

关于django - 在 Heroku 中查看数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9052419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com