SchemaCrawler从PostgreSQL数据库获取序列

时间:2017-05-01 04:40:16

标签: schemacrawler

我正在使用Schema 14.16.01并使用java api在PostgreSQL 9.6数据库上运行它。我似乎无法从api获取我的PostgreSQL中的序列数据。我从上一个问题中看到,您需要将信息级别设置为最大值,但这似乎没有帮助。我能够获得数据库的所有其他信息,但序列。

    SchemaCrawlerOptions options = new SchemaCrawlerOptions();
    options.setSchemaInfoLevel(SchemaInfoLevelBuilder.maximum());
    options.setColumnInclusionRule(new IncludeAll());
    options.setTableInclusionRule(new IncludeAll());
    options.setSchemaInclusionRule(new IncludeAll());
    options.setRoutineInclusionRule(new ExcludeAll());
    options.setSequenceInclusionRule(new IncludeAll());

    Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/database", "postgres", "postgres" );
    SchemaCrawler crawler = new SchemaCrawler(con, new DatabaseSpecificOverrideOptions());

这是我测试的控制台输出。

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option 
MaxPermSize=1g; support was removed in 8.0
Connected to the target VM, address: '127.0.0.1:64896', transport: 'socket'
Apr 28, 2017 5:25:42 PM schemacrawler.crawl.SchemaCrawler crawlSchemas
INFO: Crawling schemas
Apr 28, 2017 5:25:42 PM schemacrawler.crawl.SchemaRetriever retrieveAllSchemas
INFO: Retrieving all schemas
Apr 28, 2017 5:25:42 PM schemacrawler.crawl.SchemaRetriever retrieveAllCatalogs
INFO: Retrieving all catalogs
Apr 28, 2017 5:25:42 PM schemacrawler.crawl.MetadataResultSet close
INFO: Processed 3 rows for <retrieveAllSchemas>
Apr 28, 2017 5:25:42 PM schemacrawler.crawl.SchemaRetriever retrieveSchemas
INFO: Retrieved 3 schemas
Apr 28, 2017 5:25:42 PM schemacrawler.crawl.SchemaCrawler crawlSchemas
INFO: Total time taken for <crawlSchemas> - 00:00:00.028 hours
- 92.9% - 00:00:00.026 - <retrieveSchemas>
-  7.1% - 00:00:00.002 - <sortAndFilterSchemas>

Apr 28, 2017 5:25:42 PM schemacrawler.crawl.SchemaCrawler crawlDatabaseInfo
INFO: Retrieving database information
Apr 28, 2017 5:25:43 PM schemacrawler.crawl.SchemaCrawler crawlDatabaseInfo
INFO: Retrieving JDBC driver information
Apr 28, 2017 5:25:43 PM schemacrawler.crawl.SchemaCrawler crawlDatabaseInfo
INFO: Retrieving SchemaCrawler crawl information
Apr 28, 2017 5:25:43 PM schemacrawler.crawl.SchemaCrawler crawlDatabaseInfo
INFO: Total time taken for <crawlDatabaseInfo> - 00:00:00.678 hours
-  0.0% - 00:00:00.000 - <retrieveDatabaseInfo>
- 81.4% - 00:00:00.552 - <retrieveAdditionalDatabaseInfo>
-  0.0% - 00:00:00.000 - <retrieveJdbcDriverInfo>
-  1.2% - 00:00:00.008 - <retrieveAdditionalJdbcDriverInfo>
- 17.4% - 00:00:00.118 - <retrieveCrawlHeaderInfo>

Apr 28, 2017 5:25:43 PM schemacrawler.crawl.SchemaCrawler crawlColumnDataTypes
INFO: Crawling column data types
Apr 28, 2017 5:25:43 PM schemacrawler.crawl.SchemaCrawler$1 call
INFO: Retrieving system column data types
Apr 28, 2017 5:25:43 PM schemacrawler.crawl.SchemaCrawler$2 call
INFO: Retrieving user column data types
Apr 28, 2017 5:25:43 PM schemacrawler.crawl.DatabaseInfoRetriever retrieveUserDefinedColumnDataTypes
INFO: Retrieving data types for schema <information_schema>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.DatabaseInfoRetriever retrieveUserDefinedColumnDataTypes
INFO: Retrieving data types for schema <pg_catalog>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.DatabaseInfoRetriever retrieveUserDefinedColumnDataTypes
INFO: Retrieving data types for schema <public>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.SchemaCrawler crawlColumnDataTypes
INFO: Total time taken for <crawlColumnDataTypes> - 00:00:01.039 hours
- 34.7% - 00:00:00.361 - <retrieveSystemColumnDataTypes>
- 65.3% - 00:00:00.678 - <retrieveUserDefinedColumnDataTypes>

Apr 28, 2017 5:25:44 PM schemacrawler.crawl.SchemaCrawler crawlTables
INFO: Crawling tables
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.TableRetriever retrieveTables
INFO: Retrieving tables
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.TableRetriever retrieveTablesFromMetadata
INFO: Retrieving tables for schema <information_schema>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.MetadataResultSet close
INFO: Processed 0 rows for <retrieveTables>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.TableRetriever retrieveTablesFromMetadata
INFO: Retrieving tables for schema <pg_catalog>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.MetadataResultSet close
INFO: Processed 0 rows for <retrieveTables>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.TableRetriever retrieveTablesFromMetadata
INFO: Retrieving tables for schema <public>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.MetadataResultSet close
INFO: Processed 202 rows for <retrieveTables>
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.SchemaCrawler crawlTables
INFO: Retrieved 202 tables
Apr 28, 2017 5:25:44 PM schemacrawler.crawl.TableColumnRetriever retrieveColumns
INFO: Retrieving table columns
Apr 28, 2017 5:25:46 PM schemacrawler.crawl.TableColumnRetriever retrieveHiddenColumns
INFO: No hidden table columns SQL provided
Apr 28, 2017 5:25:46 PM schemacrawler.crawl.ForeignKeyRetriever retrieveForeignKeys
INFO: Retrieving foreign keys
Apr 28, 2017 5:25:57 PM schemacrawler.crawl.SchemaCrawler$22 call
INFO: Retrieving primary keys and indexes
Apr 28, 2017 5:25:57 PM schemacrawler.crawl.IndexRetriever retrieveIndexes
INFO: Retrieving indexes
Apr 28, 2017 5:26:02 PM schemacrawler.crawl.IndexRetriever retrievePrimaryKeys
INFO: Retrieving primary keys
Apr 28, 2017 5:26:03 PM schemacrawler.crawl.TableExtRetriever retrieveTriggerInformation
INFO: Not retrieving trigger definitions, since this was not requested
Apr 28, 2017 5:26:03 PM schemacrawler.crawl.TableExtRetriever retrieveViewInformation
INFO: Not retrieving additional view information, since this was not requested
Apr 28, 2017 5:26:03 PM schemacrawler.crawl.TableExtRetriever retrieveTableDefinitions
INFO: Not retrieving table definitions, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.TableExtRetriever retrieveIndexInformation
INFO: Not retrieving additional index information, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.TableExtRetriever retrieveIndexColumnInformation
INFO: Not retrieving additional index column information, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.TableExtRetriever retrieveAdditionalTableAttributes
INFO: Not retrieving additional table attributes, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.TableExtRetriever retrieveAdditionalColumnAttributes
INFO: Not retrieving additional column attributes, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SchemaCrawler crawlTables
INFO: Total time taken for <crawlTables> - 00:00:19.387 hours
-  0.2% - 00:00:00.047 - <retrieveTables>
-  9.2% - 00:00:01.789 - <retrieveColumns>
- 54.8% - 00:00:10.615 - <retrieveForeignKeys>
-  0.4% - 00:00:00.079 - <filterAndSortTables>
- 35.2% - 00:00:06.821 - <retrieveIndexes>
-  0.0% - 00:00:00.000 - <retrieveTableConstraintInformation>
-  0.0% - 00:00:00.000 - <isRetrieveTableConstraintDefinitions>
-  0.0% - 00:00:00.000 - <retrieveTriggerInformation>
-  0.0% - 00:00:00.000 - <retrieveViewInformation>
-  0.0% - 00:00:00.000 - <retrieveTableDefinitions>
-  0.0% - 00:00:00.001 - <retrieveIndexInformation>
-  0.0% - 00:00:00.001 - <retrieveAdditionalTableAttributes>
-  0.2% - 00:00:00.031 - <retrieveTablePrivileges>
-  0.0% - 00:00:00.001 - <retrieveAdditionalColumnAttributes>
-  0.0% - 00:00:00.002 - <retrieveTableColumnPrivileges>

Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SchemaCrawler crawlRoutines
INFO: Crawling routines
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.RoutineRetriever retrieveProcedures
INFO: Not retrieving procedures, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.RoutineRetriever retrieveFunctions
INFO: Not retrieving functions, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.RoutineRetriever retrieveProcedures
INFO: Not retrieving procedures, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.RoutineRetriever retrieveFunctions
INFO: Not retrieving functions, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.RoutineRetriever retrieveProcedures
INFO: Not retrieving procedures, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.RoutineRetriever retrieveFunctions
INFO: Not retrieving functions, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SchemaCrawler crawlRoutines
INFO: Retrieved 0 routines
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SchemaCrawler crawlSynonyms
INFO: Crawling synonyms
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SynonymRetriever retrieveSynonymInformation
INFO: Not retrieving synonyms, since this was not requested
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SchemaCrawler crawlSynonyms
INFO: Total time taken for <crawlSynonyms> - 00:00:00.001 hours
-  0.0% - 00:00:00.000 - <retrieveSynonymInformation>
-100.0% - 00:00:00.001 - <sortAndFilterSynonms>

Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SchemaCrawler crawlSequences
INFO: Crawling sequences
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SequenceRetriever retrieveSequenceInformation
INFO: Retrieving sequences
Apr 28, 2017 5:26:04 PM schemacrawler.crawl.SchemaCrawler crawlSequences
INFO: Total time taken for <crawlSequences> - 00:00:00.002 hours
-  0.0% - 00:00:00.000 - <retrieveSequenceInformation>
-100.0% - 00:00:00.002 - <sortAndFilterSequences>

EDITS

序列查询中的小段

    sequence_catalog | sequence_schema |              sequence_name              | increment | minimum_value |    maximum_value    | cycle_option
------------------+-----------------+-----------------------------------------+-----------+---------------+---------------------+--------------
                  | public          | analysis_license_pk_seq                 | 1         | 1             | 9223372036854775807 | NO
                  | public          | analysis_summaries_instance_pk_seq      | 1         | 1             | 9223372036854775807 | NO

1 个答案:

答案 0 :(得分:1)

您需要确保使用SchemaCrawler - PostgreSQL插件。为了以程序方式执行此操作,您需要:

  1. 在类路径中包含us.fatehi:schemacrawler-postgresql jar。
  2. 实例化SchemaCrawler Java对象时,请确保使用正确的DatabaseSpecificOverrideOptions实例,该实例将加载PostgreSQL插件。有关示例,请参阅code from SchemaCrawlerUtility
  3. Sualeh Fatehi,SchemaCrawler