bytebase/bytebase · error

failed to get function dependency tables from database %q

Error message

failed to get function dependency tables from database %q

What it means

As part of SyncDBSchema, getFunctionDependencyTables(txn) queries dependency catalogs (pg_depend/pg_rewrite) to find tables referenced by function bodies. This wrapper fires when that catalog query fails, aborting the whole schema sync since SyncDBSchema returns nil on any sub-step failure.

Source

Thrown at backend/plugin/db/pg/sync.go:165

		if err != nil {
			return nil, errors.Wrapf(err, "failed to get table partitions from database %q", d.databaseName)
		}
	}
	viewMap, viewOidMap, err := getViews(txn, columnMap, triggerMap, extensionDepend)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get views from database %q", d.databaseName)
	}
	ruleMap, err := getRules(txn)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get rules from database %q", d.databaseName)
	}
	materializedViewMap, materializedViewOidMap, err := getMaterializedViews(txn, indexMap, triggerMap, extensionDepend)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get materialized views from database %q", d.databaseName)
	}
	functionDependencyTables, err := getFunctionDependencyTables(txn)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get function dependency tables from database %q", d.databaseName)
	}
	functionMap, err := getFunctions(txn, functionDependencyTables, tableOidMap, viewOidMap, materializedViewOidMap, extensionDepend)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get functions from database %q", d.databaseName)
	}
	sequenceMap, err := getSequences(txn, tableOidMap, extensionDepend)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get sequences from database %q", d.databaseName)
	}

	extensions, err := getExtensions(txn)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get extensions from database %q", d.databaseName)
	}

	enumTypes, err := getEnumTypes(txn, extensionDepend)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get enum types from database %q", d.databaseName)

View on GitHub (pinned to 1870550677)

Solutions

  1. Read the wrapped cause to identify the real driver error.
  2. Ensure the sync role retains default public read access to pg_depend and related catalogs.
  3. Increase timeouts and retry; split very large schemas if catalog scans are slow.
  4. Avoid transaction-mode poolers that can sever the sync's single catalog transaction.
Defensive patterns

Strategy: try-catch

Validate before calling

SELECT count(*) FROM pg_depend; -- dependency catalog accessible?

Try / catch

deps, err := getFunctionDependencyTables(txn)
if err != nil {
	if isTransient(err) { return retrySync(txn) }
	return fmt.Errorf("sync aborted: %w", err)
}

Prevention

When it happens

Trigger: Calling SyncDBSchema when the function-dependency catalog query errors: connection loss mid-transaction, permission restriction on pg_depend, or a query timeout on databases with many functions/dependencies.

Common situations: Long-running syncs on databases with thousands of functions; restricted roles in hardened environments; unstable connections to cloud Postgres through pgbouncer in transaction mode.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/fa17b55a2591fe2e. Report an issue: GitHub.