我正在使用这个宝石: https://github.com/rails/activerecord-session_store
当我运行Rails应用程序的多个实例时,出现此错误:
PG :: UniqueViolation:错误:重复的键值违反了唯一约束“ sessions_pkey” 详细信息:密钥(id)=(3005307)已存在。 :INSERT INTO“ sessions”(“ session_id”,“ data”,“ created_at”,“ updated_at”)值($ 1,$ 2,$ 3,$ 4)返回“ id”
id列由一个序列生成:
CREATE TABLE public.sessions
(
id integer NOT NULL DEFAULT nextval('sessions_id_seq'::regclass),
session_id character varying(255) COLLATE pg_catalog."default" NOT NULL,
data text COLLATE pg_catalog."default",
created_at timestamp without time zone,
updated_at timestamp without time zone,
CONSTRAINT sessions_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
既然是这种情况,即使插入是从多个过程中进行的,序列也不应该保证唯一性吗?