On 13-06-2018 22:59, Alvaro Herrera wrote:
For context: in the backend, elog() is only used for internal messages
(i.e. "can't-happen" conditions), and ereport() is used for user-facing
messages. There are many things ereport() has that elog() doesn't,
such
as additional message fields (HINT, DETAIL, etc) that I think could
have
some use in pgbench as well. If you use elog() then you can't have
that.
AFAIU originally it was not supposed that the pgbench error messages
have these fields, so will it be good to change the final output to
stderr?.. For example:
- fprintf(stderr, "%s", PQerrorMessage(con));
- fprintf(stderr, "(ignoring this error and continuing
anyway)\n");
+ ereport(LOG,
+ (errmsg("Ignoring the server error and continuing
anyway"),
+ errdetail("%s", PQerrorMessage(con))));
- fprintf(stderr, "%s", PQerrorMessage(con));
- if (sqlState && strcmp(sqlState,
ERRCODE_UNDEFINED_TABLE) == 0)
- {
- fprintf(stderr, "Perhaps you need to do initialization (\"pgbench
-i\") in database \"%s\"\n", PQdb(con));
- }
-
- exit(1);
+ ereport(ERROR,
+ (errmsg("Server error"),
+ errdetail("%s", PQerrorMessage(con)),
+ sqlState && strcmp(sqlState,
ERRCODE_UNDEFINED_TABLE) == 0 ?
+ errhint("Perhaps you need to do initialization (\"pgbench -i\")
in database \"%s\"\n",
+ PQdb(con)) : 0));
--
Marina Polyakova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company