Open srieding opened 1 year ago
Hello @srieding,
Thanks for the detailed steps to reproduce the problem. I was able to reproduce the behavior with TimescaleDB 2.12.0-dev in my local environment. I was only able to add the constraint only to measurements
.
Hi!
This issue makes migration procedures painful following the current documentation because you end up with restored hypertables without FKs.
Documented procedure is:
pg_restore: from TOC entry 4619; 2606 361444 CONSTRAINT sensor_readings sensor_readings_read_time_device_id_12dfafaa_uniq postgres
pg_restore: error: could not execute query: ERROR: operation not supported on hypertables that have compression enabled
Command was: ALTER TABLE ONLY public.sensor_readings
ADD CONSTRAINT sensor_readings_read_time_device_id_12dfafaa_uniq UNIQUE (read_time, device_id);
[...]
pg_restore: creating FK CONSTRAINT "public.sensor_readings sensor_readings_device_id_f120ca42_fk_sensor_devices_id"
pg_restore: from TOC entry 4621; 2606 361463 FK CONSTRAINT sensor_readings sensor_readings_device_id_f120ca42_fk_sensor_devices_id postgres
pg_restore: error: could not execute query: ERROR: operation not supported on hypertables that have compression enabled
Command was: ALTER TABLE ONLY public.sensor_readings
ADD CONSTRAINT sensor_readings_device_id_f120ca42_fk_sensor_devices_id FOREIGN KEY (device_id) REFERENCES public.sensor_devices(id) DEFERRABLE INITIALLY DEFERRED;
So, I'm going to slightly change the procedure to:
ALTER TABLE
on the hypertable(s)This way I'm still going to have the same errors, but I don't care because the FK Constraint was already in place before setting a compression policy.
Is there any other option? Thank you!
Hi!
Looking at the 2.16.0 Release Notes, is this issue somehow covered/fixed?
Offer new options for use cases that require foreign keys defined.
You can now add foreign keys from regular tables towards hypertables. We have also removed
some really annoying locks in the reverse direction that blocked access to referenced tables
while compression was running.
And below, in the highlights section:
You can add foreign keys from regular tables to hypertables, with support for all types of cascading options.
This is useful for hypertables that partition using sequential IDs, and need to reference those IDs from other tables.
Thank you!
What type of bug is this?
Unexpected error
What subsystems and features are affected?
Compression
What happened?
If you create a table, make it a hypertable, add a foreign key, then switch on compression you can make a table that you are not able to make when you make the table, make it a hypertable, switch on compression and then try to add the foreign key.
TimescaleDB version affected
2.11.2
PostgreSQL version used
14
What operating system did you use?
windows 10 x64
What installation method did you use?
Docker
What platform did you run on?
Not applicable
Relevant log output and stack trace
No response
How can we reproduce the bug?