0

I am running the below query in postgres 12.4 :

SELECT (TABLE_SCHEMA || '"."' || TABLE_NAME) as table_name, 
       pg_size_pretty(pg_table_size(table_name)) as table_size,  
       pg_size_pretty(pg_indexes_size(table_name)) AS indexes_size, 
       pg_size_pretty(pg_total_relation_size(table_name)) as total_size 
from information_schema.TABLES nowait 
where TABLE_SCHEMA='myschema' 
order by pg_total_relation_size(table_name) desc;

I am getting the below error message :

ERROR:  function pg_table_size(information_schema.sql_identifier) does not exist
LINE 1: ..."."' || TABLE_NAME) as table_name, pg_size_pretty(pg_table_s...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Can anyone tell me what exactly am I missing here? I would also like to mention that the exact same query runs fine in postgres version 9.5. I couldn't find anything in the postgres 12.4 documentation as well. Any thoughts/suggestions are welcomed. Thanks!

1
  • 1
    Well the change can be found here 12 Release Notes "Treat object-name columns in the information_schema views as being of type name, not varchar (Tom Lane)". Not sure yet how to deal with that yet. Commented Dec 22, 2020 at 23:53

1 Answer 1

3

Per this thread on the Postgres --general list:

SELECT
    pg_size_pretty(pg_table_size(quote_ident(table_name))),
    pg_size_pretty(pg_indexes_size(quote_ident(table_name))) AS indexes_size,
    pg_size_pretty(pg_total_relation_size(quote_ident(table_name))) AS total_size
FROM
    information_schema.tables
WHERE
    table_schema = 'myschema'
;

Your previous query was never working with this:

(TABLE_SCHEMA || '"."' || TABLE_NAME) as table_name

it was just using the value in the table_name column which previously was a varchar so it worked in pg_table_size(). Now that the column type has changed you need to use quote_ident() to correctly cast it. FYI, the above will work in 9.5 also.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.