pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
8+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-08-28 16:45 "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
  0 siblings, 0 replies; 8+ messages in thread

From: YoimiyaLoveMe (@YoimiyaLoveMe) @ 2025-08-28 16:45 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

After importing the MSONG dataset, I used a .py to connect and search for and test it . There was a segment error when searching for the second vector. However, when I use this 'error' sql  SELECT directly on the terminal, it can be executed normally. The same error occurs in the Glove1m dataset, but it is occasional, which means it sometimes works properly on Glove.
### .py
```
import sys
import numpy as np

def ivecs_read(fname):
    a = np.fromfile(fname, dtype='int32')
    d = a[0]
    return a.reshape(-1, d + 1)[:, 1:].copy()

def fvecs_read(fname):
    return ivecs_read(fname).view('float32')

def load_msong():  #(992272, 420)
    basedir = './datasets/millionSong/'
    
    xb = fvecs_read(basedir + "millionSong_base.fvecs")
    xq = fvecs_read(basedir + "millionSong_query.fvecs")
    gt = ivecs_read(basedir + "millionSong_groundtruth.ivecs")
    xt = []
    print("done", file=sys.stderr)
    return xb, xq, xt, gt

xb, xq, xt, gt = load_msong() 
nq, d = xq.shape

import psycopg

conn = psycopg.connect(
    ....
)
times = []
recall = []
efSearch = []

conn.execute('BEGIN')

for search_L in 10,20,30,40,50,60,70,80,90,100,200,300,400,500: # msong
    print("search_L:", search_L)
    sql="SET hnsw.ef_search = "+str(search_L)
    conn.execute(sql)
    k = 10
    I=[]
    t0 = time.time()
    for q in xq:
        embedding="'"+str(q.tolist())+"'"
        sql="SELECT * FROM msong ORDER BY embedding <-> "+embedding+" LIMIT "+str(k)
        results = conn.execute(sql).fetchall()
        I.append([row[0]-1 for row in results])
    t1 = time.time()
    recall_at_1 = (I == gt[:, :1]).sum() / float(nq)
    efSearch.append(search_L)
    recall.append(float(format(recall_at_1, '.4f')))
    times.append(float(format((t1-t0)*1000.0/nq, '.4f')))
    if recall_at_1==1:break
```
conn.execute('COMMIT')
### log:
```
2025-08-29 00:02:12.484 CST [116568] LOG:  database system is ready to accept connections
2025-08-29 00:02:28.918 CST [116568] LOG:  server process (PID 117002) was terminated by signal 11: Segmentation fault
2025-08-29 00:02:28.918 CST [116568] DETAIL:  Failed process was running: SELECT * FROM msong ORDER BY embedding <-> '[6.203939914703369, 6.7285919189453125, 5.577672958374023, 4.068037986755371, 4.304356098175049, 3.9737548828125, ....Omitted '  
2025-08-29 00:02:28.919 CST [116568] LOG:  terminating any other active server processes
2025-08-29 00:02:28.919 CST [116568] LOG:  all server processes terminated; reinitializing
2025-08-29 00:02:28.938 CST [117003] LOG:  database system was interrupted; last known up at 2025-08-29 00:02:12 CST
2025-08-29 00:02:30.003 CST [117003] LOG:  database system was not properly shut down; automatic recovery in progress
2025-08-29 00:02:30.009 CST [117003] LOG:  redo starts at 5/9A5A920
2025-08-29 00:02:30.009 CST [117003] LOG:  invalid record length at 5/9A5A958: expected at least 24, got 0
2025-08-29 00:02:30.009 CST [117003] LOG:  redo done at 5/9A5A920 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
2025-08-29 00:02:30.020 CST [117004] LOG:  checkpoint starting: end-of-recovery immediate wait
2025-08-29 00:02:30.050 CST [117004] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.009 s, sync=0.004 s, total=0.035 s; sync files=2, longest=0.003 s, average=0.002 s; distance=0 kB, estimate=0 kB; lsn=5/9A5A958, redo lsn=5/9A5A958
2025-08-29 00:02:30.058 CST [116568] LOG:  database system is ready to accept connections
```

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-08-28 18:24 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2025-08-28 18:24 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @YoimiyaLoveMe, a few questions:

1. What versions of Postgres and pgvector are you on?
2. How were Postgres and pgvector installed?
3. What OS (including version) is Postgres running on?
4. What's the output of `\d msong` in psql?
5. What's the output of `EXPLAIN (ANALYZE, BUFFERS, SETTINGS)` for a single query?

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-08-29 11:56 ` "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: YoimiyaLoveMe (@YoimiyaLoveMe) @ 2025-08-29 11:56 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@YoimiyaLoveMe closed this.

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-08-29 11:57 ` "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: YoimiyaLoveMe (@YoimiyaLoveMe) @ 2025-08-29 11:57 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@YoimiyaLoveMe reopened this.

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-08-29 12:16 ` "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: YoimiyaLoveMe (@YoimiyaLoveMe) @ 2025-08-29 12:16 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane Thanks for reply. Here are some details:
1.PostgreSQL  16.10  and Ubuntu 22.04
2.pgvector v0.8.0  (commit 2627c5ff775ae6d7aef0c430121ccf857842d2f2)
3.install PG and pgvector-python using apt
4.\d msong:
```
                                Table "public.msong"
  Column   |    Type     | Collation | Nullable |              Default              
-----------+-------------+-----------+----------+-----------------------------------
 id        | bigint      |           | not null | nextval('msong_id_seq'::regclass)
 embedding | vector(420) |           |          | 
Indexes:
    "msong_hnsw" hnsw (embedding vector_l2_ops)
```
5.EXPLAIN (ANALYZE, BUFFERS, SETTINGS) 
As mentioned before, the 'error' sql can work normally when executed alone
```
Limit  (cost=817.91..838.10 rows=10 width=1704) (actual time=182.130..183.762 rows=10 loops=1)
   Buffers: shared hit=63 read=1040
   ->  Index Scan using msong_hnsw on msong  (cost=817.91..2004745.44 rows=992272 width=1704) (actual time=182.128..183.758 rows=10 loops=1)
         Order By: (embedding <-> '[6.20394,6.728592,5.577673,4.068038,4.304356,3.973755,4.196032,2.736797,2.730896,4.767528,2.230103,3.867867,2.512264,2.447017,2.31352,2
.026915,2.926622,2.348673,2.977229,2.320907,1.781369,2.040179,1.645849,1.702448,1.449433,1.415773,1.71897,1.473923,2.032973,1.359246,1.322377,1.145561,1.059009,1.442192,1
.029127,1.259502,1.251,1.145984,1.386879,0.874754,1.123022,0.878245,0.978114,0.913765,0.932987,1.138823,0.963653,0.948658,1.026079,0.81089,1.057678,0.97768,1.145535,0.917
077,0.942177,0.906845,0.911343,1.236397,0.854402,0.823594,1.045359,0.237427,2.32246,0.340074,0.438981,0.387416,0.152383,0.186669,0.194207,0.760038,0.09206,1.895929,0.2196
16,0.081356,0.203526,0.056881,0.781184,0.04358,0.032141,0.84018,0.10249,0.01763,0.02522,0.035208,0.128955,0.116722,0.008777,0.159885,0.147573,0.049274,0.014206,0.070772,0
.023917,0.104931,0.020959,0.032364,0.019057,0.043597,0.089588,0.004999,0.108063,0.003234,0.073048,0.062241,0.0121,0.102636,0.00785,0.010643,0.016959,0.045054,0.021151,0.0
52394,0.117092,0.029677,0.044741,0.078848,0.047629,0.167342,0.12427,0.076074,-0.65362,-0.698325,0.686462,-0.151185,0.580714,-0.70314,0.682425,0.084039,-0.083071,-0.291498
,0.702386,-0.585897,-0.147553,-0.694304,0.66352,0.670796,0.70635,-0.674848,-0.659542,-0.422668,-0.694864,-0.544436,0.060761,-0.157422,0.031307,0.503244,0.561054,0.129336,
-0.298965,0.64614,0.53556,0.70134,0.435962,-0.706834,-0.696598,0.6735,0.704893,-0.168509,0.141065,0.692092,-0.233427,0.67615,0.376125,0.665827,0.207752,0.70383,-0.371323,
-0.698237,0.557523,0.541606,-0.57915,0.678213,0.602972,0.596514,0.450181,0.705457,0.694387,0.613078,0.486636,0.522205,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,
1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.
5,1.5,1.5,1.5,1.5,6.656191,6.983913,4.8236,4.116361,4.062823,4.310907,4.00597,2.716991,2.750864,4.909634,2.066747,4.376338,2.550151,2.593254,2.107809,1.915549,2.430024,2.
44752,3.057966,2.545228,1.945972,2.084449,1.640591,1.718647,1.443311,1.312843,1.686434,1.445631,2.097292,1.263182,1.283491,1.003438,1.019786,1.626205,1.104247,1.174719,1.
174968,1.165301,1.363758,0.838892,1.1655,0.851192,0.920107,0.799163,0.920382,0.964235,0.982401,1.002689,0.981243,0.740608,1.11049,0.867983,1.013619,0.851744,0.886483,0.75
1163,0.799404,1.074546,0.75251,0.736512,5.033378,6.166725,4.577759,3.462221,3.796452,3.255486,3.937098,2.314989,2.280562,3.833404,2.043366,2.309016,2.025839,2.118327,2.00
1903,1.864472,2.402763,2.10885,2.771778,1.312956,1.412416,1.890922,1.489735,1.507236,1.09343,1.137427,1.645888,1.088964,1.620722,1.20148,1.227486,0.980778,0.927746,1.0681
65,0.862237,1.13766,1.167684,0.928198,1.099798,0.829169,0.775118,0.83995,0.741553,0.742176,0.829832,0.943671,0.867179,0.829698,0.924192,0.642687,0.893218,0.824276,0.88894
1,0.78703,0.764075,0.738372,0.771785,0.933013,0.56405,0.601829,6.922251,7.035139,7.331659,4.625532,5.053794,4.354872,4.645027,3.178411,3.161262,5.559547,2.580195,4.918247
,2.960803,2.629469,2.830849,2.300725,3.947078,2.489648,3.101943,3.104536,1.985719,2.145165,1.807221,1.88146,1.811557,1.79705,1.824588,1.887174,2.380907,1.613076,1.456153,
1.452467,1.229495,1.632206,1.120898,1.466126,1.410346,1.344453,1.697081,0.956201,1.428448,0.943593,1.272682,1.199956,1.048747,1.508563,1.04138,1.013588,1.172803,1.049375,
1.169327,1.240781,1.534047,1.112457,1.175972,1.231001,1.162839,1.701634,1.246645,1.13244]'::vector)
         Buffers: shared hit=63 read=1040
 Planning:
   Buffers: shared hit=56 read=18 dirtied=1
 Planning Time: 0.536 ms
 Execution Time: 183.820 ms
```

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-08-29 21:58 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2025-08-29 21:58 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Thanks. I'm not able to reproduce the crash after trying many variations the script below.

1. Does the script reproduce it for you?
2. Do you have any other Postgres extensions installed?
3. How was pgvector itself installed (not pgvector-python)?
4. What architecture are you on?
5. Does disabling JIT fix it?

```python
import numpy as np
from pgvector.psycopg import register_vector
import psycopg

dimensions = 420

conn = psycopg.connect(dbname='repro', autocommit=True)
conn.execute('CREATE EXTENSION IF NOT EXISTS vector')
register_vector(conn)

embeddings = np.random.normal(size=(1000000, dimensions))

conn.execute('DROP TABLE IF EXISTS items')
conn.execute(f'CREATE TABLE items (id bigserial, embedding vector({dimensions}))')

print('Loading data')
cur = conn.cursor()
with cur.copy('COPY items (embedding) FROM STDIN WITH (FORMAT BINARY)') as copy:
    copy.set_types(['vector'])

    for embedding in embeddings:
        copy.write_row([embedding])

print('Creating indexes')
conn.execute("SET maintenance_work_mem = '3GB'")
conn.execute("SET max_parallel_maintenance_workers = 7")
conn.execute('CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)')
conn.execute('ANALYZE items')

queries = np.random.normal(size=(1000, dimensions))

for ef_search in 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500:
    print('ef_search =', ef_search)
    conn.execute('SET hnsw.ef_search = %d' % ef_search)

    for query in queries:
        sql = "SELECT * FROM items ORDER BY embedding <-> %s LIMIT 10"
        conn.execute(sql, (query,)).fetchall()
```

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-09-05 18:02 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2025-09-05 18:02 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Closing due to no response / unable to reproduce.

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT
@ 2025-09-05 18:02 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2025-09-05 18:02 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2025-09-05 18:02 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-08-28 16:45 [pgvector/pgvector] issue #893: server process was terminated by signal 11: Segmentation fault WHEN SELECT "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
2025-08-28 18:24 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-08-29 11:56 ` "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
2025-08-29 11:57 ` "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
2025-08-29 12:16 ` "YoimiyaLoveMe (@YoimiyaLoveMe)" <noreply+YoimiyaLoveMe@github.com>
2025-08-29 21:58 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-09-05 18:02 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-09-05 18:02 ` "ankane (@ankane)" <noreply+ankane@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