/usr/share/postgresql/10/extension/citus--7.0-2--7.0-3.sql is in postgresql-10-citus 7.0.3.PGDG-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | /* citus--7.0-2--7.0-3.sql */
ALTER SEQUENCE pg_catalog.pg_dist_shard_placement_placementid_seq
RENAME TO pg_dist_placement_placementid_seq;
ALTER TABLE pg_catalog.pg_dist_shard_placement
ALTER COLUMN placementid SET DEFAULT nextval('pg_catalog.pg_dist_placement_placementid_seq');
CREATE TABLE citus.pg_dist_placement (
placementid BIGINT NOT NULL default nextval('pg_dist_placement_placementid_seq'::regclass),
shardid BIGINT NOT NULL,
shardstate INT NOT NULL,
shardlength BIGINT NOT NULL,
groupid INT NOT NULL
);
ALTER TABLE citus.pg_dist_placement SET SCHEMA pg_catalog;
GRANT SELECT ON pg_catalog.pg_dist_placement TO public;
CREATE INDEX pg_dist_placement_groupid_index
ON pg_dist_placement USING btree(groupid);
CREATE INDEX pg_dist_placement_shardid_index
ON pg_dist_placement USING btree(shardid);
CREATE UNIQUE INDEX pg_dist_placement_placementid_index
ON pg_dist_placement USING btree(placementid);
CREATE OR REPLACE FUNCTION citus.find_groupid_for_node(text, int)
RETURNS int AS $$
DECLARE
groupid int := (SELECT groupid FROM pg_dist_node WHERE nodename = $1 AND nodeport = $2);
BEGIN
IF groupid IS NULL THEN
RAISE EXCEPTION 'There is no node at "%:%"', $1, $2;
ELSE
RETURN groupid;
END IF;
END;
$$ LANGUAGE plpgsql;
INSERT INTO pg_catalog.pg_dist_placement
SELECT placementid, shardid, shardstate, shardlength,
citus.find_groupid_for_node(placement.nodename, placement.nodeport::int) AS groupid
FROM pg_dist_shard_placement placement;
DROP TRIGGER dist_placement_cache_invalidate ON pg_catalog.pg_dist_shard_placement;
CREATE TRIGGER dist_placement_cache_invalidate
AFTER INSERT OR UPDATE OR DELETE
ON pg_catalog.pg_dist_placement
FOR EACH ROW EXECUTE PROCEDURE master_dist_placement_cache_invalidate();
-- this should be removed when noderole is added but for now it ensures the below view
-- returns the correct results and that placements unambiguously belong to a view
ALTER TABLE pg_catalog.pg_dist_node ADD CONSTRAINT pg_dist_node_groupid_unique
UNIQUE (groupid);
DROP TABLE pg_dist_shard_placement;
CREATE VIEW citus.pg_dist_shard_placement AS
SELECT shardid, shardstate, shardlength, nodename, nodeport, placementid
-- assumes there's only one node per group
FROM pg_dist_placement placement INNER JOIN pg_dist_node node ON (
placement.groupid = node.groupid
);
ALTER VIEW citus.pg_dist_shard_placement SET SCHEMA pg_catalog;
GRANT SELECT ON pg_catalog.pg_dist_shard_placement TO public;
-- add some triggers which make it look like pg_dist_shard_placement is still a table
ALTER VIEW pg_catalog.pg_dist_shard_placement
ALTER placementid SET DEFAULT nextval('pg_dist_placement_placementid_seq');
CREATE OR REPLACE FUNCTION citus.pg_dist_shard_placement_trigger_func()
RETURNS TRIGGER AS $$
BEGIN
IF (TG_OP = 'DELETE') THEN
DELETE FROM pg_dist_placement WHERE placementid = OLD.placementid;
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
UPDATE pg_dist_placement
SET shardid = NEW.shardid, shardstate = NEW.shardstate,
shardlength = NEW.shardlength, placementid = NEW.placementid,
groupid = citus.find_groupid_for_node(NEW.nodename, NEW.nodeport)
WHERE placementid = OLD.placementid;
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO pg_dist_placement
(placementid, shardid, shardstate, shardlength, groupid)
VALUES (NEW.placementid, NEW.shardid, NEW.shardstate, NEW.shardlength,
citus.find_groupid_for_node(NEW.nodename, NEW.nodeport));
RETURN NEW;
END IF;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER pg_dist_shard_placement_trigger
INSTEAD OF INSERT OR UPDATE OR DELETE ON pg_dist_shard_placement
FOR EACH ROW EXECUTE PROCEDURE citus.pg_dist_shard_placement_trigger_func();
|