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 1kNcgd-00021p-Hk for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 14:02:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kNcgc-0002ud-Fn for pgsql-general@arkaria.postgresql.org; Wed, 30 Sep 2020 14:02:26 +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 1kNcgc-0002uR-7u for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 14:02:26 +0000 Received: from gandalf.net-wizard.org ([138.201.143.9]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNcgZ-0006HE-Fj for pgsql-general@lists.postgresql.org; Wed, 30 Sep 2020 14:02:25 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id 488008290A; Wed, 30 Sep 2020 16:02:22 +0200 (CEST) X-Virus-Scanned: Gentoo amavisd-new at aragorn Received: from aragorn.net-wizard.org ([127.0.0.1]) by localhost (aragorn.net-wizard.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qLxF8zj7Dgtl; Wed, 30 Sep 2020 16:02:22 +0200 (CEST) Received: from webmail.net-wizard.org (localhost [IPv6:::1]) by gandalf.net-wizard.org (Postfix) with ESMTP id EC671828F8; Wed, 30 Sep 2020 16:02:21 +0200 (CEST) MIME-Version: 1.0 Date: Wed, 30 Sep 2020 16:02:21 +0200 From: Charles Clavadetscher To: luis.roberto@siscobra.com.br Cc: pgsql-general 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> User-Agent: Roundcube Webmail/1.4.8 Message-ID: <46ba5e4effbac39b4cabec56d3250db2@swisspug.org> X-Sender: clavadetscher@swisspug.org Organization: Swiss PostgreSQL Users Group Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello On 2020-09-30 15:54, luis.roberto@siscobra.com.br wrote: >> De: "Charles Clavadetscher" >> Para: "luis.roberto" >> Cc: "pgsql-general" >> 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 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