v.21.10New Features

Add getServerPort function to retrieve server port with exception handling

Add getServerPort function to allow getting server port. When the port is not used by the server, throw an exception. #27900 (Amos Bird).
Introduces the getServerPort function to retrieve the port number on which the ClickHouse server is running.

Why it matters

This feature allows users to programmatically determine the server's listening port, which is useful for diagnostics, configuration validation, and dynamic connection management. If the server is not using a port, the function throws an exception, ensuring clear feedback on the server state.

How to use it

Users can call the getServerPort() function in their SQL queries or server-side code. If the server has no assigned port, the function will raise an exception to indicate the absence of a port.