-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump default version; add upgrade script
Adding a new UDF means adding an upgrade script to augment existing installations of pg_shard.
- Loading branch information
Showing
4 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
CREATE FUNCTION partition_column_to_node_string(table_oid oid) | ||
RETURNS text | ||
AS 'MODULE_PATHNAME' | ||
LANGUAGE C; | ||
|
||
COMMENT ON FUNCTION partition_column_to_node_string(oid) | ||
IS 'return textual form of distributed table''s partition column'; | ||
|
||
CREATE FUNCTION sync_table_metadata_to_citus(table_name text) RETURNS VOID | ||
AS $sync_table_metadata_to_citus$ | ||
DECLARE | ||
table_relation_id CONSTANT oid NOT NULL := table_name::regclass::oid; | ||
dummy_shard_length CONSTANT bigint := 0; | ||
BEGIN | ||
-- copy shard placement metadata | ||
INSERT INTO pg_dist_shard_placement | ||
(shardid, | ||
shardstate, | ||
shardlength, | ||
nodename, | ||
nodeport) | ||
SELECT shard_id, | ||
shard_state, | ||
dummy_shard_length, | ||
node_name, | ||
node_port | ||
FROM pgs_distribution_metadata.shard_placement | ||
WHERE shard_id IN (SELECT id | ||
FROM pgs_distribution_metadata.shard | ||
WHERE relation_id = table_relation_id); | ||
|
||
-- copy shard metadata | ||
INSERT INTO pg_dist_shard | ||
(shardid, | ||
logicalrelid, | ||
shardstorage, | ||
shardminvalue, | ||
shardmaxvalue) | ||
SELECT id, | ||
relation_id, | ||
storage, | ||
min_value, | ||
max_value | ||
FROM pgs_distribution_metadata.shard | ||
WHERE relation_id = table_relation_id; | ||
|
||
-- copy partition metadata, which also converts the partition column to | ||
-- a node string representation as expected by CitusDB | ||
INSERT INTO pg_dist_partition | ||
(logicalrelid, | ||
partmethod, | ||
partkey) | ||
SELECT relation_id, | ||
partition_method, | ||
partition_column_to_node_string(table_relation_id) | ||
FROM pgs_distribution_metadata.partition | ||
WHERE relation_id = table_relation_id; | ||
END; | ||
$sync_table_metadata_to_citus$ LANGUAGE 'plpgsql'; | ||
|
||
COMMENT ON FUNCTION sync_table_metadata_to_citus(text) | ||
IS 'synchronize a distributed table''s pg_shard metadata to CitusDB'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# pg_shard extension | ||
comment = 'extension for sharding across remote PostgreSQL servers' | ||
default_version = '1.0' | ||
default_version = '1.1' | ||
module_pathname = '$libdir/pg_shard' | ||
relocatable = true |