Manual:$wgDBport

Details
Port number used by the PostgreSQL database.

If left blank, the appropriate port number is used.

This setting is not applicable to MySQL. See   if you need a non-standard port for MySQL.