How to enable quiet mode for Postgres commands on Heroku

霸气de小男生 提交于 2019-12-13 16:22:49

问题


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?


回答1:


heroku pg:psql is just a wrapper onto your local psql binary (https://github.com/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.



来源:https://stackoverflow.com/questions/34700261/how-to-enable-quiet-mode-for-postgres-commands-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!