java - postgres 序列不递增

标签 java postgresql amazon-web-services

我在 PostgreSQL 10.7 dB 上创建了一个名为 markush_seq 的 PostgreSQL 序列 我从序列中读取

select nextval('markush_seq’)` ) 

使用 Java Web 服务: 当我在 Eclipse 上运行 Web 服务(使用 java 1.8.161)或直接从 SQL 开发人员调用序列时,它工作正常并且序列每次递增 1,例如:

http://localhost:8086/wipdbws/read-markush-seq

21767823690

21767823691

21767823692

但是,当我在 AWS 上运行 Web 服务(使用 java 1.8.252)并使用以下命令读取 seq 时:

https://aws-location/wipdbws/read-markush-seq

我得到返回的序列号,例如:

21767823692

21767823702

21767823693

21767823703

21767823694

21767823704

AWS 中的序列似乎是 2 个递增序列的组合,间隔 10。 这是相同的 java 代码,唯一改变的是:

  1. 网络服务的位置

    a. AWS – 美国西部

    b. Eclipse - 伦敦

  2. Java 版本:

    a. 1.8.161 伦敦

    b.美国西部 1.8.252

序列详细信息是:

SELECT * FROM information_schema.sequences
where sequence_name='markush_seq';

seq details

select * from pg_sequences where sequencename='markush_seq';

sql output

任何建议表示赞赏。

最佳答案

可能是由于多个 session 访问序列和序列缓存设置。

Documentation说:

although multiple sessions are guaranteed to allocate distinct sequence values, the values might be generated out of sequence when all the sessions are considered. For example, with a cache setting of 10, session A might reserve values 1..10 and return nextval=1, then session B might reserve values 11..20 and return nextval=11 before session A has generated nextval=2. Thus, with a cache setting of one it is safe to assume that nextval values are generated sequentially; with a cache setting greater than one you should only assume that the nextval values are all distinct, not that they are generated purely sequentially. Also, last_value will reflect the latest value reserved by any session, whether or not it has yet been returned by nextval.

关于java - postgres 序列不递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62169404/

相关文章:

java - 无法在 Java 中访问 View 对象的公共(public)方法(Android)

sql - 希望在一份声明中更新现有记录

postgresql - 如何从 docker 容器向主机发送 tcp/ip 请求?

java - 使用S3作为数据库来存储和查询应用程序数据

amazon-web-services - 销毁通过无服务器创建的资源,而不会销毁Lambda端点

java - 使用 Google Guava 格式化字符串

Java ArrayList,如何一次列出一个?

sql - 如何优化 (TimescaleDB/PostgreSQL) 时间序列 SQL 查询

objective-c - DynamoDB - 项目未上传

java - 在 java-8 lambda 表达式中使用 if-else 语句