query_routing_test_primary_replica.sql 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. \set ON_ERROR_STOP on
  2. SET SERVER ROLE TO 'primary';
  3. SET SHARDING KEY TO '1';
  4. INSERT INTO data (id, value) VALUES (1, 'value_1');
  5. SET SERVER ROLE TO 'replica';
  6. SET SHARDING KEY TO '1';
  7. SELECT * FROM data WHERE id = 1;
  8. ---
  9. SET SERVER ROLE TO 'primary';
  10. SET SHARDING KEY TO '2';
  11. INSERT INTO data (id, value) VALUES (2, 'value_1');
  12. SET SERVER ROLE TO 'replica';
  13. SET SHARDING KEY TO '2';
  14. SELECT * FROM data WHERE id = 2;
  15. ---
  16. SET SERVER ROLE TO 'primary';
  17. SET SHARDING KEY TO '3';
  18. INSERT INTO data (id, value) VALUES (3, 'value_1');
  19. SET SERVER ROLE TO 'replica';
  20. SET SHARDING KEY TO '3';
  21. SELECT * FROM data WHERE id = 3;
  22. ---
  23. SET SERVER ROLE TO 'primary';
  24. SET SHARDING KEY TO '4';
  25. INSERT INTO data (id, value) VALUES (4, 'value_1');
  26. SET SERVER ROLE TO 'replica';
  27. SET SHARDING KEY TO '4';
  28. SELECT * FROM data WHERE id = 4;
  29. ---
  30. SET SERVER ROLE TO 'primary';
  31. SET SHARDING KEY TO '5';
  32. INSERT INTO data (id, value) VALUES (5, 'value_1');
  33. SET SERVER ROLE TO 'replica';
  34. SET SHARDING KEY TO '5';
  35. SELECT * FROM data WHERE id = 5;
  36. ---
  37. SET SERVER ROLE TO 'primary';
  38. SET SHARDING KEY TO '6';
  39. INSERT INTO data (id, value) VALUES (6, 'value_1');
  40. SET SERVER ROLE TO 'replica';
  41. SET SHARDING KEY TO '6';
  42. SELECT * FROM data WHERE id = 6;
  43. ---
  44. SET SERVER ROLE TO 'primary';
  45. SET SHARDING KEY TO '7';
  46. INSERT INTO data (id, value) VALUES (7, 'value_1');
  47. SET SERVER ROLE TO 'replica';
  48. SET SHARDING KEY TO '7';
  49. SELECT * FROM data WHERE id = 7;
  50. ---
  51. SET SERVER ROLE TO 'primary';
  52. SET SHARDING KEY TO '8';
  53. INSERT INTO data (id, value) VALUES (8, 'value_1');
  54. SET SERVER ROLE TO 'replica';
  55. SET SHARDING KEY TO '8';
  56. SELECT * FROM data WHERE id = 8;
  57. ---
  58. SET SERVER ROLE TO 'primary';
  59. SET SHARDING KEY TO '9';
  60. INSERT INTO data (id, value) VALUES (9, 'value_1');
  61. SET SERVER ROLE TO 'replica';
  62. SET SHARDING KEY TO '9';
  63. SELECT * FROM data WHERE id = 9;
  64. ---
  65. \set ON_ERROR_STOP on
  66. SET SERVER ROLE TO 'primary';
  67. SET SHARDING KEY TO '10';
  68. INSERT INTO data (id, value) VALUES (10, 'value_1');
  69. SET SERVER ROLE TO 'replica';
  70. SET SHARDING KEY TO '10';
  71. SELECT * FROM data WHERE id = 10;
  72. ---
  73. SET SERVER ROLE TO 'primary';
  74. SET SHARDING KEY TO '11';
  75. INSERT INTO data (id, value) VALUES (11, 'value_1');
  76. SET SERVER ROLE TO 'replica';
  77. SET SHARDING KEY TO '11';
  78. SELECT * FROM data WHERE id = 11;
  79. ---
  80. SET SERVER ROLE TO 'primary';
  81. SET SHARDING KEY TO '12';
  82. INSERT INTO data (id, value) VALUES (12, 'value_1');
  83. SET SERVER ROLE TO 'replica';
  84. SET SHARDING KEY TO '12';
  85. SELECT * FROM data WHERE id = 12;
  86. ---
  87. SET SERVER ROLE TO 'primary';
  88. SET SHARDING KEY TO '13';
  89. INSERT INTO data (id, value) VALUES (13, 'value_1');
  90. SET SERVER ROLE TO 'replica';
  91. SET SHARDING KEY TO '13';
  92. SELECT * FROM data WHERE id = 13;
  93. ---
  94. SET SERVER ROLE TO 'primary';
  95. SET SHARDING KEY TO '14';
  96. INSERT INTO data (id, value) VALUES (14, 'value_1');
  97. SET SERVER ROLE TO 'replica';
  98. SET SHARDING KEY TO '14';
  99. SELECT * FROM data WHERE id = 14;
  100. ---
  101. SET SERVER ROLE TO 'primary';
  102. SELECT 1;
  103. SET SERVER ROLE TO 'replica';
  104. SELECT 1;
  105. set server role to 'replica';
  106. SeT SeRver Role TO 'PrImARY';
  107. select 1;
  108. SET PRIMARY READS TO 'on';
  109. SELECT 1;
  110. SET PRIMARY READS TO 'off';
  111. SELECT 1;
  112. SET PRIMARY READS TO 'default';
  113. SELECT 1;