controlling psql's use of the pager a bit more
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.
Thoughts?
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 13 November 2014 15:52, Andrew Dunstan <andrew@dunslane.net> wrote:
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this is
to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify a
minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.
+1
I've found this annoying myself.
--
Thom
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.
Are you saying you'd want to set the threshold to *more* than the window
height? Why?
My impression is that the problem is not with the threshold as such,
it's that psql is not terribly careful about determining how many lines
it will put out (ie, the value being compared to the threshold isn't
100% reliable). If that's correct, then a hand-set threshold isn't
really going to make you happier, and what's needed is some hard work
on improving the quality of the lines-to-be-output estimates.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2014-11-13 11:09:06 -0500, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the window
height? Why?
Not sure what that'd be useful for.
What I've noticed more than once is that it'd be useful to force the
pager if the result is wider than the screen.
My impression is that the problem is not with the threshold as such,
it's that psql is not terribly careful about determining how many lines
it will put out (ie, the value being compared to the threshold isn't
100% reliable). If that's correct, then a hand-set threshold isn't
really going to make you happier, and what's needed is some hard work
on improving the quality of the lines-to-be-output estimates.
If it's that, I've personally solved that problem for me by adding -F
(aka --quit-if-one-screen) to $LESS.
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 11/13/2014 11:09 AM, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the window
height? Why?
Because I might be quite happy with 100 or 200 lines I can just scroll
in my terminal's scroll buffer, but want to use the pager for more than
that. This is useful especially if I want to scroll back and see the
results from a query or two ago.
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, Nov 13, 2014 at 05:14:47PM +0100, Andres Freund wrote:
On 2014-11-13 11:09:06 -0500, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the window
height? Why?Not sure what that'd be useful for.
If the output is of the same order of magnitude as the window height, it
is still easy to compare the new output with whatever was above it by
conventional terminal scrolling (pgup, screen scrolling, whatever, if
present). If a comparison is desired in the first place, that is.
If the output goes to the pager, you're stuck with it. Unless of course
if the pager could somehow include the previous output up to some
threshold (while still being positioned at the beginning of the new
output in order to retain current behaviour), so one could scroll up in
the pager window. That would rock.
Michael
--
Michael Banck
Tel.: +49 (0) 2161 / 4643-171
credativ GmbH, HRB M�nchengladbach 12080
Hohenzollernstr. 133, 41061 M�nchengladbach
Gesch�ftsf�hrung: Dr. Michael Meskes, J�rg Folz, Sascha Heuer
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Andrew Dunstan wrote
On 11/13/2014 11:09 AM, Tom Lane wrote:
Andrew Dunstan <
andrew@
> writes:
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the window
height? Why?Because I might be quite happy with 100 or 200 lines I can just scroll
in my terminal's scroll buffer, but want to use the pager for more than
that. This is useful especially if I want to scroll back and see the
results from a query or two ago.
+1
David J.
--
View this message in context: http://postgresql.nabble.com/controlling-psql-s-use-of-the-pager-a-bit-more-tp5826819p5826833.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, Nov 13, 2014 at 11:54 AM, David G Johnston
<david.g.johnston@gmail.com> wrote:
Because I might be quite happy with 100 or 200 lines I can just scroll
in my terminal's scroll buffer, but want to use the pager for more than
that. This is useful especially if I want to scroll back and see the
results from a query or two ago.+1
+1 from me, too.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, Nov 13, 2014 at 11:39 AM, Robert Haas <robertmhaas@gmail.com> wrote:
On Thu, Nov 13, 2014 at 11:54 AM, David G Johnston
<david.g.johnston@gmail.com> wrote:Because I might be quite happy with 100 or 200 lines I can just scroll
in my terminal's scroll buffer, but want to use the pager for more than
that. This is useful especially if I want to scroll back and see the
results from a query or two ago.+1
+1 from me, too.
me three (as long as the current behaviors are not messed with and the
new stuff is 'opt in' somehow -- I also use the force quit option to
less).
merlin
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Thu, Nov 13, 2014 at 10:55 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
On Thu, Nov 13, 2014 at 11:39 AM, Robert Haas <robertmhaas@gmail.com>
wrote:On Thu, Nov 13, 2014 at 11:54 AM, David G Johnston
<david.g.johnston@gmail.com> wrote:Because I might be quite happy with 100 or 200 lines I can just scroll
in my terminal's scroll buffer, but want to use the pager for more than
that. This is useful especially if I want to scroll back and see the
results from a query or two ago.+1
+1 from me, too.
me three (as long as the current behaviors are not messed with and the
new stuff is 'opt in' somehow -- I also use the force quit option to
less).
Being able to use "\pset pager"
to toggle the capability seems useful.
Thus I'd suggest establishing a new "pager_minlines" option that if unset
(default) maintains the current behavior but which can have a value (0 to
int_max) where 0 ends up basically doing the same thing as "always" mode
for "pager". Leaving the value blank will cause the option to be unset
again and revert to the current behavior.
David J.
On Thu, Nov 13, 2014 at 7:52 AM, Andrew Dunstan <andrew@dunslane.net> wrote:
I often get annoyed because psql is a bit too aggressive when it decides
whether to put output through the pager, and the only way to avoid this is
to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify a
minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.
+1.
If it scrolls 2 or 3 lines off the top, I can just use the scroll-back
buffer to look at them, I don't want the pager for that situation.
But I am more interested in width, not length. I don't want it to switch
to the pager just because a couple lines would wrap, especially when
looking at EXPLAIN output. I have played with changing \pset columns, but
then other things get screwy once you set that to a non-actual value. I
don't recall of the top of my head which things those are, though.
Cheers,
Jeff
On Thu, Nov 13, 2014 at 8:14 AM, Andres Freund <andres@2ndquadrant.com>
wrote:
On 2014-11-13 11:09:06 -0500, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it
decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the window
height? Why?Not sure what that'd be useful for.
What I've noticed more than once is that it'd be useful to force the
pager if the result is wider than the screen.
For which formats do you want that? It is already done that way under
\pset format aligned.
Cheers,
Jeff
On Thu, Nov 13, 2014 at 12:03 PM, David Johnston
<david.g.johnston@gmail.com> wrote:
On Thu, Nov 13, 2014 at 10:55 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
On Thu, Nov 13, 2014 at 11:39 AM, Robert Haas <robertmhaas@gmail.com>
wrote:On Thu, Nov 13, 2014 at 11:54 AM, David G Johnston
<david.g.johnston@gmail.com> wrote:Because I might be quite happy with 100 or 200 lines I can just scroll
in my terminal's scroll buffer, but want to use the pager for more
than
that. This is useful especially if I want to scroll back and see the
results from a query or two ago.+1
+1 from me, too.
me three (as long as the current behaviors are not messed with and the
new stuff is 'opt in' somehow -- I also use the force quit option to
less).Being able to use "\pset pager"
to toggle the capability seems useful.
Thus I'd suggest establishing a new "pager_minlines" option that if unset
(default) maintains the current behavior but which can have a value (0 to
int_max) where 0 ends up basically doing the same thing as "always" mode for
"pager". Leaving the value blank will cause the option to be unset again
and revert to the current behavior.
seems pretty reasonable.
merlin
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 11/13/2014 11:41 AM, Andrew Dunstan wrote:
On 11/13/2014 11:09 AM, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it
decides
whether to put output through the pager, and the only way to avoid this
is to turn the pager off (in which case your next query might dump many
thousands of lines to the screen). I'd like a way to be able to specify
a minumum number of lines of output before psql would invoke the pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the window
height? Why?Because I might be quite happy with 100 or 200 lines I can just scroll
in my terminal's scroll buffer, but want to use the pager for more
than that. This is useful especially if I want to scroll back and see
the results from a query or two ago.
This patch shows more or less what I had in mind.
However, there is more work to do. As Tom noted upthread, psql's
calculation of the number of lines is pretty bad. For example, if I do:
\pset pager_min_lines 100
select * from generate_series(1,50);
the pager still gets invoked, which is unfortunate to say the least.
So I'm going to take a peek at that.
cheers
andrew
Attachments:
psqllines.patchtext/x-diff; name=psqllines.patchDownload
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 26089352..b16149a 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -786,7 +786,7 @@ exec_command(const char *cmd,
opt[--len] = '\0';
}
- helpSQL(opt, pset.popt.topt.pager);
+ helpSQL(opt, pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
free(opt);
}
@@ -1053,7 +1053,8 @@ exec_command(const char *cmd,
static const char *const my_list[] = {
"border", "columns", "expanded", "fieldsep", "fieldsep_zero",
"footer", "format", "linestyle", "null",
- "numericlocale", "pager", "recordsep", "recordsep_zero",
+ "numericlocale", "pager", "pager_min_lines",
+ "recordsep", "recordsep_zero",
"tableattr", "title", "tuples_only",
"unicode_border_linestyle",
"unicode_column_linestyle",
@@ -1252,7 +1253,8 @@ exec_command(const char *cmd,
lines++;
}
- output = PageOutput(lineno, pset.popt.topt.pager);
+ output = PageOutput(lineno, pset.popt.topt.pager,
+ pset.popt.topt.pager_min_lines);
is_pager = true;
}
else
@@ -1504,13 +1506,13 @@ exec_command(const char *cmd,
OT_NORMAL, NULL, false);
if (!opt0 || strcmp(opt0, "commands") == 0)
- slashUsage(pset.popt.topt.pager);
+ slashUsage(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
else if (strcmp(opt0, "options") == 0)
- usage(pset.popt.topt.pager);
+ usage(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
else if (strcmp(opt0, "variables") == 0)
- helpVariables(pset.popt.topt.pager);
+ helpVariables(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
else
- slashUsage(pset.popt.topt.pager);
+ slashUsage(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
}
#if 0
@@ -2506,6 +2508,13 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt->topt.pager = 1;
}
+ /* set minimum lines for pager use */
+ else if (strcmp(param, "pager_min_lines") == 0)
+ {
+ if (value)
+ popt->topt.pager_min_lines = atoi(value);
+ }
+
/* disable "(x rows)" footer */
else if (strcmp(param, "footer") == 0)
{
@@ -2627,6 +2636,13 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
printf(_("Pager usage is off.\n"));
}
+ /* show minimum lines for pager use */
+ else if (strcmp(param, "pager_min_lines") == 0)
+ {
+ printf(_("Pager won't be used for less than %d lines\n"),
+ popt->topt.pager_min_lines);
+ }
+
/* show record separator for unaligned text */
else if (strcmp(param, "recordsep") == 0)
{
@@ -2779,6 +2795,8 @@ pset_value_string(const char *param, struct printQueryOpt *popt)
return pstrdup(pset_bool_string(popt->topt.numericLocale));
else if (strcmp(param, "pager") == 0)
return psprintf("%d", popt->topt.pager);
+ else if (strcmp(param, "pager_min_lines") == 0)
+ return psprintf("%d", popt->topt.pager_min_lines);
else if (strcmp(param, "recordsep") == 0)
return pset_quoted_string(popt->topt.recordSep.separator
? popt->topt.recordSep.separator
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 66d80b5..91102f4 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1337,7 +1337,8 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
* If query requires multiple result sets, hack to ensure that
* only one pager instance is used for the whole mess
*/
- pset.queryFout = PageOutput(100000, my_popt.topt.pager);
+ pset.queryFout = PageOutput(100000, my_popt.topt.pager,
+ my_popt.topt.pager_min_lines);
did_pager = true;
}
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index ae5fe88..bb166b9 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -46,7 +46,7 @@
#define ON(var) (var ? _("on") : _("off"))
void
-usage(unsigned short int pager)
+usage(unsigned short int pager, int pager_min_lines)
{
const char *env;
const char *user;
@@ -65,7 +65,7 @@ usage(unsigned short int pager)
}
}
- output = PageOutput(59, pager);
+ output = PageOutput(59, pager, pager_min_lines);
fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
fprintf(output, _("Usage:\n"));
@@ -151,14 +151,14 @@ usage(unsigned short int pager)
* print out help for the backslash commands
*/
void
-slashUsage(unsigned short int pager)
+slashUsage(unsigned short int pager, int pager_min_lines)
{
FILE *output;
char *currdb;
currdb = PQdb(pset.db);
- output = PageOutput(103, pager);
+ output = PageOutput(103, pager, pager_min_lines);
/* if you add/remove a line here, change the row count above */
@@ -301,11 +301,11 @@ slashUsage(unsigned short int pager)
* show list of available variables (options) from command line
*/
void
-helpVariables(unsigned short int pager)
+helpVariables(unsigned short int pager, int pager_min_lines)
{
FILE *output;
- output = PageOutput(85, pager);
+ output = PageOutput(85, pager, pager_min_lines);
fprintf(output, _("List of specially treated variables.\n"));
@@ -406,7 +406,7 @@ helpVariables(unsigned short int pager)
* Note: we assume caller removed any trailing spaces in "topic".
*/
void
-helpSQL(const char *topic, unsigned short int pager)
+helpSQL(const char *topic, unsigned short int pager, int pager_min_lines)
{
#define VALUE_OR_NULL(a) ((a) ? (a) : "")
@@ -435,7 +435,7 @@ helpSQL(const char *topic, unsigned short int pager)
ncolumns = Max(ncolumns, 1);
nrows = (QL_HELP_COUNT + (ncolumns - 1)) / ncolumns;
- output = PageOutput(nrows + 1, pager);
+ output = PageOutput(nrows + 1, pager, pager_min_lines);
fputs(_("Available help:\n"), output);
@@ -488,7 +488,7 @@ helpSQL(const char *topic, unsigned short int pager)
if (wordlen >= len) /* Don't try again if the same word */
{
if (!output)
- output = PageOutput(nl_count, pager);
+ output = PageOutput(nl_count, pager, pager_min_lines);
break;
}
len = wordlen;
@@ -509,7 +509,7 @@ helpSQL(const char *topic, unsigned short int pager)
}
if (!output)
- output = PageOutput(nl_count, pager);
+ output = PageOutput(nl_count, pager, pager_min_lines);
for (i = 0; QL_HELP[i].cmd; i++)
{
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 3ad374a..646d080 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -8,13 +8,14 @@
#ifndef HELP_H
#define HELP_H
-void usage(unsigned short int pager);
+void usage(unsigned short int pager, int pager_min_lines);
-void slashUsage(unsigned short int pager);
+void slashUsage(unsigned short int pager, int pager_min_lines);
-void helpVariables(unsigned short int pager);
+void helpVariables(unsigned short int pager, int pager_min_lines);
-void helpSQL(const char *topic, unsigned short int pager);
+void helpSQL(const char *topic, unsigned short int pager,
+ int pager_min_lines);
void print_copyright(void);
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index 6416ab9..01111e8 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -479,7 +479,7 @@ printHistory(const char *fname, unsigned short int pager)
if (fname == NULL)
{
/* use pager, if enabled, when printing to console */
- output = PageOutput(INT_MAX, pager);
+ output = PageOutput(INT_MAX, pager, 0);
is_pager = true;
}
else
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 3b3c3b7..2e158b8 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -811,7 +811,8 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
if (!is_pager && fout == stdout && output_columns > 0 &&
(output_columns < total_header_width || output_columns < width_total))
{
- fout = PageOutput(INT_MAX, cont->opt->pager); /* force pager */
+ fout = PageOutput(INT_MAX, cont->opt->pager,
+ cont->opt->pager_min_lines); /* force pager */
is_pager = true;
}
@@ -2487,7 +2488,7 @@ print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
* Tests if pager is needed and returns appropriate FILE pointer.
*/
FILE *
-PageOutput(int lines, unsigned short int pager)
+PageOutput(int lines, unsigned short int pager, int min_lines)
{
/* check whether we need / can / are supposed to use pager */
if (pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
@@ -2502,7 +2503,9 @@ PageOutput(int lines, unsigned short int pager)
result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
/* >= accounts for a one-line prompt */
- if (result == -1 || lines >= screen_size.ws_row || pager > 1)
+ if (result == -1
+ || (lines >= screen_size.ws_row && lines >= min_lines)
+ || pager > 1)
{
#endif
pagerprog = getenv("PAGER");
@@ -2802,7 +2805,8 @@ IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expande
lines++;
}
- *fout = PageOutput(lines + extra_lines, cont->opt->pager);
+ *fout = PageOutput(lines + extra_lines, cont->opt->pager,
+ cont->opt->pager_min_lines);
*is_pager = (*fout != stdout);
}
else
diff --git a/src/bin/psql/print.h b/src/bin/psql/print.h
index f668b23..3510f7a 100644
--- a/src/bin/psql/print.h
+++ b/src/bin/psql/print.h
@@ -89,6 +89,8 @@ typedef struct printTableOpt
* 1=dividing lines, 2=full */
unsigned short int pager; /* use pager for output (if to stdout and
* stdout is a tty) 0=off 1=on 2=always */
+ int pager_min_lines;/* don't use pager unless there are at least
+ * this many lines */
bool tuples_only; /* don't output headers, row counts, etc. */
bool start_table; /* print start decoration, eg <table> */
bool stop_table; /* print stop decoration, eg </table> */
@@ -164,7 +166,7 @@ extern const printTextFormat pg_asciiformat_old;
extern const printTextFormat pg_utf8format;
-extern FILE *PageOutput(int lines, unsigned short int pager);
+extern FILE *PageOutput(int lines, unsigned short int pager, int min_lines);
extern void ClosePager(FILE *pagerpipe);
extern void html_escaped_print(const char *in, FILE *fout);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 11a159a..174c481 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -100,7 +100,7 @@ main(int argc, char *argv[])
{
if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0)))
{
- usage(NOPAGER);
+ usage(NOPAGER, 0);
exit(EXIT_SUCCESS);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
@@ -129,6 +129,7 @@ main(int argc, char *argv[])
pset.popt.topt.format = PRINT_ALIGNED;
pset.popt.topt.border = 1;
pset.popt.topt.pager = 1;
+ pset.popt.topt.pager_min_lines = 0;
pset.popt.topt.start_table = true;
pset.popt.topt.stop_table = true;
pset.popt.topt.default_footer = true;
@@ -569,7 +570,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
/* Actual help option given */
if (strcmp(argv[optind - 1], "-?") == 0)
{
- usage(NOPAGER);
+ usage(NOPAGER, 0);
exit(EXIT_SUCCESS);
}
/* unknown option reported by getopt */
@@ -579,11 +580,11 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
case 1:
{
if (!optarg || strcmp(optarg, "options") == 0)
- usage(NOPAGER);
+ usage(NOPAGER, 0);
else if (optarg && strcmp(optarg, "commands") == 0)
- slashUsage(NOPAGER);
+ slashUsage(NOPAGER, 0);
else if (optarg && strcmp(optarg, "variables") == 0)
- helpVariables(NOPAGER);
+ helpVariables(NOPAGER, 0);
else
goto unknown_option;
Andrew Dunstan wrote:
However, there is more work to do. As Tom noted upthread, psql's calculation
of the number of lines is pretty bad. For example, if I do:\pset pager_min_lines 100
select * from generate_series(1,50);the pager still gets invoked, which is unfortunate to say the least.
So I'm going to take a peek at that.
Any luck there?
--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 12/04/2014 03:53 PM, Alvaro Herrera wrote:
Andrew Dunstan wrote:
However, there is more work to do. As Tom noted upthread, psql's calculation
of the number of lines is pretty bad. For example, if I do:\pset pager_min_lines 100
select * from generate_series(1,50);the pager still gets invoked, which is unfortunate to say the least.
So I'm going to take a peek at that.
Any luck there?
Some, yes, See
<http://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=4077fb4d1d34ad04dfb95ba676c2b43ea1f1da53>
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 11/15/2014 05:56 PM, Andrew Dunstan wrote:
On 11/13/2014 11:41 AM, Andrew Dunstan wrote:
On 11/13/2014 11:09 AM, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it
decides
whether to put output through the pager, and the only way to avoid
this
is to turn the pager off (in which case your next query might dump
many
thousands of lines to the screen). I'd like a way to be able to
specify
a minumum number of lines of output before psql would invoke the
pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the
window
height? Why?Because I might be quite happy with 100 or 200 lines I can just
scroll in my terminal's scroll buffer, but want to use the pager for
more than that. This is useful especially if I want to scroll back
and see the results from a query or two ago.This patch shows more or less what I had in mind.
However, there is more work to do. As Tom noted upthread, psql's
calculation of the number of lines is pretty bad. For example, if I do:\pset pager_min_lines 100
select * from generate_series(1,50);the pager still gets invoked, which is unfortunate to say the least.
So I'm going to take a peek at that.
The over-eager invocation of the pager due to double counting of lines
got fixed recently, so here's a slightly updated patch for a
pager_min_lines setting, including docco.
cheers
andrew
Attachments:
psqlminlines.patchtext/x-patch; name=psqlminlines.patchDownload
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index e7fcc73..4201847 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2236,6 +2236,18 @@ lo_import 152801
</varlistentry>
<varlistentry>
+ <term><literal>pager_min_lines</literal></term>
+ <listitem>
+ <para>
+ If <literal>pager_min_lines</> is set to a number greater than the
+ page height, the pager program will not be called unless there are
+ at least this many lines of output to show. The default setting
+ is 0.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>recordsep</literal></term>
<listitem>
<para>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index c7a17d7..2703850 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -807,7 +807,7 @@ exec_command(const char *cmd,
opt[--len] = '\0';
}
- helpSQL(opt, pset.popt.topt.pager);
+ helpSQL(opt, pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
free(opt);
}
@@ -1074,7 +1074,8 @@ exec_command(const char *cmd,
static const char *const my_list[] = {
"border", "columns", "expanded", "fieldsep", "fieldsep_zero",
"footer", "format", "linestyle", "null",
- "numericlocale", "pager", "recordsep", "recordsep_zero",
+ "numericlocale", "pager", "pager_min_lines",
+ "recordsep", "recordsep_zero",
"tableattr", "title", "tuples_only",
"unicode_border_linestyle",
"unicode_column_linestyle",
@@ -1268,7 +1269,8 @@ exec_command(const char *cmd,
lines++;
}
- output = PageOutput(lineno, pset.popt.topt.pager);
+ output = PageOutput(lineno, pset.popt.topt.pager,
+ pset.popt.topt.pager_min_lines);
is_pager = true;
}
else
@@ -1520,13 +1522,13 @@ exec_command(const char *cmd,
OT_NORMAL, NULL, false);
if (!opt0 || strcmp(opt0, "commands") == 0)
- slashUsage(pset.popt.topt.pager);
+ slashUsage(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
else if (strcmp(opt0, "options") == 0)
- usage(pset.popt.topt.pager);
+ usage(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
else if (strcmp(opt0, "variables") == 0)
- helpVariables(pset.popt.topt.pager);
+ helpVariables(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
else
- slashUsage(pset.popt.topt.pager);
+ slashUsage(pset.popt.topt.pager, pset.popt.topt.pager_min_lines);
}
#if 0
@@ -2522,6 +2524,13 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt->topt.pager = 1;
}
+ /* set minimum lines for pager use */
+ else if (strcmp(param, "pager_min_lines") == 0)
+ {
+ if (value)
+ popt->topt.pager_min_lines = atoi(value);
+ }
+
/* disable "(x rows)" footer */
else if (strcmp(param, "footer") == 0)
{
@@ -2643,6 +2652,13 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
printf(_("Pager usage is off.\n"));
}
+ /* show minimum lines for pager use */
+ else if (strcmp(param, "pager_min_lines") == 0)
+ {
+ printf(_("Pager won't be used for less than %d lines\n"),
+ popt->topt.pager_min_lines);
+ }
+
/* show record separator for unaligned text */
else if (strcmp(param, "recordsep") == 0)
{
@@ -2795,6 +2811,8 @@ pset_value_string(const char *param, struct printQueryOpt *popt)
return pstrdup(pset_bool_string(popt->topt.numericLocale));
else if (strcmp(param, "pager") == 0)
return psprintf("%d", popt->topt.pager);
+ else if (strcmp(param, "pager_min_lines") == 0)
+ return psprintf("%d", popt->topt.pager_min_lines);
else if (strcmp(param, "recordsep") == 0)
return pset_quoted_string(popt->topt.recordSep.separator
? popt->topt.recordSep.separator
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 66d80b5..91102f4 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1337,7 +1337,8 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
* If query requires multiple result sets, hack to ensure that
* only one pager instance is used for the whole mess
*/
- pset.queryFout = PageOutput(100000, my_popt.topt.pager);
+ pset.queryFout = PageOutput(100000, my_popt.topt.pager,
+ my_popt.topt.pager_min_lines);
did_pager = true;
}
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index ae5fe88..bb166b9 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -46,7 +46,7 @@
#define ON(var) (var ? _("on") : _("off"))
void
-usage(unsigned short int pager)
+usage(unsigned short int pager, int pager_min_lines)
{
const char *env;
const char *user;
@@ -65,7 +65,7 @@ usage(unsigned short int pager)
}
}
- output = PageOutput(59, pager);
+ output = PageOutput(59, pager, pager_min_lines);
fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
fprintf(output, _("Usage:\n"));
@@ -151,14 +151,14 @@ usage(unsigned short int pager)
* print out help for the backslash commands
*/
void
-slashUsage(unsigned short int pager)
+slashUsage(unsigned short int pager, int pager_min_lines)
{
FILE *output;
char *currdb;
currdb = PQdb(pset.db);
- output = PageOutput(103, pager);
+ output = PageOutput(103, pager, pager_min_lines);
/* if you add/remove a line here, change the row count above */
@@ -301,11 +301,11 @@ slashUsage(unsigned short int pager)
* show list of available variables (options) from command line
*/
void
-helpVariables(unsigned short int pager)
+helpVariables(unsigned short int pager, int pager_min_lines)
{
FILE *output;
- output = PageOutput(85, pager);
+ output = PageOutput(85, pager, pager_min_lines);
fprintf(output, _("List of specially treated variables.\n"));
@@ -406,7 +406,7 @@ helpVariables(unsigned short int pager)
* Note: we assume caller removed any trailing spaces in "topic".
*/
void
-helpSQL(const char *topic, unsigned short int pager)
+helpSQL(const char *topic, unsigned short int pager, int pager_min_lines)
{
#define VALUE_OR_NULL(a) ((a) ? (a) : "")
@@ -435,7 +435,7 @@ helpSQL(const char *topic, unsigned short int pager)
ncolumns = Max(ncolumns, 1);
nrows = (QL_HELP_COUNT + (ncolumns - 1)) / ncolumns;
- output = PageOutput(nrows + 1, pager);
+ output = PageOutput(nrows + 1, pager, pager_min_lines);
fputs(_("Available help:\n"), output);
@@ -488,7 +488,7 @@ helpSQL(const char *topic, unsigned short int pager)
if (wordlen >= len) /* Don't try again if the same word */
{
if (!output)
- output = PageOutput(nl_count, pager);
+ output = PageOutput(nl_count, pager, pager_min_lines);
break;
}
len = wordlen;
@@ -509,7 +509,7 @@ helpSQL(const char *topic, unsigned short int pager)
}
if (!output)
- output = PageOutput(nl_count, pager);
+ output = PageOutput(nl_count, pager, pager_min_lines);
for (i = 0; QL_HELP[i].cmd; i++)
{
diff --git a/src/bin/psql/help.h b/src/bin/psql/help.h
index 3ad374a..646d080 100644
--- a/src/bin/psql/help.h
+++ b/src/bin/psql/help.h
@@ -8,13 +8,14 @@
#ifndef HELP_H
#define HELP_H
-void usage(unsigned short int pager);
+void usage(unsigned short int pager, int pager_min_lines);
-void slashUsage(unsigned short int pager);
+void slashUsage(unsigned short int pager, int pager_min_lines);
-void helpVariables(unsigned short int pager);
+void helpVariables(unsigned short int pager, int pager_min_lines);
-void helpSQL(const char *topic, unsigned short int pager);
+void helpSQL(const char *topic, unsigned short int pager,
+ int pager_min_lines);
void print_copyright(void);
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index 6416ab9..01111e8 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -479,7 +479,7 @@ printHistory(const char *fname, unsigned short int pager)
if (fname == NULL)
{
/* use pager, if enabled, when printing to console */
- output = PageOutput(INT_MAX, pager);
+ output = PageOutput(INT_MAX, pager, 0);
is_pager = true;
}
else
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index fd26d6d..256c333 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -811,7 +811,8 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
if (!is_pager && fout == stdout && output_columns > 0 &&
(output_columns < total_header_width || output_columns < width_total))
{
- fout = PageOutput(INT_MAX, cont->opt->pager); /* force pager */
+ fout = PageOutput(INT_MAX, cont->opt->pager,
+ cont->opt->pager_min_lines); /* force pager */
is_pager = true;
}
@@ -2488,7 +2489,7 @@ print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
* Tests if pager is needed and returns appropriate FILE pointer.
*/
FILE *
-PageOutput(int lines, unsigned short int pager)
+PageOutput(int lines, unsigned short int pager, int min_lines)
{
/* check whether we need / can / are supposed to use pager */
if (pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
@@ -2503,7 +2504,9 @@ PageOutput(int lines, unsigned short int pager)
result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
/* >= accounts for a one-line prompt */
- if (result == -1 || lines >= screen_size.ws_row || pager > 1)
+ if (result == -1
+ || (lines >= screen_size.ws_row && lines >= min_lines)
+ || pager > 1)
{
#endif
pagerprog = getenv("PAGER");
@@ -2803,7 +2806,8 @@ IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expande
lines++;
}
- *fout = PageOutput(lines + extra_lines, cont->opt->pager);
+ *fout = PageOutput(lines + extra_lines, cont->opt->pager,
+ cont->opt->pager_min_lines);
*is_pager = (*fout != stdout);
}
else
diff --git a/src/bin/psql/print.h b/src/bin/psql/print.h
index f668b23..3510f7a 100644
--- a/src/bin/psql/print.h
+++ b/src/bin/psql/print.h
@@ -89,6 +89,8 @@ typedef struct printTableOpt
* 1=dividing lines, 2=full */
unsigned short int pager; /* use pager for output (if to stdout and
* stdout is a tty) 0=off 1=on 2=always */
+ int pager_min_lines;/* don't use pager unless there are at least
+ * this many lines */
bool tuples_only; /* don't output headers, row counts, etc. */
bool start_table; /* print start decoration, eg <table> */
bool stop_table; /* print stop decoration, eg </table> */
@@ -164,7 +166,7 @@ extern const printTextFormat pg_asciiformat_old;
extern const printTextFormat pg_utf8format;
-extern FILE *PageOutput(int lines, unsigned short int pager);
+extern FILE *PageOutput(int lines, unsigned short int pager, int min_lines);
extern void ClosePager(FILE *pagerpipe);
extern void html_escaped_print(const char *in, FILE *fout);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 11a159a..174c481 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -100,7 +100,7 @@ main(int argc, char *argv[])
{
if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0)))
{
- usage(NOPAGER);
+ usage(NOPAGER, 0);
exit(EXIT_SUCCESS);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
@@ -129,6 +129,7 @@ main(int argc, char *argv[])
pset.popt.topt.format = PRINT_ALIGNED;
pset.popt.topt.border = 1;
pset.popt.topt.pager = 1;
+ pset.popt.topt.pager_min_lines = 0;
pset.popt.topt.start_table = true;
pset.popt.topt.stop_table = true;
pset.popt.topt.default_footer = true;
@@ -569,7 +570,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
/* Actual help option given */
if (strcmp(argv[optind - 1], "-?") == 0)
{
- usage(NOPAGER);
+ usage(NOPAGER, 0);
exit(EXIT_SUCCESS);
}
/* unknown option reported by getopt */
@@ -579,11 +580,11 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
case 1:
{
if (!optarg || strcmp(optarg, "options") == 0)
- usage(NOPAGER);
+ usage(NOPAGER, 0);
else if (optarg && strcmp(optarg, "commands") == 0)
- slashUsage(NOPAGER);
+ slashUsage(NOPAGER, 0);
else if (optarg && strcmp(optarg, "variables") == 0)
- helpVariables(NOPAGER);
+ helpVariables(NOPAGER, 0);
else
goto unknown_option;
On 12/21/2014 02:22 PM, Andrew Dunstan wrote:
On 11/15/2014 05:56 PM, Andrew Dunstan wrote:
On 11/13/2014 11:41 AM, Andrew Dunstan wrote:
On 11/13/2014 11:09 AM, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I often get annoyed because psql is a bit too aggressive when it
decides
whether to put output through the pager, and the only way to avoid
this
is to turn the pager off (in which case your next query might dump
many
thousands of lines to the screen). I'd like a way to be able to
specify
a minumum number of lines of output before psql would invoke the
pager,
rather than just always using the terminal window size.Are you saying you'd want to set the threshold to *more* than the
window
height? Why?Because I might be quite happy with 100 or 200 lines I can just
scroll in my terminal's scroll buffer, but want to use the pager for
more than that. This is useful especially if I want to scroll back
and see the results from a query or two ago.This patch shows more or less what I had in mind.
However, there is more work to do. As Tom noted upthread, psql's
calculation of the number of lines is pretty bad. For example, if I do:\pset pager_min_lines 100
select * from generate_series(1,50);the pager still gets invoked, which is unfortunate to say the least.
So I'm going to take a peek at that.
The over-eager invocation of the pager due to double counting of lines
got fixed recently, so here's a slightly updated patch for a
pager_min_lines setting, including docco.
The assigned reviewer hasn't done a review and hasn't responded to
email. If there are no other comments I propose to commit this shortly.
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2014-12-21 14:22:10 -0500, Andrew Dunstan wrote:
@@ -301,11 +301,11 @@ slashUsage(unsigned short int pager) * show list of available variables (options) from command line */ void -helpVariables(unsigned short int pager) +helpVariables(unsigned short int pager, int pager_min_lines) { FILE *output;
Odd space before pager_min_lines.
Without having actually tried it, it looks clean enough to me. If
there's more pager options we might at some point introduce a pager
options struct instead adding more options to PageOutput. But for now it
seems ok enough.
Greetings,
Andres Freund
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Andres Freund <andres@2ndquadrant.com> writes:
Without having actually tried it, it looks clean enough to me. If
there's more pager options we might at some point introduce a pager
options struct instead adding more options to PageOutput. But for now it
seems ok enough.
My reaction is that now would be the time to do that, really. This is
messing up the argument lists of what seems like a whole lot of functions,
and I have little faith that this is the last argument we'll need to add.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 03/26/2015 11:10 AM, Tom Lane wrote:
Andres Freund <andres@2ndquadrant.com> writes:
Without having actually tried it, it looks clean enough to me. If
there's more pager options we might at some point introduce a pager
options struct instead adding more options to PageOutput. But for now it
seems ok enough.My reaction is that now would be the time to do that, really. This is
messing up the argument lists of what seems like a whole lot of functions,
and I have little faith that this is the last argument we'll need to add.
*grumble*
OK , I'll take a look.
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 03/26/2015 11:10 AM, Tom Lane wrote:
Andres Freund <andres@2ndquadrant.com> writes:
Without having actually tried it, it looks clean enough to me. If
there's more pager options we might at some point introduce a pager
options struct instead adding more options to PageOutput. But for now it
seems ok enough.My reaction is that now would be the time to do that, really. This is
messing up the argument lists of what seems like a whole lot of functions,
and I have little faith that this is the last argument we'll need to add.
OK, this version only changes the signature of one function:
PageOutput(), which instead of taking just the pager flag takes a
pointer to the whole printTableOpt structure that contains both the
pager and pager_min_lines settings (NULL means don't use the pager).
That makes the patch smaller and less invasive, and a bit more future-proof.
cheers
andrew
Attachments:
psqlminlines2.patchtext/x-patch; name=psqlminlines2.patchDownload
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index a637001..a33e460 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -2236,6 +2236,18 @@ lo_import 152801
</varlistentry>
<varlistentry>
+ <term><literal>pager_min_lines</literal></term>
+ <listitem>
+ <para>
+ If <literal>pager_min_lines</> is set to a number greater than the
+ page height, the pager program will not be called unless there are
+ at least this many lines of output to show. The default setting
+ is 0.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>recordsep</literal></term>
<listitem>
<para>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 7c9f28d..e64c033 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1071,7 +1071,8 @@ exec_command(const char *cmd,
static const char *const my_list[] = {
"border", "columns", "expanded", "fieldsep", "fieldsep_zero",
"footer", "format", "linestyle", "null",
- "numericlocale", "pager", "recordsep", "recordsep_zero",
+ "numericlocale", "pager", "pager_min_lines",
+ "recordsep", "recordsep_zero",
"tableattr", "title", "tuples_only",
"unicode_border_linestyle",
"unicode_column_linestyle",
@@ -1265,7 +1266,7 @@ exec_command(const char *cmd,
lines++;
}
- output = PageOutput(lineno, pset.popt.topt.pager);
+ output = PageOutput(lineno, &(pset.popt.topt));
is_pager = true;
}
else
@@ -2519,6 +2520,13 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
popt->topt.pager = 1;
}
+ /* set minimum lines for pager use */
+ else if (strcmp(param, "pager_min_lines") == 0)
+ {
+ if (value)
+ popt->topt.pager_min_lines = atoi(value);
+ }
+
/* disable "(x rows)" footer */
else if (strcmp(param, "footer") == 0)
{
@@ -2640,6 +2648,13 @@ printPsetInfo(const char *param, struct printQueryOpt *popt)
printf(_("Pager usage is off.\n"));
}
+ /* show minimum lines for pager use */
+ else if (strcmp(param, "pager_min_lines") == 0)
+ {
+ printf(_("Pager won't be used for less than %d lines\n"),
+ popt->topt.pager_min_lines);
+ }
+
/* show record separator for unaligned text */
else if (strcmp(param, "recordsep") == 0)
{
@@ -2792,6 +2807,8 @@ pset_value_string(const char *param, struct printQueryOpt *popt)
return pstrdup(pset_bool_string(popt->topt.numericLocale));
else if (strcmp(param, "pager") == 0)
return psprintf("%d", popt->topt.pager);
+ else if (strcmp(param, "pager_min_lines") == 0)
+ return psprintf("%d", popt->topt.pager_min_lines);
else if (strcmp(param, "recordsep") == 0)
return pset_quoted_string(popt->topt.recordSep.separator
? popt->topt.recordSep.separator
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 15488ff..2e7d9a4 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1337,7 +1337,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
* If query requires multiple result sets, hack to ensure that
* only one pager instance is used for the whole mess
*/
- pset.queryFout = PageOutput(100000, my_popt.topt.pager);
+ pset.queryFout = PageOutput(100000, &(my_popt.topt));
did_pager = true;
}
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index ac0dc27..2da444b 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -65,7 +65,7 @@ usage(unsigned short int pager)
}
}
- output = PageOutput(59, pager);
+ output = PageOutput(59, pager ? &(pset.popt.topt) : NULL);
fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
fprintf(output, _("Usage:\n"));
@@ -158,7 +158,7 @@ slashUsage(unsigned short int pager)
currdb = PQdb(pset.db);
- output = PageOutput(103, pager);
+ output = PageOutput(103, pager ? &(pset.popt.topt) : NULL);
/* if you add/remove a line here, change the row count above */
@@ -305,7 +305,7 @@ helpVariables(unsigned short int pager)
{
FILE *output;
- output = PageOutput(85, pager);
+ output = PageOutput(85, pager ? &(pset.popt.topt) : NULL);
fprintf(output, _("List of specially treated variables.\n"));
@@ -435,7 +435,7 @@ helpSQL(const char *topic, unsigned short int pager)
ncolumns = Max(ncolumns, 1);
nrows = (QL_HELP_COUNT + (ncolumns - 1)) / ncolumns;
- output = PageOutput(nrows + 1, pager);
+ output = PageOutput(nrows + 1, pager ? &(pset.popt.topt) : NULL);
fputs(_("Available help:\n"), output);
@@ -488,7 +488,7 @@ helpSQL(const char *topic, unsigned short int pager)
if (wordlen >= len) /* Don't try again if the same word */
{
if (!output)
- output = PageOutput(nl_count, pager);
+ output = PageOutput(nl_count, pager ? &(pset.popt.topt) : NULL);
break;
}
len = wordlen;
@@ -509,7 +509,7 @@ helpSQL(const char *topic, unsigned short int pager)
}
if (!output)
- output = PageOutput(nl_count, pager);
+ output = PageOutput(nl_count, pager ? &(pset.popt.topt) : NULL);
for (i = 0; QL_HELP[i].cmd; i++)
{
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index d52a334..437fa4d 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -474,7 +474,7 @@ printHistory(const char *fname, unsigned short int pager)
if (fname == NULL)
{
/* use pager, if enabled, when printing to console */
- output = PageOutput(INT_MAX, pager);
+ output = PageOutput(INT_MAX, pager ? &(pset.popt.topt) : NULL);
is_pager = true;
}
else
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 40e5098..7c435fd 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -811,7 +811,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
if (!is_pager && fout == stdout && output_columns > 0 &&
(output_columns < total_header_width || output_columns < width_total))
{
- fout = PageOutput(INT_MAX, cont->opt->pager); /* force pager */
+ fout = PageOutput(INT_MAX, cont->opt); /* force pager */
is_pager = true;
}
@@ -2497,15 +2497,19 @@ print_troff_ms_vertical(const printTableContent *cont, FILE *fout)
* PageOutput
*
* Tests if pager is needed and returns appropriate FILE pointer.
+ *
+ * If the topt argument is NULL no pager is used.
*/
FILE *
-PageOutput(int lines, unsigned short int pager)
+PageOutput(int lines, const printTableOpt *topt)
{
/* check whether we need / can / are supposed to use pager */
- if (pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
+ if (topt && topt->pager && isatty(fileno(stdin)) && isatty(fileno(stdout)))
{
const char *pagerprog;
FILE *pagerpipe;
+ unsigned short int pager = topt->pager;
+ int min_lines = topt->pager_min_lines;
#ifdef TIOCGWINSZ
int result;
@@ -2514,7 +2518,9 @@ PageOutput(int lines, unsigned short int pager)
result = ioctl(fileno(stdout), TIOCGWINSZ, &screen_size);
/* >= accounts for a one-line prompt */
- if (result == -1 || lines >= screen_size.ws_row || pager > 1)
+ if (result == -1
+ || (lines >= screen_size.ws_row && lines >= min_lines)
+ || pager > 1)
{
#endif
pagerprog = getenv("PAGER");
@@ -2814,7 +2820,7 @@ IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expande
lines++;
}
- *fout = PageOutput(lines + extra_lines, cont->opt->pager);
+ *fout = PageOutput(lines + extra_lines, cont->opt);
*is_pager = (*fout != stdout);
}
else
diff --git a/src/bin/psql/print.h b/src/bin/psql/print.h
index a1a89d0..66cdaf3 100644
--- a/src/bin/psql/print.h
+++ b/src/bin/psql/print.h
@@ -89,6 +89,8 @@ typedef struct printTableOpt
* 1=dividing lines, 2=full */
unsigned short int pager; /* use pager for output (if to stdout and
* stdout is a tty) 0=off 1=on 2=always */
+ int pager_min_lines;/* don't use pager unless there are at least
+ * this many lines */
bool tuples_only; /* don't output headers, row counts, etc. */
bool start_table; /* print start decoration, eg <table> */
bool stop_table; /* print stop decoration, eg </table> */
@@ -164,7 +166,7 @@ extern const printTextFormat pg_asciiformat_old;
extern const printTextFormat pg_utf8format;
-extern FILE *PageOutput(int lines, unsigned short int pager);
+extern FILE *PageOutput(int lines, const printTableOpt *topt);
extern void ClosePager(FILE *pagerpipe);
extern void html_escaped_print(const char *in, FILE *fout);
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 7f09c14..d57901f 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -129,6 +129,7 @@ main(int argc, char *argv[])
pset.popt.topt.format = PRINT_ALIGNED;
pset.popt.topt.border = 1;
pset.popt.topt.pager = 1;
+ pset.popt.topt.pager_min_lines = 0;
pset.popt.topt.start_table = true;
pset.popt.topt.stop_table = true;
pset.popt.topt.default_footer = true;
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index e87b82b..a2a2615 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -65,6 +65,7 @@ linestyle ascii
null ''
numericlocale off
pager 1
+pager_min_lines 0
recordsep '\n'
recordsep_zero off
tableattr