当在本地机器上使用 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 $ c $
在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命令启用安静模式
发布评论