def pg_version(self) -> int:
        """Current full postgres version if instance is running, major version otherwise.

        We can only use ``postgres --version`` output if major version there equals to the one
        in data directory. If it is not the case, we should use major version from the ``PG_VERSION``
        file.
        """
        if self._postgresql.state == PostgresqlState.RUNNING:
            try:
                return self._postgresql.server_version
            except AttributeError:
                pass
        bin_minor = postgres_version_to_int(get_postgres_version(bin_name=self._postgresql.pgcommand('postgres')))
        bin_major = get_major_from_minor_version(bin_minor)
        datadir_major = self._postgresql.major_version
        return datadir_major if bin_major != datadir_major else bin_minor
Current full postgres version if instance is running, major version otherwise.

        We can only use ``postgres --version`` output if major version there equals to the one
        in data directory. If it is not the case, we should use major version from the ``PG_VERSION``
        file.
        
patroni/postgresql/config.py