{"record":{"id":"117f4a82d91245c0","repo":"bytebase/bytebase","slug":"failed-to-get-event-triggers-from-database-q","errorCode":null,"errorMessage":"failed to get event triggers from database %q","messagePattern":"failed to get event triggers from database %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/db/pg/sync.go","lineNumber":193,"sourceCode":"\n\textensions, err := getExtensions(txn)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to get extensions from database %q\", d.databaseName)\n\t}\n\n\tenumTypes, err := getEnumTypes(txn, extensionDepend)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to get enum types from database %q\", d.databaseName)\n\t}\n\n\tcompositeTypes, err := getCompositeTypes(txn, extensionDepend)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to get composite types from database %q\", d.databaseName)\n\t}\n\n\teventTriggers, err := getEventTriggers(txn, extensionDepend)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to get event triggers from database %q\", d.databaseName)\n\t}\n\n\tif err := txn.Commit(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tfor i, schemaName := range schemas {\n\t\ttables := tableMap[schemaName]\n\t\tfor _, table := range tables {\n\t\t\tif isAtLeastPG10 {\n\t\t\t\ttable.Partitions = warpTablePartitions(tablePartitionMap, schemaName, table.Name)\n\t\t\t}\n\t\t\t// Add rules to table\n\t\t\tkey := db.TableKey{Schema: schemaName, Table: table.Name}\n\t\t\ttable.Rules = ruleMap[key]\n\t\t}\n\t\t// Add rules to views\n\t\tviews := viewMap[schemaName]","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/db/pg/sync.go#L175-L211","documentation":"SyncDBSchema collects event triggers via getEventTriggers(txn, extensionDepend), reading pg_event_trigger and dependency info to distinguish user triggers from extension-managed ones. This wrapper is applied when that final catalog query fails, aborting the sync just before the transaction commits.","triggerScenarios":"Calling SyncDBSchema when the event-trigger catalog query errors: connection reset near the end of a long sync, statement timeout, or missing catalog access.","commonSituations":"Long syncs on large databases hitting idle-in-transaction or network timeouts right at this final step; hardened roles; servers terminating long-running read transactions.","solutions":["Inspect the wrapped cause for the concrete driver error.","Restore default catalog read privileges if revoked for the sync role.","Increase statement_timeout/idle_in_transaction_session_timeout and retry the sync.","Reduce sync scope or frequency for very large databases to keep the transaction short."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"SELECT count(*) FROM pg_event_trigger; -- readable and cheap to scan","typeGuard":null,"tryCatchPattern":"ets, err := getEventTriggers(txn, extensionDepend)\nif err != nil {\n\treturn fmt.Errorf(\"event trigger collection failed near end of sync: %w\", err)\n}","preventionTips":["Set idle_in_transaction_session_timeout above expected sync duration","Avoid network paths that reset connections mid-transaction","Keep the overall sync transaction short on large databases","Verify catalog privileges before first sync of a new database"],"tags":["postgres","schema-sync","event-trigger","catalog"],"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"}