Postgresql – What files are safe to delete after upgrade

postgresql

This question is very similar to Recommended procedure to remove old files after major version PostgreSQL database cluster upgrade, but I did the upgrade in a different way, so the answer might be/probably is different.

I administer a database on a headless Ubuntu system with disks very near capacity. Therefore, when I upgraded my database from Postgres 10 to Postgres 12, I used the –link option.

/usr/lib/postgresql/12/bin/pg_upgrade --old-datadir=/var/lib/postgresql/10/main \
--new-datadir=/var/lib/postgresql/12/main [stuff deleted] --link 

This worked great, and now I have Postgres 12 running nicely. Time to cleanup.

I now have 2 folders in /var/lib/postgresql, called 10 and 12. The documentation suggests that these folders (or the files within them) are joined by a hard link, but doing the following suggests otherwise:

[deleted output from du that was misleading and did not say what I thought it said]

I'd like to clean this up as best I can, both because space is at a premium, and I know that there is a danger that future me will come along and delete 10 because we're on 12.

In this situation, what do I need, and what can I delete? How can I make the folder structure as clear as possible to my future self?

Are there things elsewhere I can delete?

Best Answer

That is simple: remove the old data directory, and the garbage should be gone.

You have to do that anyway, because the old data directory cannot be used any more once you have started the new server.

This will of course not remove bloat. To get rid of that, identify affected tables and indexes and use VACUUM (FULL) or REINDEX to rebuild them.