Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable NOTICES in psql output

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.

like image 917
xenoterracide Avatar asked Aug 20 '10 12:08

xenoterracide


People also ask

How do I get out of psql mode?

Type \q and then press ENTER to quit psql . As of PostgreSQL 11, the keywords " quit " and " exit " in the PostgreSQL command-line interface have been included to help make it easier to leave the command-line tool.

What is raise notice in PostgreSQL?

RAISE is used to raise errors and report messages, PostgreSQL provides various parameters to report an error, warning, and information at a detailed level.

What are psql meta commands?

Meta-Commands. Anything you enter in psql that begins with an unquoted backslash is a psql meta-command that is processed by psql itself. These commands make psql more useful for administration or scripting. Meta-commands are often called slash or backslash commands.

What is the psql command for toggle timing of commands?

To turn on query execution time, you use the \timing command.


2 Answers

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".

like image 80
Milen A. Radev Avatar answered Sep 21 '22 19:09

Milen A. Radev


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 :

PGOPTIONS='--client-min-messages=warning' psql -X -q -a -1 -v ON_ERROR_STOP=1 --pset pager=off -d mydb -f script.sql 
like image 25
Gavin Avatar answered Sep 19 '22 19:09

Gavin