diff --git a/docs/en/docs/lakehouse/multi-catalog/jdbc.md b/docs/en/docs/lakehouse/multi-catalog/jdbc.md index 9827f3ba5f0e11..ef1b74935dc29d 100644 --- a/docs/en/docs/lakehouse/multi-catalog/jdbc.md +++ b/docs/en/docs/lakehouse/multi-catalog/jdbc.md @@ -66,6 +66,7 @@ Once connected, Doris will ingest metadata of databases and tables from the exte "driver_class" = "org.postgresql.Driver" ); ``` +> Doris obtains all schemas that PG user can access through the SQL statement: `select nspname from pg_namespace where has_schema_privilege('', nspname, 'USAGE');` and map these schemas to doris database. As for data mapping from PostgreSQL to Doris, one Database in Doris corresponds to one schema in the specified database in PostgreSQL (for example, "demo" in `jdbc_url` above), and one Table in that Database corresponds to one table in that schema. To make it more intuitive, the mapping relations are as follows: diff --git a/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md b/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md index c41b6ba1538ab8..aeb2b859b53a0c 100644 --- a/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md +++ b/docs/zh-CN/docs/lakehouse/multi-catalog/jdbc.md @@ -75,6 +75,8 @@ CREATE CATALOG jdbc_postgresql PROPERTIES ( | Database | Schema | | Table | Table | +> Doris通过sql语句`select nspname from pg_namespace where has_schema_privilege('', nspname, 'USAGE');` 来获得PG user能够访问的所有schema并将其映射为Doris的database + 3. Oracle diff --git a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java index 94f91dd942df5a..b913eff01de4fd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java +++ b/fe/fe-core/src/main/java/org/apache/doris/external/jdbc/JdbcClient.java @@ -24,6 +24,7 @@ import org.apache.doris.catalog.Type; import org.apache.doris.common.Config; import org.apache.doris.common.DdlException; +import org.apache.doris.common.util.Util; import com.alibaba.druid.pool.DruidDataSource; import com.google.common.collect.Lists; @@ -180,8 +181,8 @@ public List getDatabaseNameList() { rs = stmt.executeQuery("SHOW DATABASES"); break; case JdbcResource.POSTGRESQL: - rs = stmt.executeQuery("SELECT schema_name FROM information_schema.schemata " - + "where schema_owner='" + jdbcUser + "';"); + rs = stmt.executeQuery("SELECT nspname FROM pg_namespace WHERE has_schema_privilege(" + + "'" + jdbcUser + "', nspname, 'USAGE');"); break; case JdbcResource.ORACLE: rs = stmt.executeQuery("SELECT DISTINCT OWNER FROM all_tables"); @@ -376,7 +377,8 @@ public List getJdbcColumnsInfo(String dbName, String tableName) tableSchema.add(field); } } catch (SQLException e) { - throw new JdbcClientException("failed to get table name list from jdbc for table %s", e, tableName); + throw new JdbcClientException("failed to get table name list from jdbc for table %s:%s", e, tableName, + Util.getRootCauseMessage(e)); } finally { close(rs, conn); }