Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Re-creating a continuous aggregate table with an existing hyper table -- not updating #7403

Open
Auricmondal opened this issue Oct 26, 2024 · 3 comments
Labels

Comments

@Auricmondal
Copy link

Auricmondal commented Oct 26, 2024

What type of bug is this?

Unexpected error

What subsystems and features are affected?

Continuous aggregate

What happened?

If I try to drop an existing continuous aggregate to modify and recreate it, the newly formed view does not update at all whenever a new data is added to the hyper table.

TimescaleDB version affected

I have tried this on versions: 2.16.1 and 2.10.2

PostgreSQL version used

16.4

What operating system did you use?

Ubuntu 24.04.1 LTS

What installation method did you use?

Docker

What platform did you run on?

Other

Relevant log output and stack trace

No response

How can we reproduce the bug?

--- Command Lines ---
-- Create ---

CREATE TABLE my_table (
  id VARCHAR NOT NULL,
  data INTEGER DEFAULT 1,
  timestamp TIMESTAMPTZ NOT NULL UNIQUE DEFAULT NOW(),
	 PRIMARY KEY (id, timestamp)
);

CREATE TABLE my_table2 (
  id VARCHAR Primary key unique,
  install_at DATE
);

CREATE MATERIALIZED VIEW IF NOT EXISTS test2
      WITH (timescaledb.continuous) AS
SELECT
	a.id,
	time_bucket('100 years', a.timestamp) AS bucket,
    SUM(a.data) as Total_data,
	MAX(timestamp) as max_timestamp,
b.install_at
FROM my_table a
left join my_table2 b on a.id = b.id
GROUP BY a.id, bucket, b.install_at

SELECT create_hypertable('my_table', 'timestamp');


-- Get ---

select * from my_table;
select * from my_table2;

SELECT hypertable_name
FROM timescaledb_information.hypertables;


-- Alter ---

ALTER TABLE my_table
  ALTER COLUMN id TYPE VARCHAR;


--drop ---

drop table my_table
drop table my_table2
DROP MATERIALIZED VIEW test2;


--Insert ---

INSERT INTO my_table (id, data, timestamp)
VALUES ('5', 4, NOW());

INSERT INTO my_table2 (id,install_at)
VALUES ('4', '2024-10-26 19:15:00+05:30' );

--Alter---

ALTER MATERIALIZED VIEW test2 set (timescaledb.materialized_only = false);

Step 1: create the tables
step 2: create the hyper table
step 3: create the continuous aggregate
step 4: run the alter command
step 5: add data to the tables

---It should work fine till now --

step 6: Drop the view
step 7: recreate the view
step 8: try inserting data to the hyper-table

--- you will see that the view is not updating ---
@akuzm
Copy link
Member

akuzm commented Oct 28, 2024

Sounds like you're encountering the situation described here: https://docs.timescale.com/use-timescale/latest/continuous-aggregates/real-time-aggregates/#real-time-aggregates-and-refreshing-historical-data

Does manually calling the refresh_continuous_aggregate fix this?

@Auricmondal
Copy link
Author

Hey @akuzm, I'm not sure if the data can be called historical data, for I was adding data from after the present date and time each time. Moreover, the same settings were working fine the first time but not the second. Also, manually running refresh_continuous_aggregate does solve the issue for the newly added data until it is called, but again, if new data is inserted, the issue remains.

@fabriziomello
Copy link
Contributor

@Auricmondal after step 8 you should either:

You can also set the cagg realtime during it creating using the timescaledb.materialized_only=false in the definition. I.e.:

CREATE MATERIALIZED VIEW IF NOT EXISTS test2
      WITH (timescaledb.continuous, timescaledb.materialized_only=false) AS
SELECT
	a.id,
	time_bucket('100 years', a.timestamp) AS bucket,
    SUM(a.data) as Total_data,
	MAX(timestamp) as max_timestamp,
b.install_at
FROM my_table a
left join my_table2 b on a.id = b.id
GROUP BY a.id, bucket, b.install_at;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants