Issue
I am trying to restart my postgres cluster, but its supposed to be owned by user id that doesnt exist. when I try to add that user, its supposed to be existing. What can I do from here?
root@localhost:~# pg_lsclusters
12 main 5432 down /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12 main.log
root@localhost:~# pg_ctlcluster 12 main restart
Error: The cluster is owned by user id 109 which does not exist
root@localhost:~# sudo adduser -UID 109 postgres
adduser: The GID 109 is already in use.
The user should be in group 116 which also doesn't exist.
After re-adding the appropriate user and user group has not helped me to restart the cluster, I simply dropped the cluster and added a new one. Now I have a running postgres cluser again.
root@localhost:~# pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 down postgres /var/lib/postgresql/12/main /var/log
/postgresql/postgresql-12-main.log
root@localhost:~# sudo systemctl stop postgresql@12-main
root@localhost:~# sudo pg_dropcluster --stop 12 main
root@localhost:~# sudo pg_createcluster --start 12 main
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
Solution
The group 109 already exists, but the user 109 doesn't, so the solution is to create a new group with ID 116 and a new user with ID 109 in that group:
groupadd --gid 116 postgres
useradd --gid 116 --no-user-group --uid 109 --home-dir /var/lib/postgresql postgres
Next time, don't drop a user you still need...
Answered By - Laurenz Albe Answer Checked By - Willingham (WPSolving Volunteer)