disable NOTICES in psql output

2019-03-08 23:26发布

问题:

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.

回答1:

SET client_min_messages TO WARNING;

That could be set only for the session or made persistent with ALTER ROLE or ALTER DATABASE.

Or you could put that in your ".psqlrc".



回答2:

Probably the most comprehensive explanation is on Peter Eisentrauts blog entry here

I would strongly encourage that the original blog be studied and digested but the final recommendation is something like :

PGOPTIONS='--client-min-messages=warning' psql -X -q -a -1 -v ON_ERROR_STOP=1 --pset pager=off -d mydb -f script.sql


回答3:

Use --quiet when you start psql.

A notice is not useless, but that's my point of view.



回答4:

It can be set in the global postgresql.conf file as well with modifiying the client_min_messages parameter.

Example:

client_min_messages = warning