{"record":{"id":"54542decbe93d15e","repo":"bytebase/bytebase","slug":"failed-to-get-instance-s","errorCode":null,"errorMessage":"failed to get instance %s","messagePattern":"failed to get instance (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/runner/plancheck/target.go","lineNumber":21,"sourceCode":"import (\n\t\"context\"\n\n\t\"github.com/pkg/errors\"\n\n\t\"github.com/bytebase/bytebase/backend/common\"\n\t\"github.com/bytebase/bytebase/backend/store\"\n)\n\n// resolveDatabaseTarget resolves a workspace- or project-scoped database resource name.\nfunc resolveDatabaseTarget(ctx context.Context, stores *store.Store, target string) (*store.InstanceMessage, *store.DatabaseMessage, error) {\n\tprojectID, instanceID, databaseName, err := common.GetDatabaseResourceName(target)\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrapf(err, \"failed to parse target %s\", target)\n\t}\n\n\tinstance, err := stores.GetInstanceByResourceID(ctx, instanceID)\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrapf(err, \"failed to get instance %s\", instanceID)\n\t}\n\tif instance == nil {\n\t\treturn nil, nil, errors.Errorf(\"instance %s not found\", instanceID)\n\t}\n\tif instance.Deleted {\n\t\treturn nil, nil, errors.Errorf(\"instance %s has been deleted\", instanceID)\n\t}\n\tif (projectID == nil) != (instance.ProjectID == nil) ||\n\t\tprojectID != nil && *instance.ProjectID != *projectID {\n\t\tif projectID == nil {\n\t\t\treturn nil, nil, errors.Errorf(\"project instance %q must be addressed through its project\", instanceID)\n\t\t}\n\t\treturn nil, nil, errors.Errorf(\"instance %q does not belong to project %q\", instanceID, *projectID)\n\t}\n\n\tdatabase, err := stores.GetDatabase(ctx, &store.FindDatabaseMessage{InstanceID: &instance.ResourceID, DatabaseName: &databaseName})\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrapf(err, \"failed to get database %q\", databaseName)","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/runner/plancheck/target.go#L3-L39","documentation":"After successfully parsing the target, resolveDatabaseTarget loads the instance with stores.GetInstanceByResourceID. A database error occurred during that lookup (connection failure, query error) and is wrapped with this message naming the instance ID. Note this is distinct from the not-found case, which returns its own error.","triggerScenarios":"GetInstanceByResourceID returns a non-nil error: the metadata database is unreachable, the query fails, or a store-level constraint breaks while fetching the instance row for instanceID.","commonSituations":"Metadata Postgres down or misconfigured (bad PG_URL); transient connection pool exhaustion; corrupted store state triggering a query error during the instance read.","solutions":["Check the wrapped inner error for the store/DB failure cause","Verify the metadata database connectivity (PG_URL) and that the Bytebase store can query","Retry the operation if the failure was transient (connection reset/pool timeout)"],"exampleFix":"// before\ninstance, err := stores.GetInstanceByResourceID(ctx, instanceID)\nif err != nil {\n\treturn nil, nil, errors.Wrapf(err, \"failed to get instance %s\", instanceID)\n}\n// after\ninstance, err := stores.GetInstanceByResourceID(ctx, instanceID)\nif err != nil {\n\tif isTransientDBError(err) {\n\t\t// retry once before surfacing\n\t\tinstance, err = stores.GetInstanceByResourceID(ctx, instanceID)\n\t}\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrapf(err, \"failed to get instance %s\", instanceID)\n\t}\n}","handlingStrategy":"retry","validationCode":"if instanceID == \"\" {\n\treturn errors.New(\"instanceID parsed from target is empty\")\n}","typeGuard":null,"tryCatchPattern":"var nerr net.Error\nif errors.As(err, &nerr) && nerr.Timeout() {\n\t// transient: retry with backoff\n} else if isConnectionError(err) {\n\t// check metadata DB health before retrying\n}","preventionTips":["Monitor metadata Postgres health (PG_URL connectivity)","Set sane connection-pool limits to avoid pool exhaustion","Distinguish transient DB errors from permanent ones before alerting"],"tags":["go","database","instance-lookup","plancheck"],"backgroundTag":"database-query-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}