postgres-ai / database-lab-engine

DBLab enables 🖖 database branching and ⚡️ thin cloning for any Postgres database and empowers DB testing in CI/CD. This optimizes database-related costs while improving time-to-market and software quality. Follow to stay updated.
https://postgres.ai/products/how-it-works
Apache License 2.0
2.11k stars 58 forks source link

Restricted template cloning failure when using timescaledb [simple fix included] #173

Closed TheLiamGuy closed 6 months ago

TheLiamGuy commented 1 year ago

Problem:

When cloning using the restricted user template (e.g. Joe Bot) and Timescaledb hypertables, the clone fails:

High level logs: ERROR: failed to create a Database Lab clone: failed to create a new clone: failed to create clone, unexpected status given: FATAL

Explanation from server logs: FATAL failed to run objects restrict query: pq: operation not supported on chunk tables

The reason is because the restricted script tries to change the owner of all relations to the restricted user, which is not allowed for timescaledb chunks.

How to replicate the error:

1) Set up a DB Lab instance with a snapshot that includes TimescaleDB tables. The clone container must also support TimescaleDB (Postgres.AI extended already does) 2) Clone the snapshot with restricted mode active, or with a standard install of Joe Bot

Proposed solution:

Edit database-lab-engine/engine/internal/provision/databases/postgres/postgres_mgmt.go

Change and not n.nspname in ('pg_catalog', 'information_schema') to and not n.nspname in ('pg_catalog', 'information_schema', '_timescaledb_internal')

NikolayS commented 6 months ago

applied in 3.4.0