# Determining the size of PostgreSQL databases and tables

> Find out how much disk space your PostgreSQL databases and tables use, with psql commands or phpPgAdmin.

Source: https://helpcenter.ruachost.com/developers/databases/determining-the-size-of-postgresql-databases-and-tables/

> **PostgreSQL is available on Managed VPS only:**
Ruachost shared hosting supports MySQL (MariaDB) databases, not PostgreSQL. To use PostgreSQL, choose a [Managed VPS](https://ruachost.com/vps).

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?

- 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`)

### Step 1: Log in via SSH

```bash
ssh username@yourserver.ruachost.com
```

###

### Step 2: Connect to PostgreSQL

```bash
psql dbname username
```

###

### Step 3: Check Database Size

```bash
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

```
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

### Step 1: Log in to cPanel

- Navigate to **Databases → phpPgAdmin**.

### 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.

> **Important Notes:**
- Replace `dbname` and `tablename` with your actual database and table names.
- Use `pg_size_pretty()` for readable output instead of raw bytes.
- Regularly check sizes to avoid exceeding hosting limits.
- Large tables may benefit from indexing, partitioning, or archiving.
