What is Database Size, and how to calculate it?

I got an Exceeding database size limit warning in my Database size usage, which is:
- Included in free plan: 0.5GB
- Average in period: 0.58GB
- Overage in period: 0.08GB
- Included in free plan: 0.5GB
- Average in period: 0.58GB
- Overage in period: 0.08GB
However, I don't really use my database much in the past 3 month, yet the graph shows otherwise, it's increasing each day. I don't really get what is database size and how to calculate, because I only have 2 table (I have other 2 empty tables), and I check with this:
select
pg_size_pretty(pg_total_relation_size('table')) as table_size;
select
pg_size_pretty(pg_total_relation_size('table')) as table_size;
and it returns only 160 kB (this is my largest table), so I don't think this is not what database size mean.
No description
10 Replies
garyaustin
garyaustin2y ago
The database size includes all the tables in the database including Postgres tables, supabase tables, extension space, etc. Normally an new instance is in the 80MB range. Here is an instance that has about 10 of my tables. If your database is growing like that something is running to cause it to keep increasing. I can only guess some constant auth call. You may need to contact support if you don't see anything hitting the logs (like API Edge log).
No description
handjobservice
handjobserviceOP2y ago
I haven't check again, but I think I have a CRON job running to delete table content (now the table are empty already) Does it count?
garyaustin
garyaustin2y ago
Is this a table with alot of writes and deletes? Deletes don't actually release disk space in Postgres. You actually have to "vacuum" the database to return free the empty space. Also see https://github.com/reorg/pg_repack How fast are you running the cron task?
handjobservice
handjobserviceOP2y ago
I just delete rows that aged more than 3 hours. (Already unscheduled the CRON)
garyaustin
garyaustin2y ago
I'm skeptical a cron job would blow up your database that much. But you are not mentioning the rate it is running. Every time a cron task runs a table entry is generated in cron.job_run_details. Also if you are adding alot of rows and deleting them the disk space will keep building up as delete does not free disk space. If you are adding 1 row an hour and deleting it this is not your issue. If you are adding 1000 rows an hour and deleting then possibly.
handjobservice
handjobserviceOP2y ago
I've check in the cron schema, there's a job_run_details table, contains every cron job done, about 480K rows, running since June 2023. Does it count? edited: check the size, it's 517 MB. Apparently I can't delete it from the table editor, how to do that?
garyaustin
garyaustin2y ago
See pruning cron history table here https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL_pg_cron.html You have to use sql editor to delete row in protected schemas.
Scheduling maintenance with the PostgreSQL pg_cron extension - Amaz...
You can use the PostgreSQL pg_cron extension to schedule maintenance commands within a PostgreSQL database. For more information about the extension, see What is pg_cron? in the pg_cron documentation.
handjobservice
handjobserviceOP2y ago
I've empty the table with sql editor, then vacuum it. Apparently it only reduce 50 MB (quite a lot tho), but I still don't know where the other 500 MB are. How to check the database used by what data?
No description
handjobservice
handjobserviceOP2y ago
I've checked from supabase docs, my used db size is 65 MB, still doesn't match the 500 MB shown on the report
No description
garyaustin
garyaustin2y ago
I would restart the database and then reach out to support.

Did you find this page helpful?