禁用 psql 输出中的 NOTICES
如何阻止 psql(PostgreSQL 客户端)输出通知?例如
psql:schema/auth.sql:20: 注意:CREATE TABLE / PRIMARY KEY 将为表“users”创建隐式索引“users_pkey”
在我看来,程序应该保持沉默,除非它有错误或其他原因输出内容。
How do I stop psql (PostgreSQL client) from outputting notices? e.g.
psql:schema/auth.sql:20: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users"
In my opinion a program should be silent unless it has an error, or some other reason to output stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
提供一个对我的特定场景有用的建议:
示例:(
我是无法使用 PGOPTIONS 作为 Windows 环境变量——无法找出正确的语法。尝试了不同帖子中的多种方法。)
Offering a suggestion that is useful for a specific scenario I had:
Example:
(I was unable to make things work with PGOPTIONS as a Windows environment variable--couldn't work out the right syntax. Tried multiple approaches from different posts.)
我尝试了该线程中建议的各种解决方案(及其排列),但我无法完全抑制 PSQL 输出/通知。
我正在执行一个
claws2postgres.sh
BASH 脚本,该脚本会进行一些初步处理,然后调用/执行 PSQL .sql 脚本,以将 1000 个条目插入到 PostgreSQL 中。输出
解决方案
请注意这个修改后的 PSQL 行,我在其中重定向了 psql 输出:
&>> /tmp/pg_output.txt
重定向将所有输出附加到输出文件,该文件也可以用作日志文件。BASH 终端输出
监控进度:
在另一个终端中,执行
pgrep -l -f couchs2postgres.sh | grep 爪子 | awk '{ print $1 }'
获取脚本 PID,分配给 $PIDwhile Kill -0 $PID >/dev/null 2>&1; do ...
:当该脚本运行时,执行...cat /tmp/pg_output.txt | 使用输出文件行数作为进度指示器
phaser.wav
5 次来通知Phaser.wav:https://persagen.com/files/misc/phaser.wav输出文件:
参考资料
[相关 SO 线程] Postgresql - 有没有办法在从文件读入时禁用 INSERT 语句的显示?< /p>
[与解决方案相关] https://askubuntu.com/questions/350208/what-does-2-dev-null-mean
I tried the various solutions suggested (and permutations thereof) suggested in this thread, but I was unable to completely suppress PSQL output / notifications.
I am executing a
claws2postgres.sh
BASH script that does some preliminary processing then calls/executes a PSQL .sql script, to insert 1000's of entries into PostgreSQL.Output
SOLUTION
Note this modified PSQL line, where I redirect the psql output:
The
&>> /tmp/pg_output.txt
redirect appends all output to an output file, that can also serve as a log file.BASH terminal output
Monitor progress:
In another terminal, execute
pgrep -l -f claws2postgres.sh | grep claws | awk '{ print $1 }'
gets the script PID, assigned to $PIDwhile kill -0 $PID >/dev/null 2>&1; do ...
: while that script is running, do ...cat /tmp/pg_output.txt | wc -l
: use the output file line count as a progress indicatorphaser.wav
5 timesOutput file:
References
[related SO thread] Postgresql - is there a way to disable the display of INSERT statements when reading in from a file?
[relevant to solution] https://askubuntu.com/questions/350208/what-does-2-dev-null-mean
它可以在全局
postgresql.conf
文件中设置,也可以通过修改client_min_messages
参数来设置。例子:
It can be set in the global
postgresql.conf
file as well with modifiying theclient_min_messages
parameter.Example:
启动 psql 时使用
--quiet
。通知并非毫无用处,但这就是我的观点。
Use
--quiet
when you start psql.A notice is not useless, but that's my point of view.
也许最全面的解释是 Peter Eisentrauts 博客条目< /a> (存档)
我强烈鼓励研究和消化原始博客,但最终的建议是这样的:
Probably the most comprehensive explanation is on Peter Eisentrauts blog entry here (Archive)
I would strongly encourage that the original blog be studied and digested but the final recommendation is something like :
那可能是仅为会话设置或使用
ALTER ROLE
或更改数据库
。或者您可以将其放入 ".psqlrc" 中。
That could be set only for the session or made persistent with
ALTER ROLE
orALTER DATABASE
.Or you could put that in your ".psqlrc".