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]: ERROR: must be owner of table _hyper_4_7401_chunk when using different statistics target #4474

Closed
feikesteenbergen opened this issue Jun 27, 2022 · 1 comment · Fixed by #4538
Assignees
Labels

Comments

@feikesteenbergen
Copy link
Member

feikesteenbergen commented Jun 27, 2022

What type of bug is this?

Unexpected error

What subsystems and features are affected?

Data ingestion

What happened?

When inserting data into a hypertable, we received the following error:

ERROR:  must be owner of table _hyper_4_7401_chunk

NOTE: this is especially hard to troubleshoot, as this _hyper_4_7401_chunk will no longer exist, as the transaction that creates the chunk is rolled back. So the next error message will be about _hyper_4_7407_chunk (or the like), but none of these chunks can be found by querying the catalogs.

What is important to trigger this bug, is that the user that is inserting the data into the hypertable is not the owner of the chunk, but merely has INSERT privileges for example.

What causes this?

Issuing SET STATISTICS for a specific column on a table

What do we expect?

INSERT 0 8

What actually happened?

ERROR:  must be owner of table _hyper_1_3_chunk

Workaround

The workaround is to remove custom settings for SET STATISTICS for hypertables. This query can be used to generate such a list of statements:

select
    format('ALTER TABLE %s ALTER COLUMN %I SET STATISTICS -1',  attrelid::regclass, attname)
from
    timescaledb_information.hypertables
join
    pg_attribute ON (format('%I.%I', hypertable_schema, hypertable_name)::regclass=attrelid)
where
    attstattarget not in (0, -1);
ALTER TABLE bugtest ALTER COLUMN inserted SET STATISTICS -1

TimescaleDB version affected

2.7.0

PostgreSQL version used

14.4

What operating system did you use?

Ubuntu 22.04

What installation method did you use?

Docker

What platform did you run on?

Timescale Cloud

Relevant log output and stack trace

No response

How can we reproduce the bug?

CREATE ROLE bugowner;
CREATE ROLE buguser;

SET ROLE bugowner; -- The application "owner", the one owning the tables

CREATE TABLE public.bugtest (
    inserted timestamptz
);
GRANT SELECT on public.bugtest TO buguser;
GRANT INSERT on public.bugtest TO buguser;

SELECT public.create_hypertable (
    'public.bugtest',
    'inserted'
);

-- Insert some historical records, as an application user
-- This works fine: We still have the default statistics target
RESET ROLE;
SET ROLE buguser;
INSERT INTO
    public.bugtest
SELECT
    *
FROM
    generate_series(now() - interval '3 weeks', now() - interval '2 weeks', interval '1 day');

RESET ROLE;
SET ROLE bugowner;
ALTER TABLE
    public.bugtest
    ALTER COLUMN inserted
    SET statistics 10;

-- Insert some different records, as an application user
-- this fails with the mentioned error message
RESET ROLE;
SET ROLE buguser;
INSERT INTO
    public.bugtest
SELECT
    *
FROM
    generate_series(now() - interval '1 weeks', now(), interval '1 day');
@jnidzwetzki
Copy link
Contributor

Hello @feikesteenbergen,

Thank you very much for reporting this issue. I was able to reproduce the behavior with PostgreSQL 14 and TimescaleDB 2.7.0.

@svenklemm svenklemm self-assigned this Jul 21, 2022
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Jul 21, 2022
When triggering chunk creation on a hypertable with non-default
statistics targets by a user different from the hypertable owner
the chunk creation will fail with a permission error. This patch
changes the chunk table creation to run the attribute modification
as the table owner.

Fixes timescale#4474
svenklemm added a commit to svenklemm/timescaledb that referenced this issue Jul 22, 2022
When triggering chunk creation on a hypertable with non-default
statistics targets by a user different from the hypertable owner
the chunk creation will fail with a permission error. This patch
changes the chunk table creation to run the attribute modification
as the table owner.

Fixes timescale#4474
svenklemm added a commit that referenced this issue Jul 22, 2022
When triggering chunk creation on a hypertable with non-default
statistics targets by a user different from the hypertable owner
the chunk creation will fail with a permission error. This patch
changes the chunk table creation to run the attribute modification
as the table owner.

Fixes #4474
svenklemm added a commit that referenced this issue Jul 22, 2022
When triggering chunk creation on a hypertable with non-default
statistics targets by a user different from the hypertable owner
the chunk creation will fail with a permission error. This patch
changes the chunk table creation to run the attribute modification
as the table owner.

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

Successfully merging a pull request may close this issue.

3 participants