Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL database size is less after backup/load on Heroku

Recently I created a new Heroku app for production and populated it's database with a backup that I took from the staging database.

The problem is that the database size, as shown on Heroku's Postgres webpage for the two databases is different!

The first database, where I took the backup from was 360 MBs and the new database that was populated was only 290 MBs.

No errors showed up during the backup/load process. and taking a backup from the two databases results in the same backup file size (around 40 MBs).

The project is working fine, and the two apps look exactly the same, but I'm concerned that I might have lost some data that would cause troubles in the future.

More info: I'm using the same production database plan on both Apps.

Also, the first database is not attached to the first instance (because it was added from the Postgres management page, not from the App's resources page) and the new database is attached to the new App.

Thanks in advance

like image 746
Emam Avatar asked Nov 22 '12 04:11

Emam


People also ask

How does Heroku Postgres rollback work?

Heroku Postgres rollback “rolls back” the state of your database to a previous point. Rollback doesn't affect your primary database. It follows the same pattern as fork: rollback provisions a new database that isn't directly connected to the primary in any way.

Why is Heroku Postgres so slow?

Expensive queries are database queries that run slowly and/or spend a significant amount of their execution time reading and writing to disk. Such queries are the most common cause of performance issues on Heroku Postgres databases.

How much load can PostgreSQL handle?

There is no PostgreSQL-imposed limit on the number of indexes you can create on a table. Of course, performance may degrade if you choose to create more and more indexes on a table with more and more columns. PostgreSQL has a limit of 1GB for the size of any one field in a table.

How do I backup my Heroku database?

Capturing Logical Backups on Larger Databases Create a short-lived fork of your Heroku Postgres database. Create a script to run the pg_dump command and transfer the backup file to the destination of your choice. The following pg_dump command creates a backup file that is the same format as the Heroku PGBackups output.


1 Answers

It is ok for postgresql DB to consume more space when in use.

The reason of this is its MVCC system. Every time you UPDATE any record in a database it creates another "version" of this record instead of rewriting the previous. This "outdated" records will be deleted by VACUUM process, when there will be no need in them.

So, when you restored your db from backup, it didn't have any "dead" records and its size was less.

Details here http://www.postgresql.org/docs/current/static/mvcc.html and http://www.postgresql.org/docs/current/static/sql-vacuum.html.

P.S. You do not need to worry about it. Postgresql will handle VACUUM automatically.

like image 146
Ihor Romanchenko Avatar answered Oct 18 '22 01:10

Ihor Romanchenko