-- Create User Error -- time="2025-08-01T16:07:03Z" level=info msg=activity caller="/home/runner/work/zitadel/zitadel/internal/activity/activity.go:105" domain="https://ZITADEL_DOMAIN" grpcStatus=0 httpStatus=200 instance=324226624532780026 isSystemUser=false method=/zitadel.user.v2.UserService/ListUsers org=326104999421547514 path=/v2/users requestMethod=POST trigger=resourceAPI user=331365795156198931 time="2025-08-01T16:07:03Z" level=info msg="log record emitted" caller="/home/runner/work/zitadel/zitadel/internal/logstore/emitters/stdout/stdout.go:19" record="{\"logDate\":\"2025-08-01T16:07:03.694287711Z\",\"protocol\":0,\"requestUrl\":\"/zitadel.user.v2.UserService/ListUsers\",\"responseStatus\":0,\"requestHeaders\":{\":authority\":[\"localhost:8080\"],\"authorization\":[\"[REDACTED]\"],\"content-type\":[\"application/grpc\"],\"grpc-accept-encoding\":[\"gzip\"],\"grpcgateway-accept\":[\"application/json\"],\"grpcgateway-authorization\":[\"[REDACTED]\"],\"grpcgateway-content-type\":[\"application/json\"],\"user-agent\":[\"grpc-go/1.72.1\"],\"x-forwarded-for\":[\"10.0.6.13, 192.168.65.1\"],\"x-forwarded-host\":[\"ZITADEL_DOMAIN\"],\"x-zitadel-orgid\":[\"326104999421547514\"],\"zitadel-activity-path\":[\"/v2/users\"],\"zitadel-activity-request-method\":[\"POST\"]},\"responseHeaders\":{},\"instanceId\":\"324226624532780026\",\"projectId\":\"324226624532911098\",\"requestedDomain\":\"ZITADEL_DOMAIN\",\"requestedHost\":\"ZITADEL_DOMAIN\"}" 2025-08-01 16:07:03.974 UTC [56] ERROR: duplicate key value violates unique constraint "unique_constraints_pkey" 2025-08-01 16:07:03.974 UTC [56] DETAIL: Key (instance_id, unique_type, unique_field)=(324226624532780026, usernames, USER_EMAIL) already exists. 2025-08-01 16:07:03.974 UTC [56] STATEMENT: INSERT INTO eventstore.unique_constraints ( instance_id , unique_type , unique_field ) VALUES ($1, $2, $3) time="2025-08-01T16:07:03Z" level=warning msg="add unique constraint failed" caller="/home/runner/work/zitadel/zitadel/internal/eventstore/v3/unique_constraints.go:78" error="ERROR: duplicate key value violates unique constraint \"unique_constraints_pkey\" (SQLSTATE 23505)" time="2025-08-01T16:07:03Z" level=info msg=activity caller="/home/runner/work/zitadel/zitadel/internal/activity/activity.go:105" domain="https://ZITADEL_DOMAIN" grpcStatus=6 httpStatus=409 instance=324226624532780026 isSystemUser=false method=/zitadel.user.v2.UserService/AddHumanUser org=326104999421547514 path=/v2/users/human requestMethod=POST trigger=resourceAPI user=331365795156198931 time="2025-08-01T16:07:04Z" level=info msg="log record emitted" caller="/home/runner/work/zitadel/zitadel/internal/logstore/emitters/stdout/stdout.go:19" record="{\"logDate\":\"2025-08-01T16:07:04.11220067Z\",\"protocol\":0,\"requestUrl\":\"/zitadel.user.v2.UserService/AddHumanUser\",\"responseStatus\":6,\"requestHeaders\":{\":authority\":[\"localhost:8080\"],\"authorization\":[\"[REDACTED]\"],\"content-type\":[\"application/grpc\"],\"grpc-accept-encoding\":[\"gzip\"],\"grpcgateway-accept\":[\"application/json\"],\"grpcgateway-authorization\":[\"[REDACTED]\"],\"grpcgateway-content-type\":[\"application/json\"],\"user-agent\":[\"grpc-go/1.72.1\"],\"x-forwarded-for\":[\"10.0.6.13, 192.168.65.1\"],\"x-forwarded-host\":[\"ZITADEL_DOMAIN\"],\"x-zitadel-orgid\":[\"326104999421547514\"],\"zitadel-activity-path\":[\"/v2/users/human\"],\"zitadel-activity-request-method\":[\"POST\"]},\"responseHeaders\":{},\"instanceId\":\"324226624532780026\",\"projectId\":\"324226624532911098\",\"requestedDomain\":\"ZITADEL_DOMAIN\",\"requestedHost\":\"ZITADEL_DOMAIN\"}" -- Investigating these errors I found the following unique_contraints exist, when the user records do not exist. select unique_type, unique_field, u.username from eventstore.unique_constraints as uc left join projections.users14 as u on u.username = uc.unique_field where unique_type in ('usernames') and u.username is null ; -- Add Grant Error -- time="2025-08-01T16:19:52Z" level=info msg="log record emitted" caller="/home/runner/work/zitadel/zitadel/internal/logstore/emitters/stdout/stdout.go:19" record="{\"logDate\":\"2025-08-01T16:19:52.552239553Z\",\"protocol\":0,\"requestUrl\":\"/zitadel.management.v1.ManagementService/ListUserGrants\",\"responseStatus\":0,\"requestHeaders\":{\":authority\":[\"localhost:8080\"],\"authorization\":[\"[REDACTED]\"],\"content-type\":[\"application/grpc\"],\"grpc-accept-encoding\":[\"gzip\"],\"grpcgateway-accept\":[\"application/json\"],\"grpcgateway-authorization\":[\"[REDACTED]\"],\"grpcgateway-content-type\":[\"application/json\"],\"user-agent\":[\"grpc-go/1.72.1\"],\"x-forwarded-for\":[\"10.0.6.13, 192.168.65.1\"],\"x-forwarded-host\":[\"ZITADEL_DOMAIN\"],\"x-zitadel-orgid\":[\"326104999421547514\"],\"zitadel-activity-path\":[\"/users/grants/_search\"],\"zitadel-activity-request-method\":[\"POST\"]},\"responseHeaders\":{},\"instanceId\":\"324226624532780026\",\"projectId\":\"324226624532911098\",\"requestedDomain\":\"ZITADEL_DOMAIN\",\"requestedHost\":\"ZITADEL_DOMAIN\"}" 2025-08-01 16:19:52.851 UTC [966] ERROR: duplicate key value violates unique constraint "unique_constraints_pkey" 2025-08-01 16:19:52.851 UTC [966] DETAIL: Key (instance_id, unique_type, unique_field)=(324226624532780026, user_grant, 326104999421547514:326613935312606060:324951332081374202:326106173122024442) already exists. 2025-08-01 16:19:52.851 UTC [966] STATEMENT: INSERT INTO eventstore.unique_constraints ( instance_id , unique_type , unique_field ) VALUES ($1, $2, $3) time="2025-08-01T16:19:52Z" level=warning msg="add unique constraint failed" caller="/home/runner/work/zitadel/zitadel/internal/eventstore/v3/unique_constraints.go:78" error="ERROR: duplicate key value violates unique constraint \"unique_constraints_pkey\" (SQLSTATE 23505)" time="2025-08-01T16:19:52Z" level=info msg=activity caller="/home/runner/work/zitadel/zitadel/internal/activity/activity.go:105" domain="https://ZITADEL_DOMAIN" grpcStatus=6 httpStatus=409 instance=324226624532780026 isSystemUser=false method=/zitadel.management.v1.ManagementService/AddUserGrant org=326104999421547514 path=/users/326613935312606060/grants requestMethod=POST trigger=resourceAPI user=331365795156198931 time="2025-08-01T16:19:53Z" level=info msg="log record emitted" caller="/home/runner/work/zitadel/zitadel/internal/logstore/emitters/stdout/stdout.go:19" record="{\"logDate\":\"2025-08-01T16:19:53.183339929Z\",\"protocol\":0,\"requestUrl\":\"/zitadel.management.v1.ManagementService/AddUserGrant\",\"responseStatus\":6,\"requestHeaders\":{\":authority\":[\"localhost:8080\"],\"authorization\":[\"[REDACTED]\"],\"content-type\":[\"application/grpc\"],\"grpc-accept-encoding\":[\"gzip\"],\"grpcgateway-accept\":[\"application/json\"],\"grpcgateway-authorization\":[\"[REDACTED]\"],\"grpcgateway-content-type\":[\"application/json\"],\"user-agent\":[\"grpc-go/1.72.1\"],\"x-forwarded-for\":[\"10.0.6.13, 192.168.65.1\"],\"x-forwarded-host\":[\"ZITADEL_DOMAIN\"],\"x-zitadel-orgid\":[\"326104999421547514\"],\"zitadel-activity-path\":[\"/users/326613935312606060/grants\"],\"zitadel-activity-request-method\":[\"POST\"]},\"responseHeaders\":{},\"instanceId\":\"324226624532780026\",\"projectId\":\"324226624532911098\",\"requestedDomain\":\"ZITADEL_DOMAIN\",\"requestedHost\":\"ZITADEL_DOMAIN\"}" -- Investigating these errors I found the following unique_contraints exist, when the grant records do not exist. with all_grants as ( select unique_type, unique_field, STRING_TO_ARRAY(unique_field, ':') as gparts from eventstore.unique_constraints as uc where unique_type in ('user_grant') ) select ag.* from all_grants as ag left join projections.user_grants5 as ug on ug.granted_org = ag.gparts[1] and ug.user_id = ag.gparts[2] and ug.project_id = ag.gparts[3] where ug.project_id is null ;