2. Tried to initialize the PostgreSQL database: ```bash sudo su - postgres initdb --locale=C.UTF-8 --encoding=UTF8 -D '/var/lib/postgres/data' ```
It does seem a bit odd that the packager wouldn't initialize an initial cluster; most of them do. The need to initdb here is surprising. But, if you do manually run initdb then either the directory you specify for PGDATA must exist OR the parent directory (here, /var/lib/postgres) must exist and the user you are running initdb as must be permitted to create directories in that location. It is unclear what the case here may be but at the end of the day the OS administrator is responsible for ensuring an appropriate environment exists for initdb to successfully initialize a cluster in the PGDATA (-D) directory. That likely will require sudo and running mkdir and chown commands. Then the postgres user can run initdb using the newly created directory owned by them for PGDATA.
If this issue is specific to EndeavourOS or PostgreSQL on Arch-based systems, it would be helpful to identify and address the root cause to improve the experience for future users.
I suppose they may be looking here but the core project doesn't accept responsibility for the products the various and sundry packagers that exist produce.
In any case I cannot read what you've provided and conclude there is a bug rather than a mis-application of necessary administrative tasks. I also do not have access to the necessary environment in which to experiment. Others here may, though again reporting this to the provider of the pacman package directly is more likely to find someone able to experiment and, if there really is a bug, fix things.
For certain, visudo is not the only way to make it so the postgres OS user can run initdb. But if you want to put things in places only root can write to then involving root will be necessary to establish areas within its domain that postgres can administer, thus precluding the need to empower postgres to operate within the root-restricted areas.