bytebase/bytebase · error

failed to get tables from datashare database %q

Error message

failed to get tables from datashare database %q

What it means

When the driver is created with datashare enabled, SyncDBSchema calls d.getDatashareTables(txn) to read tables shared from a datashare producer database. Failure there is wrapped as "failed to get tables from datashare database %q". It indicates the datashare table enumeration query failed for the consumer database.

Source

Thrown at backend/plugin/db/redshift/sync.go:88

		return nil, common.Errorf(common.NotFound, "database %q not found", d.databaseName)
	}

	txn, err := d.db.BeginTx(ctx, nil)
	if err != nil {
		return nil, err
	}
	defer txn.Rollback()

	schemaList, err := d.getSchemas(txn)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to get schemas from database %q", d.databaseName)
	}
	var tableMap map[string][]*storepb.TableMetadata
	var viewMap map[string][]*storepb.ViewMetadata
	if d.datashare {
		tableMap, err = d.getDatashareTables(txn)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to get tables from datashare database %q", d.databaseName)
		}
	} else {
		columnMap, err := getTableColumns(txn)
		if err != nil {
			return nil, errors.Wrap(err, "failed to get table columns")
		}
		tableMap, err = getTables(txn, columnMap)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to get tables from database %q", d.databaseName)
		}
		viewMap, err = getViews(txn, columnMap)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to get views from database %q", d.databaseName)
		}
	}
	if err := txn.Commit(); err != nil {
		return nil, err
	}

View on GitHub (pinned to 1870550677)

Solutions

  1. Verify the consumer still has USAGE on the datashare: SHOW DATASHARES / GRANT USAGE ON DATASHARE <share> TO DATABASE <db>.
  2. Re-run ALTER DATABASE <db> WITH... / re-associate the datashare if the producer changed it.
  3. Check with the producer account that the share and its objects still exist.
  4. If datashare sync is not needed, recreate the driver with datashare disabled to take the normal getTables path.
Defensive patterns

Strategy: validation

Validate before calling

// ensure the consumer still has usage on the datashare
// SHOW DATASHARES;  -- confirm share exists and is associated
// GRANT USAGE ON DATASHARE <share> TO DATABASE <db>;  -- re-grant if revoked

Try / catch

meta, err := d.SyncDBSchema(ctx)
if err != nil && strings.Contains(err.Error(), "datashare") {
	return fmt.Errorf("datashare metadata unavailable (check USAGE grants and share state): %w", err)
}

Prevention

When it happens

Trigger: SyncDBSchema with d.datashare == true and getDatashareTables(txn) failing — the consumer cannot read the datashare, the share was revoked/altered, or the catalog query over the shared tables errors.

Common situations: Producer altered or dropped the datashare after the consumer configured sync; the consumer database lacks CREATE DATASHARE/USAGE grants; cross-region datashares whose metadata views are temporarily unavailable.

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/dd6373ea28d44d87. Report an issue: GitHub.