pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: luis.roberto@siscobra.com.br
To: Charles Clavadetscher <clavadetscher@swisspug.org>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Table sizes
Date: Wed, 30 Sep 2020 10:54:32 -0300 (BRT)
Message-ID: <56108176.54473966.1601474072988.JavaMail.zimbra@siscobra.com.br> (raw)
In-Reply-To: <899489bcefe7f21b9db422b1ca797e15@swisspug.org>
References: <78366091.53791693.1601467902283.JavaMail.zimbra@siscobra.com.br>
	<899489bcefe7f21b9db422b1ca797e15@swisspug.org>




De: "Charles Clavadetscher" <clavadetscher@swisspug.org> 
Para: "luis.roberto" <luis.roberto@siscobra.com.br> 
Cc: "pgsql-general" <pgsql-general@lists.postgresql.org> 
Enviadas: Quarta-feira, 30 de setembro de 2020 10:46:39 
Assunto: Re: Table sizes 

Hello 

On 2020-09-30 14:11, luis.roberto@siscobra.com.br wrote: 
> Hi! 
> 
> I'm trying to use this query to get table sizes, however I'm getting a 
> strange error: 
> 
> select tablename,pg_relation_size(tablename::text) 
> from pg_tables; 
> 
> In PG 13: 
> 
> SQL Error [42P01]: ERROR: relation "sql_implementation_info" does not 
> exist 
> 
> In PG 12: 
> 
> SQL Error [42P01]: ERROR: relation "sql_parts" does not exist 

Try like this: 

select schemaname, 
tablename, 
pg_relation_size((schemaname || '.' || '"' || tablename || 
'"')::regclass) 
from pg_tables; 

You need to schema qualify the tables. Additionally, if you happen to 
have table names that have a mix of capital and non capital letters or 
contain other characters that might be problematic, you need to enclose 
the table name in double quotes. 

Regards 
Charles 

-- 
Charles Clavadetscher 
Swiss PostgreSQL Users Group 
Treasurer 
Spitzackerstrasse 9 
CH - 8057 Zürich 

http://www.swisspug.org 

+---------------------------+ 
| ____ ______ ___ | 
| / )/ \/ \ | 
| ( / __ _\ ) | 
| \ (/ o) ( o) ) | 
| \_ (_ ) \ ) _/ | 
| \ /\_/ \)/ | 
| \/ <//| |\\> | 
| _| | | 
| \|_/ | 
| | 
| Swiss PostgreSQL | 
| Users Group | 
| | 
+---------------------------+ 





Thanks, this worked. 

I wonder though, why calling pg_relation_size('users') work (I don't need to specify the schema). 

view thread (6+ messages)  latest in thread

Message-ID: <56108176.54473966.1601474072988.JavaMail.zimbra@siscobra.com.br>
Permalink:  ../56108176.54473966.1601474072988.JavaMail.zimbra@siscobra.com.br/
Also on:    postgresql.org/message-id/56108176.54473966.1601474072988.JavaMail.zimbra@siscobra.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: luis.roberto@siscobra.com.br, clavadetscher@swisspug.org
  Subject: Re: Table sizes
  In-Reply-To: <56108176.54473966.1601474072988.JavaMail.zimbra@siscobra.com.br>
  References: <78366091.53791693.1601467902283.JavaMail.zimbra@siscobra.com.br> <899489bcefe7f21b9db422b1ca797e15@swisspug.org> <56108176.54473966.1601474072988.JavaMail.zimbra@siscobra.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox