Sunday, July 16, 2017

Postgres Pager (pager designed for psql)

I hope so every, who uses psql uses less pager as default pager. See important Merlin's article. less is great pager, but it is not designed for usage as pager of relational data, and miss some features. Mainly, there is not possible to freeze some rows and some columns. I didn't find any solution good enough for me, although there are some projects on github. The special pager for psql should to have some logic, to choose correctly and automatically frozen columns (in chars) and rows.

I wrote new pager pspg - Postgres pager. This pager is designed primary for usage as psql pager. Now, it is available for playing and testing. Probably there will be some unwanted artefacts - but for usual work it is good enough. It is first my ncurses applications, probably there will be some bugs.

This pager currently supports:
* possibility to set one from three themes from command line: -s 0 - black/white theme, -s 1 mc theme, -s 2 fox theme,
* possibility to set frozen columns from command line: -c N or interactively (0..4),
* first few rows with labels are frozen automatically,
* scrolling: left, rights, up, down, PgUp, PgDn, ^PgUp, ^PgDn,
* possibility to run demo from command line: -d,
* supports different psql border linestyles: ascii, unicode,
* supports different psql border levels: 0, 1, 2

export PAGER="pspg" #default theme 1
psql dbname
\pset border 2 #best works with border 2, but others are supported too
export PAGER="pspg -s 0" #black white theme
psql dbname

  • black white theme -s 0
  • midnight commander theme -s 1
  • fox theme -s 2

I invite any cooperation with people with ncurses knowleadge. All patches are welcome.


At July 16, 2017 at 6:35 AM , Blogger John Frazer said...

Great thing, I've been looking for something like this, especially the ability to freeze rows and/or columns. Could you write about how to compile pspg? I tried `cd pspg; make` and I get `pager.c:1:20: fatal error: curses.h: No such file or directory`.

At July 16, 2017 at 6:58 AM , Blogger Pavel Stěhule said...

you are missing ncurses dev libraries - maybe ncurses-devel

At July 16, 2017 at 7:25 AM , Blogger John Frazer said...

Yes, i did `sudo apt-get install build-essential libreadline-dev libncurses5-dev libncursesw5-dev`, so that should be alright... still getting errors about unreslved references. I opened an issue on

At July 16, 2017 at 8:40 AM , Blogger Pavel Stěhule said...

looks like linker issue. try to check

At July 16, 2017 at 8:42 AM , Blogger Pavel Stěhule said...

I am building on Fedora 26 (Centos), so there should be some differences and some options for linker should be necessary

At August 7, 2017 at 1:14 PM , Blogger Unknown said...

Is great the back to foxpro colors.


At September 12, 2017 at 1:21 PM , Blogger Rolf said...

I changed
gcc -lncursesw pager.c -o pspg -ggdb
gcc pager.c -o pspg -ggdb -lncursesw

on ubuntu 14.04 (gcc 4.8.4) and it compiled and works very well.

At September 19, 2017 at 3:25 AM , Blogger andreak said...

I'm not able to copy from the console using the mouse as ncurses captures the event and selects the row I'm clicking on. Any way to prevent this so I can use the mouse to select/copy text from the console?


At December 1, 2017 at 11:12 AM , Blogger Pavel Stěhule said...

@andreak - you can disable mouse by Alt M or use --no-mouse option.

At April 28, 2022 at 7:05 PM , Anonymous Ian Z said...

Hi / Ahoj,

is the config file format ( ~/.pspgconf ) documented anywhere? As it is, I'm trying to grok the code in pspg/config.c which is really not cool after a tough day at work :(


At August 28, 2022 at 4:52 AM , Blogger Pavel Stěhule said...

@Ian Z - you can execute save setup Menu|Options|Save setup. It does an template with current setup


Post a Comment

Subscribe to Post Comments [Atom]

<< Home