I searched for many solutions, and there are numerous solutions to this problem online, including adding the executable file path to the PATH environment variable, manually creating a postgres user and adding it to the local administrators group, granting full control permissions to the postgres user for the installation directory and data directory, running the installer with postgres privileges, even logging into Windows as the postgres user and then running the installer, uninstalling the old program completely and cleaning the registry before installation, and many other methods. However, they all still resulted in the same error.
I finally solved this problem by using administrator privileges in the command line:
D:\PostgreSQL\bin>initdb.exe -D D:\databases
D:\PostgreSQL\bin>pg_ctl.exe register -N PostgreSQL -D D:\databases
The following bug has been logged on the website:
Bug reference: 18553
Logged by: Yan Chen
Email address: pinsaxy@gmail.com
PostgreSQL version: 16.3
Operating system: Windows 10
Description:
The first step for customers using PostgreSQL is installation. However, due
to potential user permission issues with PostgreSQL, the installation always
fails at the database creation step. During the installation process, a
dialog box pops up saying: Problem running post-install step, Installation
may not complete correctly. Failed to start the database server. After
installation, the data directory is empty.
I believe that a dedicated software company should not ignore installation
issues. I am extremely angry about this and have registered an account
specifically to express my dissatisfaction with you!