canonical / canonical/postgresql-operator

Unable to run TimescaleDB retention and aggregation policies, when the timescaleDB extension is enabled.

Open
#1,737 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
Python
Stars
20
Forks
36
Avg merge
4d 15h
Merged PRs (30d)
30

Description

## Steps to reproduce

1. Deploy postgresql from the `16/stable` channel in a VM model.
2. Once postgresql has been deployed, enable the timescaledb plugin with `juju config postgresql plugin-timescaledb-enable=true`
3. Deploy the `data-integrator` charm using `juju deploy data-integrator --config database-name=test-db`
4. Integrate the charms using `juju integrate data-integrator postgresql`. This will create a new username, password and database for the relation.
5. Obtain DB credentials using `juju run data-integrator/leader get-credentials` and ssh into the postgres unit.
6. Login to postgres using `psql `. This will log you in to the `test-db` that was created for the relation.
7. Running `\du;` shows that the `charmed_test-db_owner` role has the `Cannot login` message in role attributes.
8. Run `SET ROLE "charmed_test-db_owner";` as the owner role is normally used to run schema-migrations and queries.
9. Create a temporary table and hypertable
```
--- 1. Create a test table
CREATE TABLE demo_metrics (
time TIMESTAMPTZ NOT NULL,
temperature DOUBLE PRECISION
);

-- 2. Convert it into a TimescaleDB hypertable
SELECT create_hypertable('demo_metrics', 'time');
```
10. Add a TimescaleDB retention policy on the hypertable: `SELECT add_retention_policy('demo_metrics', INTERVAL '30 days');`.
This is a background process that will delete old data from the hypertable.

11. Trying to add a retention policy will result in
```
ERROR: permission denied to start background process as role "charmed_test-db_owner"
HINT: Hypertable owner must have LOGIN permission to run background tasks.
```

This means that the default user and role that will be created for a relation, will never be able to run queries or schema migrations that set up background processes for TimescaleDB.

## Expected behavior

When the TimescaleDB extension is enabled, the relation user must have permissions to login, thereby enabling it to set up TimescaleDB background processes, such as, retention and aggregation policies.

## Actual behavior

Because the default user and role created for a relation does not have any login privileges, any attempts to create TimescaleDB retention or aggregation policies, will result in an error.

Image

Image

## Versions

Operating system: Ubuntu 22.04.5

Juju CLI: 3.6.23-genericlinux-amd64

Juju agent: 3.6.23

Charm revision: 1089

LXD: 5.0.6

## Log output

Juju debug log:

[log.txt](https://github.com/user-attachments/files/28495493/log.txt)

## Additional context

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the PostgreSQL 16/stable deployment with plugin-timescaledb-enable=true, then follow the data-integrator integration and get-credentials flow to inspect how the relation user and owner role are created. Done means the relation user can log in and successfully create TimescaleDB retention or aggregation policies after SET ROLE.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.