query_routing_setup.sql 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. DROP DATABASE IF EXISTS shard0;
  2. DROP DATABASE IF EXISTS shard1;
  3. DROP DATABASE IF EXISTS shard2;
  4. DROP DATABASE IF EXISTS some_db;
  5. CREATE DATABASE shard0;
  6. CREATE DATABASE shard1;
  7. CREATE DATABASE shard2;
  8. CREATE DATABASE some_db;
  9. \c shard0
  10. DROP TABLE IF EXISTS data CASCADE;
  11. CREATE TABLE data (
  12. id BIGINT,
  13. value VARCHAR
  14. ) PARTITION BY HASH (id);
  15. CREATE TABLE data_shard_0 PARTITION OF data FOR VALUES WITH (MODULUS 3, REMAINDER 0);
  16. \c shard1
  17. DROP TABLE IF EXISTS data CASCADE;
  18. CREATE TABLE data (
  19. id BIGINT,
  20. value VARCHAR
  21. ) PARTITION BY HASH (id);
  22. CREATE TABLE data_shard_1 PARTITION OF data FOR VALUES WITH (MODULUS 3, REMAINDER 1);
  23. \c shard2
  24. DROP TABLE IF EXISTS data CASCADE;
  25. CREATE TABLE data (
  26. id BIGINT,
  27. value VARCHAR
  28. ) PARTITION BY HASH (id);
  29. CREATE TABLE data_shard_2 PARTITION OF data FOR VALUES WITH (MODULUS 3, REMAINDER 2);
  30. \c some_db
  31. DROP TABLE IF EXISTS data CASCADE;
  32. CREATE TABLE data (
  33. id BIGINT,
  34. value VARCHAR
  35. );
  36. DROP ROLE IF EXISTS sharding_user;
  37. DROP ROLE IF EXISTS other_user;
  38. DROP ROLE IF EXISTS simple_user;
  39. CREATE ROLE sharding_user ENCRYPTED PASSWORD 'sharding_user' LOGIN;
  40. CREATE ROLE other_user ENCRYPTED PASSWORD 'other_user' LOGIN;
  41. CREATE ROLE simple_user ENCRYPTED PASSWORD 'simple_user' LOGIN;
  42. GRANT CONNECT ON DATABASE shard0 TO sharding_user;
  43. GRANT CONNECT ON DATABASE shard1 TO sharding_user;
  44. GRANT CONNECT ON DATABASE shard2 TO sharding_user;
  45. GRANT CONNECT ON DATABASE shard0 TO other_user;
  46. GRANT CONNECT ON DATABASE shard1 TO other_user;
  47. GRANT CONNECT ON DATABASE shard2 TO other_user;
  48. GRANT CONNECT ON DATABASE some_db TO simple_user;
  49. \c shard0
  50. CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
  51. GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO sharding_user;
  52. GRANT ALL ON SCHEMA public TO sharding_user;
  53. GRANT ALL ON TABLE data TO sharding_user;
  54. GRANT ALL ON SCHEMA public TO other_user;
  55. GRANT ALL ON TABLE data TO other_user;
  56. GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO other_user;
  57. \c shard1
  58. CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
  59. GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO sharding_user;
  60. GRANT ALL ON SCHEMA public TO sharding_user;
  61. GRANT ALL ON TABLE data TO sharding_user;
  62. GRANT ALL ON SCHEMA public TO other_user;
  63. GRANT ALL ON TABLE data TO other_user;
  64. GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO other_user;
  65. \c shard2
  66. CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
  67. GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO sharding_user;
  68. GRANT ALL ON SCHEMA public TO sharding_user;
  69. GRANT ALL ON TABLE data TO sharding_user;
  70. GRANT ALL ON SCHEMA public TO other_user;
  71. GRANT ALL ON TABLE data TO other_user;
  72. GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO other_user;
  73. \c some_db
  74. CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
  75. GRANT EXECUTE ON FUNCTION pg_stat_statements_reset TO simple_user;
  76. GRANT ALL ON SCHEMA public TO simple_user;
  77. GRANT ALL ON TABLE data TO simple_user;