Search code examples
clickhouse

Read clickhouse configured port numbers from inside


Are there any possibility to read clickhouse's ports? TCP port information can be read from system.clusters table, but I need to figure out http port


Solution

  • Use getServerPort function:

    SELECT getServerPort('http_port')
    
    /*
    ┌─getServerPort('http_port')─┐
    │                       8123 │
    └────────────────────────────┘
    */
    

    Take into account that this function is available starting from version 21.10.


    SELECT
        tcpPort() AS tcpPort,
        getServerPort('tcp_port'),
        getServerPort('http_port')
    
    /*
    ┌─tcpPort─┬─getServerPort('tcp_port')─┬─getServerPort('http_port')─┐
    │    9000 │                      9000 │                       8123 │
    └─────────┴───────────────────────────┴────────────────────────────┘
    */