Horizontal scaling deployment causes PGVector violates unique key constraint
Author: cdxvy30Created Jun 15, 2025Updated Aug 14, 2025
Current Behavior
When trying to initialize data manager with following stack (PostgreSQL as scalar storage, PGVector as vector storage and Redis as eviction manager cause' I want to set GPTCache in multi-node K8s environment.)
data_manager = manager_factory(
manager="postgresql,pgvector",
eviction_manager="redis",
scalar_params={
"sql_url": cache_store_url,
},
vector_params={
"url": vector_store_url,
"collection_name": "qa_cache",
"dimension": albert.dimension,
},
eviction_params={
"url": redis_url,
"maxmemory": f"{CACHE_MAX_SIZE}mb",
"policy": CACHE_EVICTION,
}
)I encountered:
ERROR: Failed to initialize cache: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "pg_extension_name_index"
DETAIL: Key (extname)=(vector) already exists.
[SQL: CREATE EXTENSION IF NOT EXISTS vector;]
(Background on this error at: https://sqlalche.me/e/20/gkpj)Expected Behavior
Connect with Vector storage/Scalar storage and create table, index without reporting errors.
Steps To Reproduce
- In a multi-node environment (like K8s), set both Vector storage and Scalar storage with
manager_factory, and deploy the application with GPTCache on multi-node.
Source: zilliztech/GPTCache