postgresql 是否有像“psql --quiet”这样的“pg_restore --quiet”选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11485358/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:06:13  来源:igfitidea点击:

Is there a "pg_restore --quiet" option like "psql --quiet"?

postgresqlpostgresql-9.1psqlpg-restore

提问by Rob Bednark

psqlhas a -q/ --quietoption (environment variable QUIET). pg_restoredoes not have a quiet option. Is there any way to make pg_restorenot verbosely show the SQL commands that it's executing?

psql有一个-q/--quiet选项(环境变量QUIET)。 pg_restore没有安静的选择。有什么方法可以pg_restore不详细显示它正在执行的 SQL 命令?

# e.g., here's the verbose output that I don't want to see:
$ pg_restore --cluster 8.4/mycluster mycluster.dump
---- PostgreSQL database dump
--
SET statement_timeout = 0;SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;SET check_function_bodies = false;
...
--
-- Name: data_src; Type: TABLE; Schema: public; Owner: postgres; Tablespace:--
CREATE TABLE data_src (
...

回答by Daniel Vérité

The question seems to imply that pg_restoreis executing these SQL commands and you wouldn't want to see them in the output. But outputting them is what it's only supposed to do.

这个问题似乎暗示pg_restore正在执行这些 SQL 命令并且您不希望在输出中看到它们。但是输出它们只是它应该做的。

pg_restorehas two modes of operation, with or without connecting to a database. When it's called without a database (-doption) as shown in the question:

pg_restore有两种操作模式,连接或不连接数据库。当它在没有数据库(-d选项)的情况下调用时,如问题所示:

$ pg_restore --cluster 8.4/mycluster mycluster.dump

$ pg_restore --cluster 8.4/mycluster mycluster.dump

then its sole purpose is to output a set of SQL commands in plain text that should be fed to an SQL interpreter to restore the database. Those SQL commands form a coherent set without any concept of verbosity, and they are not executedby pg_restoreitself. They're generally redirected into a file for later execution or piped into psqlfor immediate execution.

那么它的唯一目的是以纯文本形式输出一组 SQL 命令,这些命令应该提供给 SQL 解释器以恢复数据库。这些SQL命令形成了一整套无冗长的任何概念,他们不执行pg_restore本身。它们通常被重定向到一个文件中以供稍后执行或通过管道输入psql以立即执行。

回答by Ligemer

You can redirect stdout to a file:

您可以将标准输出重定向到文件:

pg_restore --cluster 8.4/mycluster mycluster.dump > pg_restore.log

Or provide the -d option, but what you want is either -for -d

或提供 -d 选项,但您想要的是-f-d

pg_restore -f pg_restore.sql --cluster 8.4/mycluster mycluster.dump
pg_restore -d yourdatabase --cluster 8.4/mycluster mycluster.dump