timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
https://www.timescale.com/
Other
17.86k stars 884 forks source link

[Bug]: Can't drop table from publication if added before `create_hypertable()` #7208

Open soedirgo opened 2 months ago

soedirgo commented 2 months ago

What type of bug is this?

Unexpected error

What subsystems and features are affected?

Other

What happened?

If create_hypertable() is called on a base table after it's added to a publication, its hypertable doesn't get added into pg_publication_tables. This prevents Postgres from dropping the table from the publication because it'll try to drop the hypertable during alter publication ... drop table ....

TimescaleDB version affected

2.16.1

PostgreSQL version used

15.7

What operating system did you use?

Alpine Linux 3.20 arm64

What installation method did you use?

Docker

What platform did you run on?

On prem/Self-hosted

Relevant log output and stack trace

postgres=# alter publication p drop table public.t1;
ERROR:  relation "_hyper_1_1_chunk" is not part of the publication

How can we reproduce the bug?

Run the following (tested using Docker on timescale/timescaledb:latest-pg15):

create table public.t1 (timestamp timestamptz not null);
create publication p;
alter publication p add table public.t1;
select create_hypertable('public.t1', 'timestamp');
insert into public.t1 (timestamp) values (now());
alter publication p drop table public.t1;
mkindahl commented 2 months ago

@soedirgo Thank you for the bug report. Unfortunately, we do not support logical replication of hypertables currently (for implementation reasons). This makes it strange that you can create a hypertable when you have publications for it. Fixing logical replication for hypertables is a significant undertaking, but just preventing the creation of hypertables with publications by throwing an error is probably easier.

soedirgo commented 2 months ago

Thanks for the response @mkindahl. Agreed that preventing the creation of hypertables on published tables is a lower hanging fruit and prevents the unhappy state.