如何在Heroku上为Postgres命令启用安静模式

编程入门 行业动态 更新时间:2024-10-27 14:30:02
本文介绍了如何在Heroku上为Postgres命令启用安静模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当在本地机器上使用 psql 命令行工具时,我可以选择使用 -q 或 - quiet 切换到告诉Postgres这样做是安静的 - 即它不会打印每一个 INSERT 语句如果您正在进行大量导入,请使用控制台。

以下是我如何使用它的示例:

psql -q -d< SOME_DATABASE> -f< SOME_SQL_FILE>

然而,当使用 pg:psql Heroku中的命令行实用程序,该选项似乎不可用。所以我现在必须像这样使用它:

heroku pg:psql DATABASE -a< SOME_HEROKU_APP> < < SOME_SQL_FILE>

这会产生很多的输出到我的控制台(数十万行),因为我导入的SQL文件的大小很大。每当我尝试使用 -q 或 - quiet 选项时,都是这样的:

heroku pg:psql DATABASE -q -a< SOME_HEROKU_APP> < < SOME_SQL_FILE>

它会抛出一个错误,指出 -q

在Heroku中运行Postgres命令时,有什么方法可以启用安静模式?

解决方案

>二进制( github/ heroku / heroku / blob / master / lib / heroku / command / pg.rb#L151 )

所以,你可以这样做:

psql`heroku config:get DATABASE_URL -a< yourappname>`

获得psql连接,并相应地传递 -q 其他选项。

When using the psql command line utility on my local machine, I have the option to use the -q or --quiet switch to tell Postgres to do it's work quietly - i.e. it won't print every single INSERT statement to the console if you're doing a large import.

Here's an example of how I'm using it:

psql -q -d <SOME_DATABASE> -f <SOME_SQL_FILE>

However, when using the pg:psql command line utility in Heroku, that option doesn't seem to be available. So I'm currently having to use it like so:

heroku pg:psql DATABASE -a <SOME_HEROKU_APP> < <SOME_SQL_FILE>

which produces a lot of output to my console (hundreds of thousands of lines), because of the large size of the SQL file I'm importing. Whenever I try to use the -q or --quiet option, something like this:

heroku pg:psql DATABASE -q -a <SOME_HEROKU_APP> < <SOME_SQL_FILE>

it'll throw an error saying that -q is not a valid option.

Is there some way to enable quiet mode when running Postgres commands in Heroku?

解决方案

heroku pg:psql is just a wrapper onto your local psql binary (github/heroku/heroku/blob/master/lib/heroku/command/pg.rb#L151)

So, given this - you are able to do:

psql `heroku config:get DATABASE_URL -a <yourappname>`

to get a psql connection and consequently pass -q other options accordingly.

更多推荐

如何在Heroku上为Postgres命令启用安静模式

本文发布于:2023-10-13 09:32:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487576.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上为   安静   命令   模式   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!