pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Table sizes
6+ messages / 4 participants
[nested] [flat]

* Table sizes
@ 2020-09-30 12:11  luis.roberto@siscobra.com.br
  0 siblings, 2 replies; 6+ messages in thread

From: luis.roberto@siscobra.com.br @ 2020-09-30 12:11 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

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 

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Table sizes
@ 2020-09-30 13:41  Ireneusz Pluta/wp.pl <ipluta@wp.pl>
  parent: luis.roberto@siscobra.com.br
  1 sibling, 0 replies; 6+ messages in thread

From: Ireneusz Pluta/wp.pl @ 2020-09-30 13:41 UTC (permalink / raw)
  To: luis.roberto@siscobra.com.br, pgsql-general <pgsql-general@lists.postgresql.org>

W dniu 2020-09-30 o 14:11, luis.roberto@siscobra.com.br pisze:
> 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
>
You need to use full tablenames, using schemaname of pg_tables too.






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Table sizes
@ 2020-09-30 13:46  Charles Clavadetscher <clavadetscher@swisspug.org>
  parent: luis.roberto@siscobra.com.br
  1 sibling, 1 reply; 6+ messages in thread

From: Charles Clavadetscher @ 2020-09-30 13:46 UTC (permalink / raw)
  To: luis.roberto@siscobra.com.br; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

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         |
|                           |
+---------------------------+





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Table sizes
@ 2020-09-30 13:54  luis.roberto@siscobra.com.br
  parent: Charles Clavadetscher <clavadetscher@swisspug.org>
  0 siblings, 2 replies; 6+ messages in thread

From: luis.roberto@siscobra.com.br @ 2020-09-30 13:54 UTC (permalink / raw)
  To: Charles Clavadetscher <clavadetscher@swisspug.org>; +Cc: pgsql-general <pgsql-general@lists.postgresql.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). 

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Table sizes
@ 2020-09-30 13:59  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: luis.roberto@siscobra.com.br
  1 sibling, 0 replies; 6+ messages in thread

From: Adrian Klaver @ 2020-09-30 13:59 UTC (permalink / raw)
  To: luis.roberto@siscobra.com.br, Charles Clavadetscher <clavadetscher@swisspug.org>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On 9/30/20 6:54 AM, luis.roberto@siscobra.com.br wrote:

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

Because it is in the search_path. In psql do:

show search_path;

It will show you the schemas Postgres will search for a table name 
without using a schema qualification.

-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Table sizes
@ 2020-09-30 14:02  Charles Clavadetscher <clavadetscher@swisspug.org>
  parent: luis.roberto@siscobra.com.br
  1 sibling, 0 replies; 6+ messages in thread

From: Charles Clavadetscher @ 2020-09-30 14:02 UTC (permalink / raw)
  To: luis.roberto@siscobra.com.br; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Hello

On 2020-09-30 15:54, luis.roberto@siscobra.com.br wrote:
>> 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).

Glad to hear that.

The other problem probably depend on your search_path.

You can look at it using (in a psql shell):

show search_path;

Tables that are in your search_path don't need to be schema qualified, 
those that aren't need it.
If you need to, you can change your search_path.

set search_path to ...;

To change it permanently you can use ALTER ROLE:

ALTER ROLE <yourrole> SET search_path=... ;

Have a look for more information at 
https://www.postgresql.org/docs/current/ddl-schemas.html (chapter 
5.9.3).

Regards
Charles





^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2020-09-30 14:02 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 12:11 Table sizes luis.roberto@siscobra.com.br
2020-09-30 13:41 ` Ireneusz Pluta/wp.pl <ipluta@wp.pl>
2020-09-30 13:46 ` Charles Clavadetscher <clavadetscher@swisspug.org>
2020-09-30 13:54   ` luis.roberto@siscobra.com.br
2020-09-30 13:59     ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-09-30 14:02     ` Charles Clavadetscher <clavadetscher@swisspug.org>

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