DEV Community

Michael
Michael

Posted on • Originally published at gbase8.cn

Fixing "Can't get distribution attribute of table" in GBase 8a

When a gbase database cluster experiences an unclean shutdown — a sudden power loss or kernel panic — some metadata that was still in memory may never make it to disk. This can leave the critical gbase.table_distribution table with missing rows, causing queries against certain tables to fail with the error:

ERROR 1149 (42000): (GBA-02SC-1001) Can't get distribution attribute of table `testdb`.`t2_test`, please check your gbase.table_distribution.
Enter fullscreen mode Exit fullscreen mode

The Symptom

The affected table enters a contradictory state:

  • Dropping it returns Unknown table.
  • Re‑creating it returns Table already exists.

The data files exist on disk, but the metadata record that describes how the table is distributed is gone.

Root Cause

GBase 8a stores critical table metadata — distribution type (hash or random), replication status, hash column — in the system table gbase.table_distribution. After an abrupt shutdown, this table may have missing entries, causing the cluster to lose track of the table's distribution properties.

Recovery Options

Option 1: Re‑insert the Metadata Row (Keeps Data Intact)

This is the recommended approach when the data must be preserved. Insert the missing row directly into gbase.table_distribution.

-- Insert the lost metadata record
INSERT INTO gbase.table_distribution
VALUES ('testdb.t2_test', 'testdb', 't2_test', 'NO', NULL, NULL, NULL, 'NO', 2);

-- Verify the row is now present
SELECT * FROM gbase.table_distribution WHERE index_name LIKE '%t2_test%';
Enter fullscreen mode Exit fullscreen mode

Key fields:

  • isReplicate: YES if the table is replicated, otherwise NO.
  • hash_column: The distribution key column name (if hash‑distributed); NULL for random distribution.
  • data_distribution_id: A numeric ID. Copy the value from another healthy table in the same database to keep it consistent.

After inserting, restart the gcluster service so the metadata takes effect (the table_distribution table is managed by gcluster, not gnodes):

gcluster_services gcluster restart
Enter fullscreen mode Exit fullscreen mode

The table should now be queryable again.

Finding All Tables with Missing Metadata

Use this query to detect which tables have lost their distribution records:

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'testdb'
  AND table_name NOT IN (
      SELECT tbname FROM gbase.table_distribution WHERE dbname = 'testdb'
  );
Enter fullscreen mode Exit fullscreen mode

Option 2: Restore from Another Identical Cluster

If you have a standby cluster with the same table layout, copy the table_distribution data files across.

scp gbase@<remote_host>:/opt/gbase/gcluster/userdata/gcluster/gbase/table_distribution.* \
    /opt/gbase/gcluster/userdata/gcluster/gbase/
Enter fullscreen mode Exit fullscreen mode

Always back up the local files first before overwriting them.

Option 3: Drop and Rebuild (Test Environments Only)

If the data is disposable, dropping and recreating the database is the fastest path to recovery.

Prevention

  • Keep regular backups of the table_distribution table, especially on single‑node or low‑replica clusters.
  • Monitor cluster health and avoid abrupt shutdowns whenever possible.

In a gbase database, the Can't get distribution attribute error is a classic case of metadata–data inconsistency after a crash. Knowing how to manually reconstruct the missing rows gives you a quick, safe recovery path that preserves your business data.

Top comments (0)