How to find the size of a table in SQL?


How to find the size of a table in SQL?

As a SQL developer or database administrator, it is essential to have a good understanding of the size of your database tables. Knowing the size of a table can help you optimize your database performance, plan for storage requirements, and troubleshoot issues related to database performance. In this blog post, we will guide you through the process of finding the size of a table in SQL.

Here’s how you can see the size table sizes for public schema

SELECT
	table_name,
	pg_size_pretty(pg_relation_size(quote_ident(table_name))),
	pg_relation_size(quote_ident(table_name))
FROM
	information_schema.tables
WHERE
	table_schema = 'public'
ORDER BY
	3 DESC;

See sizes of tables of all schemas:

SELECT
	schema_name,
	relname,
	pg_size_pretty(table_size) AS size,
	table_size
FROM (
	SELECT
		pg_catalog.pg_namespace.nspname AS schema_name,
		relname,
		pg_relation_size(pg_catalog.pg_class.oid) AS table_size
	FROM
		pg_catalog.pg_class
		JOIN pg_catalog.pg_namespace ON relnamespace = pg_catalog.pg_namespace.oid) t
WHERE
	schema_name NOT LIKE 'pg_%'
ORDER BY
	table_size DESC;

Newsletter


Related Posts

Tools for Analyzing Your Competition

Before knowing where your business stands, you should look at the market and your competition. You need to know what marketing tactics and strategies are working for your audience, what traffic the competition has, and how they position.

Free Online Photo Editor with Cool Effects | Edit Images Easily

Transform your images with our free online photo editor with cool effects. Add filters, adjust colors, and apply creative enhancements. Edit your photos easily and make them stand out.

MongoDB Query date by _id field

Query date by _id in mongodb. Straighforward guide to solve your issue right away.

Unleashing the Power of Free API for Scrape Reverse Geocoding

Learn how to harness the potential of reverse geocoding with our beginner's guide to scraping APIs for free. Unlock the power today.

Discover the Power of Whatsapp-web.js for Safe and Easy Automation

Automate WhatsApp with ease using Whatsapp-web.js, a NodeJS client library that connects through the official WhatsApp Web app, reducing ban risks. Perfect for user or business accounts.

Website tours js tools

Tools to create live tours for your web project using js libraries.

Unlocking SaaS Marketing Success: Essential Resources to Learn and Grow

Discover a comprehensive collection of valuable resources to master the art of SaaS marketing.

Where to launch your startup

Do you wanna launch grandiosely your startup? Get a list of platforms where people can discover your project and can push your project directly to the sky.

Email campaign improving my SaaS convertion - Manager Flota

Users subscribe to your SaaS, but don't let the money on your table. Here's how I do it!

Exploring Romania's Vibrant Startup Ecosystem - Startup List

Romania, a hidden gem in Eastern Europe, has become a thriving hub for innovation and entrepreneurship.