Why some files in data directory of a Postgresql cluster are symlink to files of another cluster?

All we need is an easy explanation of the problem, so here it is.

I did use pg_upgrade.

I had a cluster of Postgresql with version 9.6 on my machine, and then I did start another cluster with version of v12. Each of them had separate data directories, in a directory scheme like this:

├── 12
│   └── main
└── 9.6
    └── main

Then I turned off the 9.6 cluster and started using the v12 one. But now, by accident, I found out that some of the files in the base directory of the v12 cluster are not files, but symlinks to files in base directory of the 9.6 one; For example:

./postgresql/12/main/base/16401/35093 -> ./postgresql/9.6/main/base/16402/35093

Why is it so? And, more importantly, how is it so?! I mean, I thought that the files inside base directory are so internal to each DB that this could not be possible at all.

And, can I do something to disable using symlinks?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

This is the result of a pg_upgrade with the -k option, and these are not symbolic links, but hard links.

If you didn’t manage to start the old cluster after pg_upgrade everything is fine. You just forgot to remove the old cluster after upgrading. Do that right now:

rm -rf /var/lib/postgresql/9.6/main

If you use -k, the upgrade process doesn’t copy, but link the files. That makes the upgrade much faster, but renders the old cluster unusable.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply