简体   繁体   中英

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

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 .

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

See if this helps: PostgreSQL database size increasing

Also try to measure the size of each table individually and for those tables where you see differences, compare counts of records: postgresql total database size not matching sum of individual table sizes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM