Determining the size of PostgreSQL databases and tables
PostgreSQL provides built‑in functions to check the size of databases and tables. On ruachost.com, you can use either the psql command line or the phpPgAdmin web interface to determine storage usage.
Why Check Database Size?
Section titled “Why Check Database Size?”- Monitor disk usage and prevent storage overages.
- Identify large tables that may need optimization.
- Plan for scaling and resource allocation.
Method 1: Using the Command Line (psql)
Section titled “Method 1: Using the Command Line (psql)”Step 1: Log in via SSH
Section titled “Step 1: Log in via SSH”ssh username@yourserver.ruachost.comStep 2: Connect to PostgreSQL
Section titled “Step 2: Connect to PostgreSQL”psql dbname usernameStep 3: Check Database Size
Section titled “Step 3: Check Database Size”SELECT pg_size_pretty(pg_database_size('dbname'));- Returns the total size of the database in a human‑readable format (e.g., MB, GB).
Step 4: Check Table Size
Section titled “Step 4: Check Table Size”SELECT pg_size_pretty(pg_total_relation_size('tablename'));- Returns the size of a specific table, including indexes and related data.
Method 2: Using phpPgAdmin
Section titled “Method 2: Using phpPgAdmin”Step 1: Log in to cPanel
Section titled “Step 1: Log in to cPanel”- Navigate to Databases → phpPgAdmin.
Step 2: View Database Sizes
Section titled “Step 2: View Database Sizes”- In the left pane, click PostgreSQL.
- phpPgAdmin displays the size of each database.
???? Note: phpPgAdmin shows database sizes only. To check table sizes, you must use the psql command line.