static void checkSchemaName () {
    Configuration conf = injector.getInstance(Configuration.class);
    if(conf.getDatabaseType() == Configuration.DatabaseType.POSTGRES) {
      LOG.info("Ensuring that the schema set for Postgres is correct");

      ensureConnection();

      try (ResultSet schemaRs = connection.getMetaData().getSchemas();
           ResultSet searchPathRs = connection.createStatement().executeQuery("show search_path");
           ResultSet ambariTablesRs = connection.createStatement().executeQuery(
               "select table_schema from information_schema.tables where table_name = 'hostcomponentdesiredstate'")) {
        // Check if ambari's schema exists
        final boolean ambariSchemaExists = getResultSetColumn(schemaRs, "TABLE_SCHEM").contains(conf.getDatabaseSchema());
        if ( !ambariSchemaExists ) {
          warning("The schema [{}] defined for Ambari from ambari.properties has not been found in the database. " +
              "Storing Ambari tables under a different schema can lead to problems.", conf.getDatabaseSchema());
        }
        // Check if the right schema is first on the search path
        List<Object> searchPathResultColumn = getResultSetColumn(searchPathRs, "search_path");
        List<String> searchPath = searchPathResultColumn.isEmpty() ? ImmutableList.of() :
            ImmutableList.copyOf(Splitter.on(",").trimResults().split(String.valueOf(searchPathResultColumn.get(0))));
        String firstSearchPathItem = searchPath.isEmpty() ? null : searchPath.get(0);
        if (!Objects.equals(firstSearchPathItem, conf.getDatabaseSchema())) {
          warning("The schema [{}] defined for Ambari in ambari.properties is not first on the search path:" +
              " {}. This can lead to problems.", conf.getDatabaseSchema(), searchPath);
        }
        // Check schemas with Ambari tables.
        ArrayList<Object> schemasWithAmbariTables = getResultSetColumn(ambariTablesRs, "table_schema");
        if ( ambariSchemaExists && !schemasWithAmbariTables.contains(conf.getDatabaseSchema()) ) {
          warning("The schema [{}] defined for Ambari from ambari.properties does not contain the Ambari tables. " +
              "Storing Ambari tables under a different schema can lead to problems.", conf.getDatabaseSchema());
        }
        if ( schemasWithAmbariTables.size() > 1 ) {
          warning("Multiple schemas contain the Ambari tables: {}. This can lead to problems.", schemasWithAmbariTables);
        }
      }
      catch (SQLException e) {
        warning("Exception occurred during checking db schema name: ", e);
      }
    }
  }
This makes the following checks for Postgres:
<ol>
  <li>Check if the connection's schema (first item on search path) is the one set in ambari.properties</li>
  <li>Check if the connection's schema is present in the DB</li>
  <li>Check if the ambari tables exist in the schema configured in ambari.properties</li>
  <li>Check if ambari tables don't exist in other shemas</li>
</ol>
The purpose of these checks is to avoid that tables and constraints in ambari's schema get confused with tables
and constraints in other schemas on the DB user's search path. This can happen after an improperly made DB restore
operation and can cause issues during upgrade.
we may have no permissions (e.g. external DB) to auto fix this problem
ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java