FastGPT
FastGPT copied to clipboard
init pg error error: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
最新代码(main分支,20240102) 源码启动抛出以下错误:
init pg error error: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
at eval (webpack-internal:///(api)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async initPg (webpack-internal:///(api)/../../packages/service/common/vectorStore/pg/controller.ts:23:9)
定位到是文件:FastGPT\packages\service\common\vectorStore\pg\controller.ts的问题,把创建index单独分离出来:
export async function initPg() {
try {
await connectPg();
await PgClient.query(`
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS ${PgDatasetTableName} (
id BIGSERIAL PRIMARY KEY,
vector VECTOR(1536) NOT NULL,
team_id VARCHAR(50) NOT NULL,
tmb_id VARCHAR(50) NOT NULL,
dataset_id VARCHAR(50) NOT NULL,
collection_id VARCHAR(50) NOT NULL,
data_id VARCHAR(50) NOT NULL,
createTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`);
await PgClient.query(`
CREATE INDEX CONCURRENTLY IF NOT EXISTS vector_index ON ${PgDatasetTableName}
USING hnsw (vector vector_ip_ops) WITH (m = 32, ef_construction = 64);
`);
console.log('init pg successful');
} catch (error) {
console.log('init pg error', error);
}
}
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
The latest code (main branch, 20240102) Source code startup throws the following error: i``` nit pg error error: CREATE INDEX CONCURRENTLY cannot run inside a transaction block at eval (webpack-internal:///(api)/../../node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index .js:45:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async initPg (webpack-internal:///(api)/../../packages/service/common/vectorStore/pg/controller.ts:23:9)
Locate the problem with the file: FastGPT\packages\service\common\vectorStore\pg\controller.ts, and separate the created index separately:
export async function initPg() {
try {
await connectPg();
await PgClient.query(CREATE EXTENSION IF NOT EXISTS vector; CREATE TABLE IF NOT EXISTS ${PgDatasetTableName} ( id BIGSERIAL PRIMARY KEY, vector VECTOR(1536) NOT NULL, team_id VARCHAR(50) NOT NULL, tmb_id VARCHAR(50) NOT NULL, dataset_id VARCHAR(50) NOT NULL, collection_id VARCHAR(50) NOT NULL, data_id VARCHAR(50) NOT NULL, createTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
);
await PgClient.query(`
CREATE INDEX CONCURRENTLY IF NOT EXISTS vector_index ON ${PgDatasetTableName}
USING hnsw (vector vector_ip_ops) WITH (m = 32, ef_construction = 64);
`);
console.log('init pg successful');
} catch (error) { console.log('init pg error', error); } }
New version has been fixed https://github.com/labring/FastGPT/pull/684#issue-2063291710