diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 36a1ba46d5b..dceb8cdfd43 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3039,8 +3039,21 @@ lo_import 152801 Controls use of a pager program for query and psql - help output. If the environment variable PSQL_PAGER - or PAGER is set, the output is piped to the + help output. + When the pager option is off, the pager + program is not used. When the pager option is + on, the pager is used when appropriate, i.e., when the + output is to a terminal and will not fit on the screen. + The pager option can also be set to always, + which causes the pager to be used for all terminal output regardless + of whether it fits on the screen. \pset pager + without a value + toggles pager use on and off. + + + + If the environment variable PSQL_PAGER + or PAGER is set, output to be paged is piped to the specified program. Otherwise a platform-dependent default program (such as more) is used. @@ -3054,18 +3067,6 @@ lo_import 152801 psql's output format (such as pspg --stream). - - - When the pager option is off, the pager - program is not used. When the pager option is - on, the pager is used when appropriate, i.e., when the - output is to a terminal and will not fit on the screen. - The pager option can also be set to always, - which causes the pager to be used for all terminal output regardless - of whether it fits on the screen. \pset pager - without a value - toggles pager use on and off. - @@ -4775,7 +4776,7 @@ PSQL_EDITOR_LINENUMBER_ARG='--line ' pager-related options of the \pset command. These variables are examined in the order listed; the first that is set is used. - If none of them is set, the default is to use more on most + If neither of them is set, the default is to use more on most platforms, but less on Cygwin. diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index bb94df50a63..897fbee8d6c 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -5020,14 +5020,20 @@ do_watch(PQExpBuffer query_buf, double sleep) /* * For \watch, we ignore the size of the result and always use the pager - * if PSQL_WATCH_PAGER is set. We also ignore the regular PSQL_PAGER or - * PAGER environment variables, because traditional pagers probably won't - * be very useful for showing a stream of results. + * as long as we're talking to a terminal and "\pset pager" is enabled. + * However, we'll only use the pager identified by PSQL_WATCH_PAGER. We + * ignore the regular PSQL_PAGER or PAGER environment variables, because + * traditional pagers probably won't be very useful for showing a stream + * of results. */ #ifdef HAVE_POSIX_DECL_SIGWAIT pagerprog = getenv("PSQL_WATCH_PAGER"); + /* if variable is empty or all-white-space, don't use pager */ + if (pagerprog && strspn(pagerprog, " \t\r\n") == strlen(pagerprog)) + pagerprog = NULL; #endif - if (pagerprog && myopt.topt.pager) + if (pagerprog && myopt.topt.pager && + isatty(fileno(stdin)) && isatty(fileno(stdout))) { disable_sigpipe_trap(); pagerpipe = popen(pagerprog, "w");