Last active
September 24, 2016 00:49
-
-
Save saicitus/ecf8fe2122b02eb384b5a41f84fef615 to your computer and use it in GitHub Desktop.
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
#Table and Schema Creation. | |
CREATE TABLE data_rows(company_id integer,id integer, data text); | |
ALTER TABLE dATA_ROWS ADD COLUMN tsv tsvector; | |
select master_create_distributed_table('data_rows','company_id','hash'); | |
select master_create_worker_shards('data_rows',16,1); | |
#Create a file called trigger_procedure.sql with this function(the function may change as per your specification, this is just a sample) | |
CREATE FUNCTION documents_search_trigger() RETURNS trigger AS $$ begin | |
new.tsv := | |
setweight(to_tsvector(coalesce(new.data,'')), 'D'); | |
return new; | |
end | |
$$ LANGUAGE plpgsql; | |
#Create the following above function on the workers | |
#<password_string> is found between the symbols : and @ in the master url which you get. | |
psql -tA -F" " <conn_string_master> -c "SELECT node_name,node_port from master_get_active_worker_nodes();" | | |
xargs -n 2 -P 4 sh -c "psql postgres://citus:<password_string>@\$0:\$1/citus?sslmode=require -f trigger_procedure.sql" | |
#Create triggers on the worker shards | |
psql -tA -F" " <conn_string_master> -c "SELECT logicalrelid::regclass||'_'||s.shardid, \ | |
nodename, nodeport FROM pg_dist_shard s JOIN pg_dist_shard_placement p ON (s.shardid = p.shardid) \ | |
WHERE logicalrelid::regclass = 'data_rows'::regclass;" |xargs -n 3 -P 4 sh -c "psql postgres://citus:<password_string>@\$1:\$2/citus?sslmode=require -c \"CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON \$0 FOR EACH ROW EXECUTE PROCEDURE documents_search_trigger();\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment