Waiting for 8.4 – \o and \d+ in psql

Today, we have 2 new changes in psql. One of them is not actually new feature, but I decided to write about it anyway, because of its implications.

First (which was actually committed second), is patch from Dickson S. Guedes, committed by Heikki Linnakangas

Commit message was quite small, but it does explain what the new code does:

Show relation size in verbose (e.g. \d+) output.
Dickson S. Guedes

So, with this patch applied, if I'll list all my tables with “+", I will get:

# \d+
                                   List of relations
 Schema |             Name             |   Type   | Owner |    Size    | Description
--------+------------------------------+----------+-------+------------+-------------
 public | payments                     | table    | test  | 8192 bytes |
 public | payments_id_seq              | sequence | test  | 8192 bytes |
 public | people                       | table    | test  | 848 kB     |
 public | people_id_seq                | sequence | test  | 8192 bytes |
 public | product_stock_changes        | table    | test  | 104 kB     |
 public | product_stock_changes_id_seq | sequence | test  | 8192 bytes |
 public | products                     | table    | test  | 264 kB     |
 public | products_id_seq              | sequence | test  | 8192 bytes |
 public | sales                        | table    | test  | 1464 kB    |
 public | sales_id_seq                 | sequence | test  | 8192 bytes |
 public | sold_products                | table    | test  | 1032 kB    |
 public | sold_products_id_seq         | sequence | test  | 8192 bytes |
(12 rows)

As You can see, there is new column: “Size". What it shows is rather obvious.

Of course not only \d+ was extended – \dt+, \dS+, \di+.

Now for the second patch.

Bernd Helmle wrote, and Peter Eisentraut committed a patch which requires space between single character \X commands in psql.

In case You're not familiar with it, psql allows You to do many cool things using \X commands. \d, \l, \x are the most commonly used, but some other are even more interesting.

For example \o <filename>. It allows You to redirect query output to file (or program via pipe).

What this patch does, it explicitly forbids writing these “\X argument" commands without first space.

So, with 8.3 You could do:

\o/tmp/filename

but in 8.4, You will get an error:

# \o/tmp/filename
Invalid command \o/tmp/filename. Try \? for help.

(of course, not only \o is modified, all single-letter commands that take arguments)

Now, You might ask – why? Did it bother anyone? It was cool, and You used it without space?

Well, making the parser a bit strict is a first step for a really cool new feature that might make it to 8.4 (but there is no guarantee): psql aliases.

What it means is that You will be able to make Your own \xxxxx commands. Ever felt that there should be some \dL to show locks? Or maybe You'd like to bind Your own favorite query to some short \xxxx command?

Of course it will take some time to get aliasing in psql, but at least – first step has been made.

2 thoughts on “Waiting for 8.4 – \o and \d+ in psql”

  1. Command alias sound fantastic. First thing I’d set up is one to query against pg_stat_activity for a quick way to see currently-running queries…

Comments are closed.