immich/docs/docs/guides/database-queries.md
Matthew Momjian 28d081338b
docs: update community Guide/Projects, small PG query updates (#8844)
* Update community-projects.tsx

* Update community-guides.tsx

* Update community-projects.tsx

* Update database-queries.md

* Update database-queries.md

* Update community-projects.tsx
2024-04-16 12:39:03 -04:00

2.9 KiB

Database Queries

:::danger Keep in mind that mucking around in the database might set the moon on fire. Avoid modifying the database directly when possible, and always have current backups. :::

:::tip Run docker exec -it immich_postgres psql immich <DB_USERNAME> to connect to the database via the container directly.

(Replace <DB_USERNAME> with the value from your .env file). :::

Assets

:::note The "originalFileName" column is the name of the file at time of upload, including the extension. :::

SELECT * FROM "assets" WHERE "originalFileName" = 'PXL_20230903_232542848.jpg';
SELECT * FROM "assets" WHERE "originalFileName" LIKE 'PXL_%'; -- all files starting with PXL_
SELECT * FROM "assets" WHERE "originalFileName" LIKE '%_2023_%'; -- all files with _2023_ in the middle
SELECT * FROM "assets" WHERE "originalPath" = 'upload/library/admin/2023/2023-09-03/PXL_20230903_232542848.jpg';
SELECT * FROM "assets" WHERE "originalPath" LIKE 'upload/library/admin/2023/%';

:::note You can calculate the checksum for a particular file by using the command sha1sum <filename>. :::

SELECT encode("checksum", 'hex') FROM "assets";
SELECT * FROM "assets" WHERE "checksum" = decode('69de19c87658c4c15d9cacb9967b8e033bf74dd1', 'hex');
SELECT * FROM "assets" WHERE "livePhotoVideoId" IS NOT NULL;
SELECT "assets".* FROM "exif"
  LEFT JOIN "assets" ON "assets"."id" = "exif"."assetId"
  WHERE "exif"."assetId" IS NULL;
SELECT * FROM "assets"
  JOIN "exif" ON "assets"."id" = "exif"."assetId"
  WHERE "exif"."fileSizeInByte" < 100000
  ORDER BY "exif"."fileSizeInByte" ASC;
SELECT * FROM "assets" WHERE "assets"."previewPath" IS NULL OR "assets"."thumbnailPath" IS NULL;
SELECT * FROM "assets" WHERE "assets"."type" = 'VIDEO';
SELECT * FROM "assets" WHERE "assets"."type" = 'IMAGE';
SELECT "assets"."type", COUNT(*) FROM "assets" GROUP BY "assets"."type";
SELECT "users"."email", "assets"."type", COUNT(*) FROM "assets"
  JOIN "users" ON "assets"."ownerId" = "users"."id"
  GROUP BY "assets"."type", "users"."email"
  ORDER BY "users"."email";
SELECT * FROM "move_history";

Users

SELECT * FROM "users";

System Config

SELECT "key", "value" FROM "system_config";

(Only used when not using the config file)

Persons

DELETE FROM person WHERE name = 'PersonNameHere';