postgres_ry_seata.sql 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. --
  2. -- Licensed to the Apache Software Foundation (ASF) under one or more
  3. -- contributor license agreements. See the NOTICE file distributed with
  4. -- this work for additional information regarding copyright ownership.
  5. -- The ASF licenses this file to You under the Apache License, Version 2.0
  6. -- (the "License"); you may not use this file except in compliance with
  7. -- the License. You may obtain a copy of the License at
  8. --
  9. -- http://www.apache.org/licenses/LICENSE-2.0
  10. --
  11. -- Unless required by applicable law or agreed to in writing, software
  12. -- distributed under the License is distributed on an "AS IS" BASIS,
  13. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. -- See the License for the specific language governing permissions and
  15. -- limitations under the License.
  16. --
  17. -- -------------------------------- The script used when storeMode is 'db' --------------------------------
  18. -- the table to store GlobalSession data
  19. CREATE TABLE IF NOT EXISTS public.global_table
  20. (
  21. xid VARCHAR(128) NOT NULL,
  22. transaction_id BIGINT,
  23. status SMALLINT NOT NULL,
  24. application_id VARCHAR(32),
  25. transaction_service_group VARCHAR(32),
  26. transaction_name VARCHAR(128),
  27. timeout INT,
  28. begin_time BIGINT,
  29. application_data VARCHAR(2000),
  30. gmt_create TIMESTAMP(0),
  31. gmt_modified TIMESTAMP(0),
  32. CONSTRAINT pk_global_table PRIMARY KEY (xid)
  33. );
  34. CREATE INDEX idx_global_table_status_gmt_modified ON public.global_table (status, gmt_modified);
  35. CREATE INDEX idx_global_table_transaction_id ON public.global_table (transaction_id);
  36. -- the table to store BranchSession data
  37. CREATE TABLE IF NOT EXISTS public.branch_table
  38. (
  39. branch_id BIGINT NOT NULL,
  40. xid VARCHAR(128) NOT NULL,
  41. transaction_id BIGINT,
  42. resource_group_id VARCHAR(32),
  43. resource_id VARCHAR(256),
  44. branch_type VARCHAR(8),
  45. status SMALLINT,
  46. client_id VARCHAR(64),
  47. application_data VARCHAR(2000),
  48. gmt_create TIMESTAMP(6),
  49. gmt_modified TIMESTAMP(6),
  50. CONSTRAINT pk_branch_table PRIMARY KEY (branch_id)
  51. );
  52. CREATE INDEX idx_branch_table_xid ON public.branch_table (xid);
  53. -- the table to store lock data
  54. CREATE TABLE IF NOT EXISTS public.lock_table
  55. (
  56. row_key VARCHAR(128) NOT NULL,
  57. xid VARCHAR(128),
  58. transaction_id BIGINT,
  59. branch_id BIGINT NOT NULL,
  60. resource_id VARCHAR(256),
  61. table_name VARCHAR(32),
  62. pk VARCHAR(36),
  63. status SMALLINT NOT NULL DEFAULT 0,
  64. gmt_create TIMESTAMP(0),
  65. gmt_modified TIMESTAMP(0),
  66. CONSTRAINT pk_lock_table PRIMARY KEY (row_key)
  67. );
  68. comment on column public.lock_table.status is '0:locked ,1:rollbacking';
  69. CREATE INDEX idx_lock_table_branch_id ON public.lock_table (branch_id);
  70. CREATE INDEX idx_lock_table_xid ON public.lock_table (xid);
  71. CREATE INDEX idx_lock_table_status ON public.lock_table (status);
  72. CREATE TABLE distributed_lock (
  73. lock_key VARCHAR(20) NOT NULL,
  74. lock_value VARCHAR(20) NOT NULL,
  75. expire BIGINT NOT NULL,
  76. CONSTRAINT pk_distributed_lock_table PRIMARY KEY (lock_key)
  77. );
  78. INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
  79. INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
  80. INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
  81. INSERT INTO distributed_lock (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);
  82. CREATE TABLE IF NOT EXISTS vgroup_table
  83. (
  84. vGroup VARCHAR(255),
  85. namespace VARCHAR(255),
  86. cluster VARCHAR(255),
  87. PRIMARY KEY (vGroup)
  88. );