What to do when Openshift gives you "Disk quota exceeded" when using PostgreSQL
Second time I had this now. Context: www.thebountyrenderer.org is the website of TheBounty; it's a fork of YafaRay, and I am the guy managing the website. The thing is built on Ruby on Rails; custom downloads page (which I need to update for the Wings3D plugin. Soon™). It also has Ahoy, which I intended to use for the website's usage statistics.
Ahoy generates a lot of content, apparently. I don't remember the exact last time when I had exceeded my disk quota on the free (as in price) OpenShift online service, but I don't think it's been four months.
Anyway, the PostgreSQL gear has a quota of 1GB, and I exceeded it. If you know that you have a large table which you can do without, or you know how to delete a bunch of data in the database to restore your quota, this is how you do it. The first problem that arises is, when you login on your Rails/PHP/ whatever application gear, and use psql
to access the database, DELETE
statements won't work, and neither will TRUNCATE
statements. That's because of the journaled nature of PostgreSQL; it creates a new file for each write operation, and that's exactly what you cannot do.
Here's how you actually can do it:
- Stop PostgreSQL. Easily done by
rhc tidy
, as it tries to restart your gear. Stopping will succeed, but starting won't because of your disk quota. - You login on your PostgreSQL gear (not your application gear). You can do that with
ssh [user]@[hostname]
. Your hostname is in$OPENSHIFT_POSTGRESQL_DB_HOST
on your application gear, and your user is the part before your OpenShift domain. - Copy some unneeded data from your PostgreSQL gear somewhere outside OpenShift. Good candidates are in postgresql/versions (just take the whole directory) or the log files, if they are substantial enough.
- Remove the files from the gear
- Restart PostgreSQL (e.g.
rhc tidy
again will do that...) - Use
psql
on your website gear toTRUNCATE
a table orDELETE
some stuff. In my case, I truncated ahoy_events withCASCADE
. - Use
VACUUM FULL;
inpsql
so PostgreSQL actually removes the data from its files. - Move the files you copied back it their original place.
Things should be running smooth again. For now, I disabled Ahoy, as I don't really want to buy a larger database just for statistics.