Files
documentdb/pg_helio_api/sql/schema/background_index_queue--1.14-0.sql
T
Tanvi Bhandari 8d461c2b27 Merged PR 1271218: CurrentOp showing the progress for Index Build in background
### Does this PR have any customer impact?
No

### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature

### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes)
Yes

### Release Note (Refer [Template](../docs/release_notes/pgmongo_template.md))

### Description
Issue:
Since the owner of scheduled cron job for index build background is admin user i.e. 'postgres' in prod, the CREATE INDEX CONCURRETLY queries are owned by 'postgres' user in pg_stat_activity.
And non-admin user who requests for currentOp to get progress of running indexes, does not have enough privilege to read queries owned by admin user in pg_stat_activity.

Solutions:
From inside running cron-job, create LibPQ connection as the non-admin user for CREATE INDEX CONCURRENTLY. The pre-requisite for this approach is that we have the information of user-oid who has submitted the request in queue. I.e. This needs user_name column in index_queue table.

Related work items: #2961369
2024-03-01 17:24:28 +03:00

22 lines
1.0 KiB
SQL

DROP TABLE IF EXISTS helio_api_catalog.helio_index_queue;
CREATE TABLE helio_api_catalog.helio_index_queue
(
index_cmd text not null,
cmd_type char CHECK (cmd_type IN ('C', 'R')), -- 'C' for CREATE INDEX and 'R' for REINDEX
index_id integer not null,
index_cmd_status integer default 1, -- This gets represented as enum IndexCmdStatus in index.h
global_pid bigint,
start_time timestamp WITH TIME ZONE,
collection_id bigint not null,
comment __CORE_SCHEMA__.bson,
attempt smallint,
update_time timestamp with time zone DEFAULT now(),
user_oid Oid CHECK (user_oid IS NULL OR user_oid != '0'::oid)
);
CREATE INDEX IF NOT EXISTS helio_index_queue_indexid_cmdtype on helio_api_catalog.helio_index_queue (index_id, cmd_type);
CREATE INDEX IF NOT EXISTS helio_index_queue_cmdtype_collectionid_cmdstatus on helio_api_catalog.helio_index_queue (cmd_type, collection_id, index_cmd_status);
GRANT SELECT ON TABLE helio_api_catalog.helio_index_queue TO public;
GRANT ALL ON TABLE helio_api_catalog.helio_index_queue TO helio_admin_role;