pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: R3gardless (@R3gardless) <noreply+R3gardless@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #969: Tuning `maintencne_work_mem` to improve  HNSW index build time
Date: Mon, 16 Mar 2026 02:41:29 +0000
Message-ID: <gh-pgvector-pgvector-969-c4064695148@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-969@github.com>
References: <gh-pgvector-pgvector-969@github.com>

Hi @ankane thank you for response!

I attached logs from tests with varying `maintenance_work_mem` values (1GB, 10GB and 20GB.)

**`maintenance_work_mem` 1GB**
```
2026-03-13 10:27:16 KST [00000] [3475327 (12)] vectordb@127.0.0.1(60648)/vectordb LOG:  statement: ALTER USER "vectordb" SET maintenance_work_mem TO '1GB';
2026-03-13 10:27:16 KST [00000] [3475327 (13)] vectordb@127.0.0.1(60648)/vectordb LOG:  statement: ALTER USER "vectordb" SET max_parallel_maintenance_workers TO '16';
2026-03-13 10:27:16 KST [00000] [3475327 (14)] vectordb@127.0.0.1(60648)/vectordb LOG:  statement: ALTER USER "vectordb" SET max_parallel_workers TO '16';
2026-03-13 10:27:16 KST [00000] [3475327 (15)] vectordb@127.0.0.1(60648)/vectordb LOG:  statement: ALTER TABLE "vdbbench_table_test" SET (parallel_workers = 16);
2026-03-13 10:27:17 KST [00000] [3475327 (16)] vectordb@127.0.0.1(60648)/vectordb DEBUG:  sending cancel to blocking autovacuum PID 3469924
2026-03-13 10:27:17 KST [00000] [3475327 (17)] vectordb@127.0.0.1(60648)/vectordb DETAIL:  Process 3475327 waits for ShareUpdateExclusiveLock on relation 25373 of database 16385.
2026-03-13 10:27:17 KST [57014] [3469924 (3)] @/ ERROR:  canceling autovacuum task
2026-03-13 10:27:17 KST [57014] [3469924 (4)] @/ CONTEXT:  while scanning block 1207948 of relation "public.vdbbench_table_test"
  automatic vacuum of table "vectordb.public.vdbbench_table_test"
2026-03-13 10:27:17 KST [00000] [3475327 (18)] vectordb@127.0.0.1(60648)/vectordb LOG:  duration: 1001.047 ms
2026-03-13 10:27:17 KST [00000] [3475327 (19)] vectordb@127.0.0.1(60648)/vectordb LOG:  statement: 
                  CREATE INDEX IF NOT EXISTS  "pgvector_index"  ON public. "vdbbench_table_test" 
                  USING  "hnsw"  (embedding  "vector_cosine_ops" )
                   WITH ( "m" = "16", "ef_construction" = "64" );
2026-03-13 10:27:17 KST [00000] [3475327 (20)] vectordb@127.0.0.1(60648)/vectordb DEBUG:  building index "pgvector_index" on table "vdbbench_table_test" serially
2026-03-13 10:28:23 KST [00000] [3475333 (1)] @/ NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 284896 tuples
2026-03-13 10:28:23 KST [00000] [3475333 (2)] @/ DETAIL:  Building will take significantly more time.
2026-03-13 10:28:23 KST [00000] [3475333 (3)] @/ HINT:  Increase maintenance_work_mem to speed up builds.
2026-03-13 10:28:25 KST [00000] [3475327 (22)] vectordb@127.0.0.1(60648)/vectordb NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 284896 tuples
2026-03-13 10:28:25 KST [00000] [3475327 (23)] vectordb@127.0.0.1(60648)/vectordb DETAIL:  Building will take significantly more time.
2026-03-13 10:28:25 KST [00000] [3475327 (24)] vectordb@127.0.0.1(60648)/vectordb HINT:  Increase maintenance_work_mem to speed up builds.
2026-03-13 12:19:24 KST [00000] [3475327 (1045)] vectordb@127.0.0.1(60648)/vectordb LOG:  duration: 6726699.766 ms
```

**`maintenance_work_mem` 10GB**
```
2026-03-13 17:18:39 KST [00000] [3594164 (12)] vectordb@127.0.0.1(35526)/vectordb LOG:  statement: ALTER USER "vectordb" SET maintenance_work_mem TO '10GB';
2026-03-13 17:18:39 KST [00000] [3594164 (13)] vectordb@127.0.0.1(35526)/vectordb LOG:  statement: ALTER USER "vectordb" SET max_parallel_maintenance_workers TO '16';
2026-03-13 17:18:39 KST [00000] [3594164 (14)] vectordb@127.0.0.1(35526)/vectordb LOG:  statement: ALTER USER "vectordb" SET max_parallel_workers TO '16';
2026-03-13 17:18:39 KST [00000] [3594164 (15)] vectordb@127.0.0.1(35526)/vectordb LOG:  statement: ALTER TABLE "vdbbench_table_test" SET (parallel_workers = 16);
2026-03-13 17:18:40 KST [00000] [3594164 (16)] vectordb@127.0.0.1(35526)/vectordb DEBUG:  sending cancel to blocking autovacuum PID 3589517
2026-03-13 17:18:40 KST [00000] [3594164 (17)] vectordb@127.0.0.1(35526)/vectordb DETAIL:  Process 3594164 waits for ShareUpdateExclusiveLock on relation 25397 of database 16385.
2026-03-13 17:18:40 KST [57014] [3589517 (3)] @/ ERROR:  canceling autovacuum task
2026-03-13 17:18:40 KST [57014] [3589517 (4)] @/ CONTEXT:  while scanning block 1089328 of relation "public.vdbbench_table_test"
  automatic vacuum of table "vectordb.public.vdbbench_table_test"
2026-03-13 17:18:40 KST [00000] [3594164 (18)] vectordb@127.0.0.1(35526)/vectordb LOG:  duration: 1000.895 ms
2026-03-13 17:18:40 KST [00000] [3594164 (19)] vectordb@127.0.0.1(35526)/vectordb LOG:  statement: 
                  CREATE INDEX IF NOT EXISTS  "pgvector_index"  ON public. "vdbbench_table_test" 
                  USING  "hnsw"  (embedding  "vector_cosine_ops" )
                   WITH ( "m" = "16", "ef_construction" = "64" );
2026-03-13 17:18:40 KST [00000] [3594164 (20)] vectordb@127.0.0.1(35526)/vectordb DEBUG:  building index "pgvector_index" on table "vdbbench_table_test" seriall
2026-03-13 17:32:55 KST [00000] [3594174 (1)] @/ NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 2859018 tuples
2026-03-13 17:32:55 KST [00000] [3594174 (2)] @/ DETAIL:  Building will take significantly more time.
2026-03-13 17:32:55 KST [00000] [3594174 (3)] @/ HINT:  Increase maintenance_work_mem to speed up builds.
2026-03-13 19:11:01 KST [00000] [3594164 (1129)] vectordb@127.0.0.1(35526)/vectordb LOG:  duration: 6741619.730 ms
```

**`maintenance_work_mem` 30GB**
```
026-03-14 00:07:08 KST [00000] [3712285 (12)] vectordb@127.0.0.1(56168)/vectordb LOG:  statement: ALTER USER "vectordb" SET maintenance_work_mem TO '20GB';
2026-03-14 00:07:08 KST [00000] [3712285 (13)] vectordb@127.0.0.1(56168)/vectordb LOG:  statement: ALTER USER "vectordb" SET max_parallel_maintenance_workers TO '16';
2026-03-14 00:07:08 KST [00000] [3712285 (14)] vectordb@127.0.0.1(56168)/vectordb LOG:  statement: ALTER USER "vectordb" SET max_parallel_workers TO '16';
2026-03-14 00:07:08 KST [00000] [3712285 (15)] vectordb@127.0.0.1(56168)/vectordb LOG:  statement: ALTER TABLE "vdbbench_table_test" SET (parallel_workers = 16);
2026-03-14 00:07:09 KST [00000] [3712285 (16)] vectordb@127.0.0.1(56168)/vectordb DEBUG:  sending cancel to blocking autovacuum PID 3707543
2026-03-14 00:07:09 KST [00000] [3712285 (17)] vectordb@127.0.0.1(56168)/vectordb DETAIL:  Process 3712285 waits for ShareUpdateExclusiveLock on relation 25421 of database 16385.
2026-03-14 00:07:09 KST [57014] [3707543 (3)] @/ ERROR:  canceling autovacuum task
2026-03-14 00:07:09 KST [57014] [3707543 (4)] @/ CONTEXT:  while scanning block 1238902 of relation "public.vdbbench_table_test"
  automatic vacuum of table "vectordb.public.vdbbench_table_test"
2026-03-14 00:07:09 KST [00000] [3712285 (18)] vectordb@127.0.0.1(56168)/vectordb LOG:  duration: 1000.780 ms
2026-03-14 00:07:09 KST [00000] [3712285 (19)] vectordb@127.0.0.1(56168)/vectordb LOG:  statement: 
                  CREATE INDEX IF NOT EXISTS  "pgvector_index"  ON public. "vdbbench_table_test" 
                  USING  "hnsw"  (embedding  "vector_cosine_ops" )
                   WITH ( "m" = "16", "ef_construction" = "64" );
2026-03-14 00:07:09 KST [00000] [3712285 (20)] vectordb@127.0.0.1(56168)/vectordb DEBUG:  building index "pgvector_index" on table "vdbbench_table_test" serially
2026-03-14 00:41:58 KST [00000] [3712285 (22)] vectordb@127.0.0.1(56168)/vectordb NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 5719284 tuples
2026-03-14 00:41:58 KST [00000] [3712285 (23)] vectordb@127.0.0.1(56168)/vectordb DETAIL:  Building will take significantly more time.
2026-03-14 00:41:58 KST [00000] [3712285 (24)] vectordb@127.0.0.1(56168)/vectordb HINT:  Increase maintenance_work_mem to speed up builds.
2026-03-14 02:24:50 KST [00000] [3712285 (1261)] vectordb@127.0.0.1(56168)/vectordb LOG:  duration: 8260413.418 ms
```

In the logs, the following message appears:
```
hnsw graph no longer fits into maintenance_work_mem after <# of tuples> tuples
```

The number of tuples increases as `maintenance_work_mem` increases. However, the overall index build duration did not improve significantly.

Also, there were no other active sessions running while the index was being built.

So it seems that increasing `maintenance_work_mem` allows more tuples to fit into memory during the HNSW graph construction phase, but it does not significantly reduce the total build time in this case.

Thanks a lot!

view thread (8+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-969-c4064695148@github.com>
Permalink:  ../gh-pgvector-pgvector-969-c4064695148@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox