postgresql 查看heroku上的数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9254584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Looking at the database on heroku
提问by baash05
I am attempting to take a look at the data on my heroku instance. I'd like to be able to view the database on their server..
我正在尝试查看我的 heroku 实例上的数据。我希望能够在他们的服务器上查看数据库..
I don't want to pull it down to my local system.. More to the point I don't want wait that long, to take a look at the data.
我不想把它拉到我的本地系统..更重要的是我不想等那么久,看看数据。
Lets assume I push my current database of 8 million books(and all the meta data associated) up to heroku. Then in two months I add another 12 million. (I'm still in development mode) If I have a problem with one batch of data, I don't think it's feasible to pull down the whole database.
假设我将我当前的 800 万本书(以及所有相关元数据)的数据库推送到 heroku。然后在两个月内我又增加了 1200 万。(我还在开发模式)如果我的一批数据有问题,我认为拉下整个数据库是不可行的。
I suppose I could do crunches while I wait on the download of the gigs of data. I hear that's what old programmers did during compiles.
我想我可以在等待下载数据演出时做仰卧起坐。我听说老程序员在编译时就是这样做的。
I've looked at Viewing database in Herokuand it's just a "Can't do it."
Is that true? We can't look at the live data?
采纳答案by samarth
(untested but seem it is what you are looking for.. )
(未经测试,但似乎这是您要找的东西..)
回答by sehrope
You can use HymanDB (http://www.Hymandb.com).
您可以使用HymanDB (http://www.Hymandb.com)。
HymanDB is a database client in your web browser that has OAuth integration with Heroku. It lets you list your Heroku apps and their respective datasources and then connect to them to run SQL queries. See the docsfor details of how to use it with Heroku.
HymanDB 是 Web 浏览器中的数据库客户端,它与 Heroku 集成了 OAuth。它允许您列出 Heroku 应用程序及其各自的数据源,然后连接到它们以运行 SQL 查询。有关如何在 Heroku 中使用它的详细信息,请参阅文档。
Here's what it looks like:
这是它的样子:
There's also the HymanDB Heroku pluginfor the Heroku CLI. The plugin let's you run heroku Hymandb
from your command line to connect to your default database. There are additional options if you have more than one database and want to explicitly select which one you'd like to connect to.
还有用于 Heroku CLI的HymanDB Heroku 插件。该插件让您从命令行运行heroku Hymandb
以连接到默认数据库。如果您有多个数据库并希望明确选择要连接到哪个数据库,则还有其他选项。
To install it:
要安装它:
$ heroku plugins:install https://github.com/Hymandb/Hymandb-heroku-plugin.git
To connect to your default database:
要连接到您的默认数据库:
$ heroku Hymandb
Full disclosure:I'm the founder of HymanDB.
完全披露:我是HymanDB的创始人。
回答by qix
From https://devcenter.heroku.com/articles/heroku-postgresql
来自https://devcenter.heroku.com/articles/heroku-postgresql
Heroku Postgres can be attached to a Heroku application via the CLI:
$ heroku addons:add heroku-postgresql:dev
Heroku Postgres 可以通过 CLI 附加到 Heroku 应用程序:
$ heroku addons:add heroku-postgresql:dev
To establish a psql session with your remote database use heroku pg:psql
.
要与远程数据库建立 psql 会话,请使用heroku pg:psql
.
回答by samarth
Try
尝试
heroku pg:psql
You'll get to know next steps automatically
您将自动了解后续步骤
回答by corg
To view a database directly from Heroku, I just create a 'Dataclip' of the entire database, at https://dataclips.heroku.com/. You can alternatively get there from the postgreSQL app. From this page, do a SQL query to view the desired data.
要直接从 Heroku 查看数据库,我只需在https://dataclips.heroku.com/ 上创建整个数据库的“Dataclip” 。您也可以从 postgreSQL 应用程序到达那里。从此页面执行 SQL 查询以查看所需数据。
If you are unsure which tables are in the database, view them with:
如果您不确定数据库中有哪些表,请使用以下命令查看它们:
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
回答by Andrew
Well, this isn't a perfect answer, but the best way to get in is with the console IMO.
嗯,这不是一个完美的答案,但最好的方法是使用控制台 IMO。
To make that a little easier I've put a class method on some of my models to print them. One example from my app is:
为了让这更容易一些,我在我的一些模型上放置了一个类方法来打印它们。我的应用程序中的一个示例是:
class User
def self.list
puts "ID. Name - Email\n"
self.all.each do |user|
puts "#{user.id}. #{user.name} - #{user.email}\n"
end
end
end
In console you can just call User.list
to get the list.
在控制台中,您只需调用User.list
即可获取列表。
Now this method is not very well optimized, and it would be better if it was written so it could be chained to the end of a query, but you get the basic idea.
现在这个方法没有得到很好的优化,如果把它写成可以链接到查询的末尾会更好,但是你得到了基本的想法。
It's a little bit cludgy but making a display helper method like this is probably the quickest way to introspect your data on Heroku.
这有点笨拙,但制作这样的显示辅助方法可能是在 Heroku 上内省数据的最快方法。
Otherwise my advice would be contact them and ask for recommendations, in my experience the Heroku staff are very responsive and helpful with such requests.
否则,我的建议是联系他们并寻求建议,根据我的经验,Heroku 员工对此类请求非常敏感且乐于助人。
I hope this gives you an idea or two.
我希望这能给你一两个想法。
回答by John Beynon
You can't connect directly to Shared Heroku instances - if you use a dedicated Postgres Heroku addon then you are able to connect directly with PG tools from your local system. However, there is a significant cost jump to do this.
您无法直接连接到共享 Heroku 实例 - 如果您使用专用的 Postgres Heroku 插件,那么您可以直接连接本地系统中的 PG 工具。但是,这样做的成本会显着增加。
回答by Mark Tabler
Depends on what you mean by "view the database". If you're looking for a bona fide SQL console, you're probably out of luck; however, there's always heroku console
which gets you access to an IRB session attached to your app and its Heroku database. From there, you can use the usual commands like Book.where("title = ?", @title)
or Book.count
or whatever you need.
取决于您所说的“查看数据库”是什么意思。如果您正在寻找真正的 SQL 控制台,那么您可能不走运;但是,总有heroku console
哪些方法可以让您访问附加到您的应用程序及其 Heroku 数据库的 IRB 会话。从那里,您可以使用通常的命令,例如Book.where("title = ?", @title)
或Book.count
或任何您需要的命令。
回答by knoxjeffrey
I know this is an old question but thought I'd answer in case anyone was interested. I have been using PG Commanderto view my databases both locally and on heroku. It's not free (£28 at the moment) but it is very good.
我知道这是一个老问题,但我想我会回答以防万一有人感兴趣。我一直在使用PG Commander在本地和 heroku 上查看我的数据库。它不是免费的(目前为 28 英镑),但非常好。
Go to your Heroku databasesand all of the login details will be there.
转到您的Heroku 数据库,所有登录详细信息都将在那里。