Re: Making psql error out on output failures - Mailing list pgsql-hackers

From David Zhang
Subject Re: Making psql error out on output failures
Date
Msg-id 157911333817.709.14442233793862477339.pgcf@coridan.postgresql.org
Whole thread Raw
In response to Re: Making psql error out on output failures  ("Daniel Verite" <daniel@manitou-mail.org>)
Responses Re: Making psql error out on output failures  ("Daniel Verite" <daniel@manitou-mail.org>)
List pgsql-hackers
Right, the file difference is caused by "-At". 

On the other side, in order to keep the output message more consistent with other tools, I did a litter bit more
investigationon pg_dump to see how it handles this situation. Here is my findings.
 
pg_dump using WRITE_ERROR_EXIT to throw the error message when "(bytes_written != size * nmemb)", where
WRITE_ERROR_EXITcalls fatal("could not write to output file: %m") and then "pg_log_generic(PG_LOG_ERROR, __VA_ARGS__)".
Afterran a quick test in the same situation, I got message like below,
 
$ pg_dump -h localhost -p 5432  -d postgres -t psql_error -f /mnt/ramdisk/file
pg_dump: error: could not write to output file: No space left on device

If I change the error log message like below, where "%m" is used to pass the value of strerror(errno), "could not write
tooutput file:" is copied from function "WRITE_ERROR_EXIT". 
 
-            pg_log_error("Error printing tuples");
+            pg_log_error("could not write to output file: %m");
then the output message is something like below, which, I believe, is more consistent with pg_dump.
$ psql -d postgres  -t -c "select repeat('111', 1000000)" -o /mnt/ramdisk/file
could not write to output file: No space left on device
$ psql -d postgres  -t -c "select repeat('111', 1000000)" > /mnt/ramdisk/file
could not write to output file: No space left on device

Hope the information will help.

David
---
Highgo Software Inc. (Canada)
www.highgo.ca

pgsql-hackers by date:

Previous
From: Juan José Santamaría Flecha
Date:
Subject: Re: Allow to_date() and to_timestamp() to accept localized names
Next
From: Robert Haas
Date:
Subject: Re: our checks for read-only queries are not great