Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNcZJ-0001gv-I3 for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 13:54:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kNcZH-0003JB-Mu for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 13:54:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNcZH-0003J4-F6 for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 13:54:51 +0000 Received: from mxh01aws49.mxout.inova.com.br ([34.198.242.49] helo=mxhero01.a.inova.com.br) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNcZ6-0006Dw-Er for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 13:54:51 +0000 Received: from ip-10-0-4-78.ec2.internal (localhost [127.0.0.1]) by mxhero01.a.inova.com.br (Postfix) with ESMTP id 80EF01CA72A for ; Wed, 30 Sep 2020 13:54:37 +0000 (UTC) Received: from corpmoutpolicyd01.a.inova.com.br (puppetmaster.a.inova.com.br [10.0.1.88]) by mxhero01.a.inova.com.br (Postfix) with ESMTP; Wed, 30 Sep 2020 13:54:37 +0000 (UTC) Received: from corpmoutpolicyd01.a.inova.com.br (localhost [127.0.0.1]) by corpmoutpolicyd01.a.inova.com.br (Postfix) with ESMTP id 70DB6220C03; Wed, 30 Sep 2020 10:54:34 -0300 (BRT) Received: from corpmout01.a.inova.com.br (ip-10-0-1-125.ec2.internal [10.0.1.125]) by corpmoutpolicyd01.a.inova.com.br (Postfix) with ESMTP id 1778ABA4D5; Wed, 30 Sep 2020 10:54:33 -0300 (BRT) Received: from corpmbox02.a.inova.com.br (ip-10-0-4-158.ec2.internal [10.0.4.158]) by corpmout01.a.inova.com.br (Postfix) with ESMTP; Wed, 30 Sep 2020 10:54:33 -0300 (-03) Date: Wed, 30 Sep 2020 10:54:32 -0300 (BRT) From: luis.roberto@siscobra.com.br To: Charles Clavadetscher Cc: pgsql-general Message-ID: <56108176.54473966.1601474072988.JavaMail.zimbra@siscobra.com.br> In-Reply-To: <899489bcefe7f21b9db422b1ca797e15@swisspug.org> References: <78366091.53791693.1601467902283.JavaMail.zimbra@siscobra.com.br> <899489bcefe7f21b9db422b1ca797e15@swisspug.org> Subject: Re: Table sizes MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_f7b6ca01-1024-4380-aa2e-1e702777731a" X-Originating-IP: [10.0.1.247] X-Mailer: Zimbra 8.8.15_GA_3955 (ZimbraWebClient - GC85 (Win)/8.8.15_GA_3953) Thread-Topic: Table sizes Thread-Index: R7+1aPrSSkyrx3myQOoQesdz6Gvl7Q== x-mxHero-Origin-Ip: /127.0.0.1:51422 X-mxHero-AttachmentBlock: rule=48;result=false List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_f7b6ca01-1024-4380-aa2e-1e702777731a Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable De: "Charles Clavadetscher" =20 Para: "luis.roberto" =20 Cc: "pgsql-general" =20 Enviadas: Quarta-feira, 30 de setembro de 2020 10:46:39=20 Assunto: Re: Table sizes=20 Hello=20 On 2020-09-30 14:11, luis.roberto@siscobra.com.br wrote:=20 > Hi!=20 >=20 > I'm trying to use this query to get table sizes, however I'm getting a=20 > strange error:=20 >=20 > select tablename,pg_relation_size(tablename::text)=20 > from pg_tables;=20 >=20 > In PG 13:=20 >=20 > SQL Error [42P01]: ERROR: relation "sql_implementation_info" does not=20 > exist=20 >=20 > In PG 12:=20 >=20 > SQL Error [42P01]: ERROR: relation "sql_parts" does not exist=20 Try like this:=20 select schemaname,=20 tablename,=20 pg_relation_size((schemaname || '.' || '"' || tablename ||=20 '"')::regclass)=20 from pg_tables;=20 You need to schema qualify the tables. Additionally, if you happen to=20 have table names that have a mix of capital and non capital letters or=20 contain other characters that might be problematic, you need to enclose=20 the table name in double quotes.=20 Regards=20 Charles=20 --=20 Charles Clavadetscher=20 Swiss PostgreSQL Users Group=20 Treasurer=20 Spitzackerstrasse 9=20 CH - 8057 Z=C3=BCrich=20 http://www.swisspug.org=20 +---------------------------+=20 | ____ ______ ___ |=20 | / )/ \/ \ |=20 | ( / __ _\ ) |=20 | \ (/ o) ( o) ) |=20 | \_ (_ ) \ ) _/ |=20 | \ /\_/ \)/ |=20 | \/ |=20 | _| | |=20 | \|_/ |=20 | |=20 | Swiss PostgreSQL |=20 | Users Group |=20 | |=20 +---------------------------+=20 Thanks, this worked.=20 I wonder though, why calling pg_relation_size('users') work (I don't need t= o specify the schema).=20 --=_f7b6ca01-1024-4380-aa2e-1e702777731a Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
De: "Charles Clavadetscher" <clavadetscher@swisspug.org&g= t;
Para: "luis.roberto" <luis.roberto@siscobra.com.br>
<= b>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 siz= es, however I'm getting a
> strange error:
>
> select ta= blename,pg_relation_size(tablename::text)
>   from pg_tables;>
> In PG 13:
>
> SQL Error [42P01]: ERROR: relatio= n "sql_implementation_info" does not
> exist
>
> In PG 1= 2:
>
> SQL Error [42P01]: ERROR: relation "sql_parts" does not= exist

Try like this:

select schemaname,
   &nbs= p;    tablename,
        pg_relation_= size((schemaname || '.' || '"' || tablename ||
'"')::regclass)
from = pg_tables;

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

Regards
Charle= s

--
Charles Clavadetscher
Swiss PostgreSQL Users Group
Tr= easurer
Spitzackerstrasse 9
CH - 8057 Z=C3=BCrich

http://www.s= wisspug.org

+---------------------------+
|     ____ &n= bsp;______  ___     |
|    /    )/ &n= bsp;    \/   \    |
|   (     / = __    _\    )   |
|    \    = ;(/ o)  ( o)   )   |
|     \_  (_  ) =   \ ) _/    |
|       \  /\_/   =  \)/      |
|        \/ <//| =  |\\>      |
|          =   _|  |         |
|       =       \|_/          |
|   &= nbsp;                    =   |
|     Swiss PostgreSQL      |
| &n= bsp;     Users Group         |
|   &n= bsp;                     =   |
+---------------------------+


Than= ks, this worked.

I wonder tho= ugh, why calling pg_relation_size('users') work (I don't need to specify th= e schema).
--=_f7b6ca01-1024-4380-aa2e-1e702777731a--