def get_postgres_version(bin_dir: Optional[str] = None, bin_name: str = 'postgres') -> str:
    """Get full PostgreSQL version.

    It is based on the output of ``postgres --version``.

    :param bin_dir: path to the PostgreSQL binaries directory. If ``None`` or an empty string, it will use the first
                    *bin_name* binary that is found by the subprocess in the ``PATH``.
    :param bin_name: name of the postgres binary to call (``postgres`` by default)

    :returns: the PostgreSQL version.

    :raises:
        :exc:`~patroni.exceptions.PatroniException`: if the postgres binary call failed due to :exc:`OSError`.

    :Example:

        * Returns `9.6.24` for PostgreSQL 9.6.24
        * Returns `15.2` for PostgreSQL 15.2
    """
    if not bin_dir:
        binary = bin_name
    else:
        binary = os.path.join(bin_dir, bin_name)
    try:
        version = subprocess.check_output([binary, '--version']).decode()
    except OSError as e:
        raise PatroniException(f'Failed to get postgres version: {e}')
    version = re.match(r'^[^\s]+ [^\s]+ ((\d+)(\.\d+)*)', version)
    if TYPE_CHECKING:  # pragma: no cover
        assert version is not None
    version = version.groups()  # e.g., ('15.2', '15', '.2')
    major_version = int(version[1])
    dot_count = version[0].count('.')
    if major_version < 10 and dot_count < 2 or major_version >= 10 and dot_count < 1:
        return '.'.join((version[0], '0'))
    return version[0]
Get full PostgreSQL version.

    It is based on the output of ``postgres --version``.

    :param bin_dir: path to the PostgreSQL binaries directory. If ``None`` or an empty string, it will use the first
                    *bin_name* binary that is found by the subprocess in the ``PATH``.
    :param bin_name: name of the postgres binary to call (``postgres`` by default)

    :returns: the PostgreSQL version.

    :raises:
        :exc:`~patroni.exceptions.PatroniException`: if the postgres binary call failed due to :exc:`OSError`.

    :Example:

        * Returns `9.6.24` for PostgreSQL 9.6.24
        * Returns `15.2` for PostgreSQL 15.2
    
patroni/utils.py