M
M
Mikhail Mashkantsev2021-06-12 17:17:48
PostgreSQL
Mikhail Mashkantsev, 2021-06-12 17:17:48

What query should be entered to determine the amount of memory used in Postgre?

select table_schema "table name", sum(data_length+index_length)/1024/1024 "Data Base Size in MB" from information_schema.TABLES GROUP BY table_schema;

ERROR: column "data_length" does not exist.
I found such an answer to my question, only in this DBMS (the query works in the workbench) the information_schema.TABLES table does not contain the necessary information. What query should be entered?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorLaze, 2021-06-12
@ Michael_29

I don't know where you found this query, but the error is correct - there is no such field in this table.
In general, the query "postgres get table size" among the first issues a link to postgresqltutorial.com , and there is such a wonderful query (the 5 largest tables in the current database):

SELECT
    relname AS "relation",
    pg_size_pretty (
        pg_total_relation_size (C .oid)
    ) AS "total_size"
FROM
    pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace)
WHERE
    nspname NOT IN (
        'pg_catalog',
        'information_schema'
    )
AND C .relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY
    pg_total_relation_size (C .oid) DESC
LIMIT 5;

Actually, there are many useful queries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question