Uninstall the Microsoft Visual C++ 2015-2022 redistributable and the PostgreSQL with installation failed and try install again.
Has worked for me to upgrade PostgreSQL 17 to 18.