{"record":{"id":"56718217dd8c7867","repo":"immich-app/immich","slug":"if-using-docker-consider-increasing-shm-size-for-the","errorCode":null,"errorMessage":"If using Docker, consider increasing shm_size for the database.","messagePattern":"If using Docker, consider increasing shm_size for the database\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/src/repositories/database.repository.ts","lineNumber":255,"sourceCode":"        await sql`ALTER TABLE ${sql.raw(table)} ADD COLUMN embedding real[] NOT NULL`.execute(tx);\n      }\n      await sql`ALTER TABLE ${sql.raw(table)} ALTER COLUMN embedding SET DATA TYPE real[]`.execute(tx);\n      await sql`\n        ALTER TABLE ${sql.raw(table)}\n        ALTER COLUMN embedding\n        SET DATA TYPE vector(${sql.raw(String(dimSize))})`.execute(tx);\n      await sql.raw(vectorIndexQuery({ vectorExtension, table, indexName, lists })).execute(tx);\n    });\n    this.logger.log(`Reindexed ${indexName}`);\n    void this.vacuum({ table }).catch((error) => this.logger.warn(`Failed to vacuum ${table}: ${error}`));\n  }\n\n  async vacuum({ analyze = false, table }: { analyze?: boolean; table?: keyof DB } = {}): Promise<void> {\n    try {\n      await sql`VACUUM ${sql.raw(analyze ? 'ANALYZE' : '')} ${sql.raw(table ?? '')}`.execute(this.db);\n    } catch (error) {\n      this.logger.warn(`Failed to vacuum ${table || 'database'}: ${error}`);\n      this.logger.warn('If using Docker, consider increasing shm_size for the database.');\n    }\n  }\n\n  reindex(table: keyof DB, { concurrently = false } = {}): Promise<unknown> {\n    return sql`REINDEX TABLE ${sql.raw(concurrently ? 'CONCURRENTLY' : '')} ${sql.raw(table)}`.execute(this.db);\n  }\n\n  private async getDatabaseName(): Promise<string> {\n    const { rows } = await sql<{ db: string }>`SELECT current_database() as db`.execute(this.db);\n    return rows[0].db;\n  }\n\n  getMigrations() {\n    return this.db.selectFrom('kysely_migrations').select(['name', 'timestamp']).orderBy('name', 'asc').execute();\n  }\n\n  async getSchemaDrift() {\n    const source = schemaFromCode({","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/immich-app/immich/blob/e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c/server/src/repositories/database.repository.ts#L237-L273","documentation":"After a VACUUM command fails, the repository logs the failure and this hint suggesting that in Docker the default 64MB shared memory (shm_size) of the Postgres container is often too small for VACUUM operations. The vacuum call swallows the error and continues.","triggerScenarios":"vacuum() runs `VACUUM [ANALYZE] [table]` and Postgres raises an error — classically 'out of shared memory' during concurrent operations or VACUUM inside a Dockerized Postgres with low shm_size. Called by reindexVectors after reindexing.","commonSituations":"Postgres Docker container with default shm_size running VACUUM/ANALYZE on large tables; heavy concurrent index creation exceeding max_locks/shared memory; low disk space during vacuum.","solutions":["Increase the database container's shm_size (e.g. shm_size: 256mb in docker-compose for the postgres service)","Run VACUUM manually inside the database container with psql when idle to see the exact error","Check Postgres logs for the underlying error (out of shared memory, disk full, locks)","If transient, retry once the database is less loaded"],"exampleFix":"// before (docker-compose.yml)\ndatabase:\n  image: ghcr.io/immich-app/postgres\n// after\ndatabase:\n  image: ghcr.io/immich-app/postgres\n  shm_size: 256mb","handlingStrategy":"retry","validationCode":"// pre-check shared memory from the host before heavy maintenance\nconst shmBytes = Number(fs.readFileSync('/dev/shm/../shm_size', 'utf8')) || -1;\n// simpler: verify in container\n// docker exec immich_postgres df -h /dev/shm   → ensure >> 64mb","typeGuard":null,"tryCatchPattern":"try {\n  await db.vacuum({ analyze: true, table: 'smart_search' });\n} catch (err) {\n  if (String(err).includes('out of shared memory')) {\n    logger.warn('Increase Postgres shm_size and retry vacuum');\n  }\n}","preventionTips":["Set shm_size: 256mb (or higher) on the Postgres Docker service from day one","Schedule VACUUM/REINDEX during low-traffic windows","Watch Postgres logs for 'out of shared memory' during maintenance","Keep disk headroom above the size of the largest table"],"tags":["postgres","docker","vacuum","shm-size"],"backgroundTag":"database-query-failed","analyzedSha":"e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c","analyzedAt":"2026-09-15T07:20:19.675Z","contentChangedAt":"2026-09-15T07:20:19.675Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}