w3resource

Assess Disk Usage for the 2023 Sales Partition


Querying Partition Size in PostgreSQL

Write a PostgreSQL query to check the disk size of a specific partition Sales_2023.

Solution:

-- Get the total size of the 'Sales_2023' partition in a human-readable format.
SELECT pg_size_pretty(pg_total_relation_size('Sales_2023'));

Explanation:

  • Purpose of the Query:
    • o Retrieves the disk space occupied by a partition.
  • Key Components:
    • pg_total_relation_size(): Fetches the table size.
  • Real-World Application:
    • Helps in storage management for large partitioned tables.

Notes:

  • Use pg_size_pretty() for human-readable output.

For more Practice: Solve these Related Problems:

  • Write a PostgreSQL query to retrieve the disk sizes of all partitions of a table in a single consolidated output.
  • Write a PostgreSQL query to check the size of a specific partition and compare it against a predefined threshold value.
  • Write a PostgreSQL query to list all partitions of a table sorted by their disk usage in descending order.
  • Write a PostgreSQL query to fetch the disk size of a partition and convert the output into megabytes (MB) for easier interpretation.


Go to:


PREV : Query Partition Metadata.

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.