Could you please send us the error taken from Event Log.
You should see an Error in Event Log with name PostgreSQL
Paste the inner error here let me have a look.
Mehmet Gunay did a complete reinstall, download and install the SP5 and restored it from the backup. This not a solution but it is a workaround to get the upgrade.
Therefore this problem comes from downgrade process, SP5 beta or SP5 backup and restore to SP4 this might work but it is not recommended and not supported.
While the update process is running, the system adds some new parameters to the existing service pack. Finally the following error "duplicate key value violates unique constraint "parameter_name_key"" indicates that this value is added in the System Phone twice and the upgrade process halts on that point. Every service pack that is released may have new parameters, new db_tables etc.. so the downgrade is not recommended and may brake the 3CX Phone system.