diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 5e4e0fd9d62..03f069838b0 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3354,8 +3354,9 @@ $endif If the query results do not fit on the screen, they are piped through this command. Typical values are more or less. The default - is platform-dependent. The use of the pager can be disabled by - using the \pset command. + is platform-dependent. Use of the pager can be disabled by setting + PAGER to empty, or by using pager-related options of + the \pset command. diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 12a5421f1e3..bf5f4ff5671 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -2075,6 +2075,12 @@ PageOutput(int lines, unsigned short int pager) pagerprog = getenv("PAGER"); if (!pagerprog) pagerprog = DEFAULT_PAGER; + else + { + /* if PAGER is empty or all-white-space, don't use pager */ + if (strspn(pagerprog, " \t\r\n") == strlen(pagerprog)) + return stdout; + } #ifndef WIN32 pqsignal(SIGPIPE, SIG_IGN); #endif diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index 585e831cdb6..cb360c36a18 100644 --- a/src/interfaces/libpq/fe-print.c +++ b/src/interfaces/libpq/fe-print.c @@ -167,8 +167,9 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po) screen_size.ws_col = 80; #endif pagerenv = getenv("PAGER"); + /* if PAGER is unset, empty or all-white-space, don't use pager */ if (pagerenv != NULL && - pagerenv[0] != '\0' && + strspn(pagerenv, " \t\r\n") != strlen(pagerenv) && !po->html3 && ((po->expanded && nTups * (nFields + 1) >= screen_size.ws_row) ||