La seguente query di selezione restituirà tutta la tabella e le sue dimensioni
SELECT
relname as mytable,
pg_size_pretty(pg_relation_size(relid)) As size
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
Crea una VISTA con questa selezione
CREATE VIEW vTableAndSize AS
SELECT
relname as mytable,
pg_size_pretty(pg_relation_size(relid)) As size
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
e ora puoi eseguire query su questa vista per ottenere le dimensioni in questo modo
SELECT mytable,size
FROM vTableAndSize WHERE mytable in ('table1','table2')
Secondo Commento di OP
CREATE VIEW vTableAndSize_1 as
SELECT
relname as mytable,
(pg_relation_size(relid)) As size
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
e ottieni la somma delle dimensioni di più colonne utilizzando
/* Get sum of specific tables */
SELECT pg_size_pretty(sum(size)) tablesizesum
FROM vTableAndSize_1 WHERE mytable in ('table1','table2')
/* Get sum of all tables */
SELECT pg_size_pretty(sum(size)) tablesizesum
FROM vTableAndSize_1
Crea vTableAndSize_1
nel tuo PostgreSQL
database e query come di seguito nel front-end (non ho familiarità con Ruby
)
ActiveRecord::Base.connection.execute("SELECT pg_size_pretty(sum(size)) FROM vTableAndSize_1
WHERE mytable in ('table1','table2')")