Skip to content

Instantly share code, notes, and snippets.

@Raidus
Last active April 11, 2020 06:48
Show Gist options
  • Save Raidus/6a457faec38281dcaed6ca7fa438367c to your computer and use it in GitHub Desktop.
Save Raidus/6a457faec38281dcaed6ca7fa438367c to your computer and use it in GitHub Desktop.

Revisions

  1. Raidus revised this gist Apr 11, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions snippet.sql
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ SELECT
    pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS TableSize
    FROM information_schema.tables
    ORDER BY
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC;

    # Find all the table and index size in the current database.
    SELECT
    @@ -19,4 +19,4 @@ FROM
    SELECT ('"' || table_schema || '"."' || table_name || '"') AS TableName
    FROM information_schema.tables
    ) AS Tables
    ORDER BY 4 DESC
    ORDER BY 4 DESC;
  2. Raidus revised this gist Sep 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion snippet.sql
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Resource: https://www.dbrnd.com/2015/05/how-to-find-size-of-database-and-table-in-postgresql/

    # Find all the table size in the current database.

    SELECT
    table_schema || '.' || table_name AS TableName,
    pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS TableSize
  3. Raidus revised this gist Sep 25, 2019. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion snippet.sql
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,14 @@

    # Find all the table and index size in the current database.
    # Find all the table size in the current database.

    SELECT
    table_schema || '.' || table_name AS TableName,
    pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS TableSize
    FROM information_schema.tables
    ORDER BY
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC

    # Find all the table and index size in the current database.
    SELECT
    TableName
    ,pg_size_pretty(pg_table_size(TableName)) AS TableSize
  4. Raidus created this gist Sep 25, 2019.
    14 changes: 14 additions & 0 deletions snippet.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@

    # Find all the table and index size in the current database.

    SELECT
    TableName
    ,pg_size_pretty(pg_table_size(TableName)) AS TableSize
    ,pg_size_pretty(pg_indexes_size(TableName)) AS IndexSize
    ,pg_size_pretty(pg_total_relation_size(TableName)) AS TotalSize
    FROM
    (
    SELECT ('"' || table_schema || '"."' || table_name || '"') AS TableName
    FROM information_schema.tables
    ) AS Tables
    ORDER BY 4 DESC