Skip to content

Commit cba9cd4

Browse files
committed
Make psql use pg_table_size instead of pg_relation_size on 9.0+ servers.
Per discussion, pg_table_size() is a more helpful number than pg_relation_size(). Bernd Helmle, reviewed by Susanne Ebrecht and me.
1 parent 0bd155c commit cba9cd4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/bin/psql/describe.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -2522,14 +2522,25 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
25222522
",\n c2.relname as \"%s\"",
25232523
gettext_noop("Table"));
25242524

2525-
if (verbose && pset.sversion >= 80100)
2526-
appendPQExpBuffer(&buf,
2527-
",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
2528-
gettext_noop("Size"));
25292525
if (verbose)
2526+
{
2527+
/*
2528+
* As of PostgreSQL 9.0, use pg_table_size() to show a more acurate size
2529+
* of a table, including FSM, VM and TOAST tables.
2530+
*/
2531+
if (pset.sversion >= 90000)
2532+
appendPQExpBuffer(&buf,
2533+
",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"",
2534+
gettext_noop("Size"));
2535+
else if (pset.sversion >= 80100)
2536+
appendPQExpBuffer(&buf,
2537+
",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"",
2538+
gettext_noop("Size"));
2539+
25302540
appendPQExpBuffer(&buf,
25312541
",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
25322542
gettext_noop("Description"));
2543+
}
25332544

25342545
appendPQExpBuffer(&buf,
25352546
"\nFROM pg_catalog.pg_class c"

0 commit comments

Comments
 (0)