postgresql 如何在heroku数据库中查找行数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12433036/
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
How to find number of rows in heroku database
提问by mea36
The title pretty much sums up my question, but here are more details:
标题几乎总结了我的问题,但这里有更多细节:
I'm running a script to import rows into a heroku database. I started getting errors:
我正在运行一个脚本来将行导入到 heroku 数据库中。我开始收到错误:
<class 'django.db.utils.DatabaseError'> current transaction is aborted, commands ignored until end of transaction block`
The script runs smoothly on my localhost so I'm not looking for problems there. I recently received an email from heroku stating that I'm "Approaching row limit for dev database"
该脚本在我的本地主机上顺利运行,所以我没有在那里寻找问题。我最近收到一封来自 heroku 的电子邮件,说明我正在“接近开发数据库的行数限制”
I'm assuming I hit the row limit but I'd like to confirm this before taking further action.
我假设我达到了行数限制,但我想在采取进一步行动之前确认这一点。
Does anyone know how I can find my current row count for the whole database? (I know I can just do a count on each table but I'm hoping there's a cleaner way)
有谁知道如何找到整个数据库的当前行数?(我知道我可以对每张桌子进行计数,但我希望有一种更清洁的方法)
回答by GregB
If you have the heroku cli tool, this will give you, among other things, the number of rows in your database
如果你有 heroku cli 工具,这会给你,除其他外,你的数据库中的行数
heroku pg:info -a your_app
Also given are your plan type, the db status, the number of current connections, postgres version, when the db was created, the number of rows in your plan, the data size, the number of tables and if your db has any fork/follow options activated.
还给出了您的计划类型、数据库状态、当前连接数、postgres 版本、数据库创建时间、计划中的行数、数据大小、表数以及您的数据库是否有任何叉/按照激活的选项。
回答by CraigKerstiens
This will give you the approximate count of all rows within your database:
这将为您提供数据库中所有行的大致计数:
SELECT sum(reltuples) from pg_class where relname IN (SELECT c.relname
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind = 'r'
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND n.nspname !~ '^pg_toast'
AND pg_catalog.pg_table_is_visible(c.oid));
Though the error message indicates some error on your database, likely a constraint violation versus something with your insert privileges being revoked.
尽管错误消息表明您的数据库出现了一些错误,但可能是违反了约束,而不是您的插入权限被撤销。
回答by nico_lrx
Heroku released a "pg-extras" toolbeltwhich can give you extra informations like the number of rows of your database.
Heroku 发布了一个“pg-extras”工具带,它可以为您提供额外的信息,例如数据库的行数。
Even if you have a higher plan than Hobby, you will get the number of rows by doing the following:
即使您有比 Hobby 更高的计划,您也可以通过执行以下操作获得行数:
heroku plugins:install heroku-pg-extras
Then:
然后:
heroku pg:index_usage --app dashboard
This will give you the number of rows per table.
这将为您提供每个表的行数。