The OS is Ubuntu 20.04. I moved the data directory to a secondary disk. In the "Disks" utility, I clicked "Edit Mount Options", turned off "User Session Defaults", and specified a hard-coded Mount Point like
/mnt/database, because by default it was mounted at something like
/media/[user name]/disk label. "Mount at system startup" had been checked (unchanged from default).
Now, postgresql's automatic start at the system startup fails with a message like: "[data directory] is not accessible or does not exist". If I manually start it, by executing
sudo systemctl start postgresql it starts fine. I suspect that the system tried to start postgresql before the secondary disk was automatically mounted. Is that so? If that is the case, how can I make it start after the secondary disk has been mounted?
PS: I solved it. It was the order. I cannot believe why the tutorials that explained moving data directory to a secondary disk did not mention this.
Open the service file:
sudo nano /lib/systemd/system/postgresql@.service
Add the disk's name at:
After=network.target mnt-[disk name].mount
If the disk name is "database", then it is