Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init pg error error: CREATE INDEX CONCURRENTLY cannot run inside a transaction block #682

Closed
leoterry-ulrica opened this issue Jan 2, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@leoterry-ulrica
Copy link
Contributor

leoterry-ulrica commented Jan 2, 2024

最新代码(main分支,20240102)
源码启动抛出以下错误:

init pg error error: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
    at eval (webpack-internal:///(api)/../../node_modules/.pnpm/registry.npmmirror.com+pg-pool@3.6.1_pg@8.10.0/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);
  }
}
@leoterry-ulrica leoterry-ulrica added the bug Something isn't working label Jan 2, 2024
@c121914yu
Copy link
Collaborator

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/registry.npmmirror.com+pg-pool@3.6.1_pg@8.10.0/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);
}
}

      

@leoterry-ulrica
Copy link
Contributor Author

New version has been fixed #684 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants