我在 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 代码,唯一改变的是:
网络服务的位置
a. AWS – 美国西部
b. Eclipse - 伦敦
Java 版本:
a. 1.8.161 伦敦
b.美国西部 1.8.252
序列详细信息是:
SELECT * FROM information_schema.sequences
where sequence_name='markush_seq';
select * from pg_sequences where sequencename='markush_seq';
任何建议表示赞赏。
最佳答案
可能是由于多个 session 访问序列和序列缓存设置。
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/