Skip to content

Conversation

@labkey-jeckels
Copy link
Contributor

@labkey-jeckels labkey-jeckels commented Nov 1, 2025

Rationale

If we know the sizes of tables we can make better choices about infrastructure and better estimate usage. Limited to Postgres.

Changes

  • Admin Console->Postgres Table Sizes report to show size of all tables and their indices
  • modules.Core.databaseSchemaSizes metric to roll up table sizes by schema

Tasks 📍

  • Manual Testing @labkey-adam
    • Seems to work and will be interesting to inspect. Consider filtering out the "system" schemas/tables from the list, unless those are critical. (Okay, maybe they're interesting from an operational perspective.) See SqlDialect.isSystemSchema().
  • Needs Automation

@labkey-jeckels labkey-jeckels requested a review from a team November 1, 2025 00:32
@labkey-jeckels labkey-jeckels self-assigned this Nov 1, 2025
@github-actions
Copy link

github-actions bot commented Nov 1, 2025

ERROR: A pull request from 25.11_fb_tableAndSchemaSizes is expected to target release25.11-SNAPSHOT, not develop


setDescription("Shows info Postgres table sizes");

addColumn(new ExprColumn(this, "table_schema", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".table_schema"), JdbcType.VARCHAR));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the default behavior of BaseColumnInfo (no need for ExprColumn and SQLFragment). See BaseColumnInfo.getValueSql(String tableAliasName)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Thanks. I updated all three special PG tables

SELECT
table_schema,
table_name,
pg_table_size('"' || table_schema || '"."' || table_name || '"') AS table_size,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, this syntax is so weird. PG is very vague about how a VARCHAR gets converted to OID. This is also slightly weirder in that you're using the information_schema where OID doesn't exist.

Something like this against the native schema let's you get the OID directly.

SELECT pg_namespace.nspname as schema_name, pg_class.relname as table_name, pg_table_size(pg_class.oid)
FROM pg_class JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
WHERE pg_class.relkind = 'r' and nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY schema_name, table_name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a SQL problem with the original. I just don't know what PG will do when converting the generated string to an OID when the table has double-quotes in the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg. Stupid quotes.

I created a horrible schema and table name. I verified that quote_ident fixes the problem and resolves to regclass/OID correctly.

Copy link
Contributor

@labkey-matthewb labkey-matthewb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Comments for you consideration.

@labkey-jeckels
Copy link
Contributor Author

@labkey-adam I added a filter to omit those PG internal schemas

@labkey-jeckels labkey-jeckels changed the base branch from develop to release25.11-SNAPSHOT November 4, 2025 01:48
@labkey-jeckels labkey-jeckels merged commit 0fb9737 into release25.11-SNAPSHOT Nov 4, 2025
6 of 9 checks passed
@labkey-jeckels labkey-jeckels deleted the 25.11_fb_tableAndSchemaSizes branch November 4, 2025 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants