pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
8+ messages / 3 participants
[nested] [flat]

* [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 13:53 "itinance (@itinance)" <noreply+itinance@github.com>
  0 siblings, 0 replies; 8+ messages in thread

From: itinance (@itinance) @ 2024-08-19 13:53 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

After running almost one year successfully in a production-database, we reached a point where we can't restore a backend any more. It happens during the statement CREATE INDEX ... USING hnsw on a partitioned table.

This happens on a Macbook Pro 1, where I usually restore backups of the same database once in a week. Data storage is still available. The docker image I am using is `ankane/pgvector`.

Logfiles don't give much information, that's all I could see. Please tell me if I can provide further information:

```
db-prod-copy-146  | 2024-08-19 13:07:50.338 UTC [64] LOG:  checkpoint starting: wal
db-prod-copy-146  | 2024-08-19 13:12:20.088 UTC [64] LOG:  checkpoint complete: wrote 4 buffers (0.0%); 0 WAL file(s) added, 0 removed, 67 recycled; write=269.684 s, sync=0.005 s, total=269.751 s; sync files=63, longest=0.001 s, average=0.001 s; distance=1097702 kB, estimate=1097740 kB
db-prod-copy-146  | 2024-08-19 13:44:01.427 UTC [1] LOG:  server process (PID 79) was terminated by signal 9: Killed
db-prod-copy-146  | 2024-08-19 13:44:01.427 UTC [1] DETAIL:  Failed process was running: CREATE INDEX embeddings_summary_embedding_idx ON vectors.embeddings_summary USING hnsw (embedding public.vector_cosine_ops);
db-prod-copy-146  | 2024-08-19 13:44:01.429 UTC [1] LOG:  terminating any other active server processes
db-prod-copy-146  | 2024-08-19 13:44:01.430 UTC [1] LOG:  all server processes terminated; reinitializing
db-prod-copy-146  | 2024-08-19 13:44:01.508 UTC [865] LOG:  database system was interrupted; last known up at 2024-08-19 13:12:20 UTC
db-prod-copy-146  | 2024-08-19 13:44:01.832 UTC [865] LOG:  database system was not properly shut down; automatic recovery in progress
db-prod-copy-146  | 2024-08-19 13:44:01.838 UTC [865] LOG:  redo starts at C/4B3FF7C8
db-prod-copy-146  | 2024-08-19 13:44:02.992 UTC [865] LOG:  invalid record length at C/641640E0: wanted 24, got 0
db-prod-copy-146  | 2024-08-19 13:44:02.992 UTC [865] LOG:  redo done at C/641640A8 system usage: CPU: user: 0.25 s, system: 0.64 s, elapsed: 1.15 s
db-prod-copy-146  | 2024-08-19 13:44:03.002 UTC [866] LOG:  checkpoint starting: end-of-recovery immediate wait
db-prod-copy-146  | 2024-08-19 13:44:04.381 UTC [866] LOG:  checkpoint complete: wrote 16384 buffers (100.0%); 0 WAL file(s) added, 25 removed, 0 recycled; write=0.127 s, sync=1.144 s, total=1.381 s; sync files=65, longest=0.710 s, average=0.018 s; distance=406930 kB, estimate=406930
```

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

* Re: [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 14:04 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: jkatz (@jkatz) @ 2024-08-19 14:04 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@itinance Are you restoring a file created with `pg_dump`?

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

* Re: [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 14:07 ` "itinance (@itinance)" <noreply+itinance@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: itinance (@itinance) @ 2024-08-19 14:07 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

> @itinance Are you restoring a file created with `pg_dump`?

yes

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

* Re: [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 16:38 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: jkatz (@jkatz) @ 2024-08-19 16:38 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@itinance Thanks. So a few things here:

1. `pg_dump` is not a backup utility (more on this in a second) - for true backup/restore you'll want to use something like [`pg_basebackup`](https://www.postgresql.org/docs/current/app-pgbasebackup.html) or a utility like [pgBackRest](https://pgbackrest.org/) (there are a variety of tools available here). Effectively these tools take a snapshot of the binary representation of your data, so you can restore it to a similar physical environment. They'll be much more efficient than `pg_dump`/`pg_restore`, which is just recreating the SQL commands used to build your environment.

2. For cases where you do need to use `pg_dump` (e.g. transferring data between non-binary compatible systems), what's likely happening is that your HNSW index build is exceeding the available memory to build the index, and as a result the OOM killer is taking out the process. If you have more resources on the machine, this is likely due to your container settings (limits within the cgroup) that when the process exceeds the container memory threshold, the OOM killer kills the process putting on the most memory pressure (Joe Conway has an [excellent blog on this topic](https://www.crunchydata.com/blog/deep-postgresql-thoughts-the-linux-assassin)). Without knowing more about your setup, if you do need to use the dump/restore method, you likely need to increase the memory limit of your container.



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

* Re: [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 17:19 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2024-08-19 17:19 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

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

* Re: [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 18:53 ` "itinance (@itinance)" <noreply+itinance@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: itinance (@itinance) @ 2024-08-19 18:53 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@jkatz probably out of scope, but since you recommended `pg_basebackup` (thx!), I tried it but after running 1-2 hours it broke up with `backup failed: ERROR:  requested WAL segment 0000000100000169000000F2 has already been removed`.
Is this normal for big databases? Should I rather try to split the whole database into minor databases that this can't happen during the time of a backup?


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

* Re: [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 19:04 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: jkatz (@jkatz) @ 2024-08-19 19:04 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@itinance Hard to answer without specific details on database size and transaction amount. However, what's happening is that your WAL is being recycled before the backup completes.

In the [`pg_basebackup`](https://www.postgresql.org/docs/current/app-pgbasebackup.html) docs, there are several WAL methods described (`X`) option:

* `n` - None
* `f` - fetches all the WAL at the end (which sounds like what you're using) - if [`wal_keep_size`](https://www.postgresql.org/docs/current/runtime-config-replication.html#GUC-WAL-KEEP-SIZE) is too small, then you'll encounter a message like the above
* `s` - stream, sends the WAL simultaneously with the backup.

If your backup strategy involves being able to restore to a point in time (point-in-time recovery), you'll want to keep the WAL with your backups. If your backup strategy is to just snapshot at a particular point of time ("standalone backup"), then you can use `n`.

(So yes, slightly out of scope for pgvector, but want to help you get in the right direction :smile:)

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

* Re: [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw
@ 2024-08-19 19:06 ` "itinance (@itinance)" <noreply+itinance@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: itinance (@itinance) @ 2024-08-19 19:06 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@jkatz thank you very much!  this helped me a lot! 

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


end of thread, other threads:[~2024-08-19 19:06 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-08-19 13:53 [pgvector/pgvector] issue #647: Restoring a backup suddenly breaks with CREATE INDEX ... USING hnsw "itinance (@itinance)" <noreply+itinance@github.com>
2024-08-19 14:04 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-08-19 14:07 ` "itinance (@itinance)" <noreply+itinance@github.com>
2024-08-19 16:38 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-08-19 17:19 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-08-19 18:53 ` "itinance (@itinance)" <noreply+itinance@github.com>
2024-08-19 19:04 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-08-19 19:06 ` "itinance (@itinance)" <noreply+itinance@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