How come the storage on the RDS portal is different that what my Postgres Database is showing in pgAdmin?

0

I have an RDS PostgreSQL instance that I would like to keep in the Free Tier. However, after a month with minimal data (6 tables with no data and one table with 5 rows and 4 columns of varchars and ints), I got a notification saying I had used 85% of the free tier storage for the month. Specifically, it was around 17GB of the 20 allotted GB. I ran the following SQL command in pgAdmin to see how much data is being stored:

SELECT pg_database.datname AS "Database", pg_size_pretty(pg_database_size(pg_database.datname)) AS "Size" FROM pg_database;

I got back that this:

Enter image description here

None of these add to the 17GB. How can I fix this issue and remove unnecessary data to stay in Free Tier usage?

2 Answers
1

The discrepancy between the storage shown in the RDS portal and the size reported by the pg_database_size function in PostgreSQL is likely due to the fact that the RDS portal includes the storage used by other database objects, such as indexes, transaction logs, and temporary files, in addition to the actual data stored in the tables.

To stay within the Free Tier usage, you can try the following steps:

  1. Run the following query to get a detailed breakdown of the database size:
SELECT
  datname,
  pg_size_pretty(pg_database_size(datname)) AS size
FROM pg_database;

SELECT
  schemaname, relname, pg_size_pretty(pg_relation_size(relid)) AS size
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_relation_size(relid) DESC;

This will show you the size of each database, schema, and table, helping you identify the largest objects.

  1. Run VACUUM and ANALYZE commands on your tables to reclaim unused space and update the database statistics:
VACUUM FULL;
ANALYZE;
  1. If you have any unnecessary data, such as old log files or temporary tables, you can remove them to free up space.

  2. By default, PostgreSQL performs automatic vacuuming, which can consume extra disk space. You can temporarily disable this feature to reduce disk usage:

ALTER DATABASE your_database_name SET autovacuum_vacuum_scale_factor = 0;
ALTER DATABASE your_database_name SET autovacuum_analyze_scale_factor = 0;
  1. PostgreSQL log files can consume significant disk space over time. Configure log file rotation to limit the number of log files and their size.
profile picture
EXPERT
answered a month ago
  • How would I know then for the future how much data will increase the storage size on AWS given the indexes and database objects? I am working with a client and I told them that they should be able to stay on free tier since there is little data at the moment. I want to give them an estimate for the future.

  • Also how can I delete log files and temporary tables

0

If you are using RDS PostgreSQL as opposed to Amazon Aurora PostgreSQL you pay for provisioned storage, not actual storage. So if you allocated 20GB to your database, you will be billed for 20GB regardless if you are using the full 20GB or not.

With RDS you get 20 GB of General Purpose SSD (gp2) storage per month for free-tier.

What is the size of the RDS storage that you have allocated to this (and all your other free-tier eligible RDS services if you have more than 1 RDS instance).

AWS
EXPERT
answered a month ago
  • I allocated 20GB of storage for the database because I wanted to make sure I did not exceed Free Tier usage. I got an email today that 17.02363324GB of the 20GB were used which is 85% of the usage limit even though there is little data in the database

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions