Skip to content

Commit

Permalink
0003852: Startup on Postgres no relation for gp_id
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jan 9, 2019
1 parent ac0cbeb commit 538d3ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Expand Up @@ -295,21 +295,15 @@ public static String[] determineDatabaseNameVersionSubprotocol(DataSource dataSo
private static boolean isGreenplumDatabase(Connection connection) {
Statement stmt = null;
ResultSet rs = null;
String productName = null;
boolean isGreenplum = false;
int greenplumCount = 0;
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(GreenplumPlatform.SQL_GET_GREENPLUM_NAME);
while (rs.next()) {
productName = rs.getString(1);
}
if (productName != null && productName.equalsIgnoreCase("Greenplum")) {
isGreenplum = true;
rs = stmt.executeQuery(GreenplumPlatform.SQL_GET_GREENPLUM_COUNT);
if (rs.next()) {
greenplumCount = rs.getInt(1);
}
} catch (SQLException ex) {
// ignore the exception, if it is caught, then this is most likely
// not
// a greenplum database
throw new RuntimeException(ex);
} finally {
try {
if (rs != null) {
Expand All @@ -321,7 +315,7 @@ private static boolean isGreenplumDatabase(Connection connection) {
} catch (SQLException ex) {
}
}
return isGreenplum;
return greenplumCount > 0;
}

private static boolean isRedshiftDatabase(Connection connection) {
Expand Down
Expand Up @@ -31,7 +31,7 @@
public class GreenplumPlatform extends PostgreSqlDatabasePlatform {

/* PostgreSql can be either PostgreSql or Greenplum. Metadata queries to determine which one */
public static final String SQL_GET_GREENPLUM_NAME = "select gpname from gp_id";
public static final String SQL_GET_GREENPLUM_COUNT = "select count(*) from information_schema.tables where table_name = 'gp_id'";
public static final String SQL_GET_GREENPLUM_VERSION = "select productversion from gp_version_at_initdb";

public GreenplumPlatform(DataSource dataSource, SqlTemplateSettings settings) {
Expand Down

0 comments on commit 538d3ca

Please sign in to comment.