我正在尝试在Spring Boot应用程序中与Redshift Database建立连接。我的属性文件中有以下条目。
spring.datasource.driver-class-name=com.amazon.redshift.jdbc41.Driver
spring.datasource.url=jdbc:redshift://redshift_url/db_name
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true
spring.jpa.properties.hibernate.current_session_context_class =org.springframework.orm.hibernate5.SpringSessionContext
在pom.xml中,我有以下条目。
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc41</artifactId>
<version>1.2.10.1009</version>
</dependency>
我已经创建了一个如下所示的POJO文件。
@Entity
@Table(name = "some_data_table")
public class SomeDataTable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private long id;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_at", nullable = false)
private Date createdAt;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="date",nullable = false)
private Date date;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "updated_at", nullable = false)
private Date updatedAt;
@Column(name = "data_source", nullable = false)
private String dataSource;
Getters and Setters...
}
但是每当我启动应用程序时,我都会遇到错误。
Caused by: java.sql.SQLException: [Amazon](500310) Invalid operation: relation "information_schema.sequences" does not exist;
at com.amazon.redshift.client.messages.inbound.ErrorResponse.toErrorException(Unknown Source) ~[na:na]
at com.amazon.redshift.client.PGMessagingContext.handleErrorResponse(Unknown Source) ~[na:na]
at com.amazon.redshift.client.PGMessagingContext.handleMessage(Unknown Source) ~[na:na]
at com.amazon.jdbc.communications.InboundMessagesPipeline.getNextMessageOfClass(Unknown Source) ~[na:na]
at com.amazon.redshift.client.PGMessagingContext.doMoveToNextClass(Unknown Source) ~[na:na]
请指导我解决此错误。
如错误所指出,在Redshift中不存在表information_schema.sequences。尽管Redshift基于PostgreSQL,但是它有很多差异(https://docs.aws.amazon.com/redshift/latest/dg/c_redshift-and-postgres-sql.html)
但是,Redshift专门设计为分析数据库,针对在大量数据上运行SELECT语句进行了优化,它不像很多写入/更新操作,因此不适合Spring Boot应用程序。我建议您为应用选择其他数据库类型,如果您使用AWS,则可以用于例如RDS