psql

Posted on:

The PostgreSQL client tool psql automatically uses a pager to scroll through results when they do not fit on the screen. Many users utilize this feature without being aware of it, but the pager typically provides a simple function to “display one screen at a time and allow scrolling.” However, ov offers a wide range of features that are convenient for handling data, such as automatic recognition of headers and columns, color coding for each column, fixed display, search and filter capabilities, and column shrinking and alignment. This allows for a more readable and efficient way to review the output of psql. See also Setting the PAGER for PSQL.

psql

This is the recommended setting for PSQL_PAGER. Header 1 is specified (-H1). “|” is used to separate columns (-d "|"), and column mode (-C) is set. Exit the pager (-F) if the content fits on the screen. It is also recommended to change the color of the columns(--column-rainbow).

The --align option added in v0.37.0 can also be used to shrink columns.

PSQL_PAGER='ov -F -C -d "|" -H1 --column-rainbow --align'

The following sets the header style of config.yaml.

StyleHeader:
  Background: "#23274f"
  Bold: true
StyleColumnHighlight:
  Foreground: "lightcyan"
  Reverse: true
StyleAlternate:
  Background: "#2a2a2a"

psql psql

watch(PostgreSQL 15)

A pager is available for WATCH from PostgreSQL version 15. This is the recommended value for PSQL_WATCH_PAGER. Continues to display the last section separated by blank lines.

PSQL_WATCH_PAGER='ov --follow-section --section-delimiter "^$"'

watch watch

expanded output (\x)

When displaying in the extended output (\x), treat the record delimiter as a section delimiter. This will make the display easier to see when moved.

PAGER='ov -F --section-delimiter "^-"'

\\x \\x

You can also display expanded output (\x) with \watch.

watch2 watch2

unaligned (\a)

By specifying \a on the psql side, you can display without alignment (without aligning columns). This is done by specifying the --align option of ov.

PSQL_PAGER='ov -F -C -d "|" -H1 --column-rainbow --align'

unalign unalign

shrink columns and fixed columns

You can also shrink columns and fix the width of columns with the --align option.

When in align mode, you can shrink the currently selected column by pressing s (default key).
Additionally, by pressing F (default key), all columns to the left of the selected column will be fixed and remain visible while scrolling horizontally.

PSQL_PAGER='ov -F -C -d "|" -H1 --column-rainbow --align'

shrink shrink