You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the `examples` directory there is an executable with some examples.
93
+
94
+
```
95
+
cd examples
96
+
docker-compose up -d
97
+
```
98
+
99
+
then you can run the 3 examples. Please read the source code and it's comments.
100
+
101
+
```
102
+
go run main.go -cmd=basic
103
+
go run main.go -cmd=concurrency1
104
+
go run main.go -cmd=concurrency2
105
+
```
106
+
107
+
## Caution
108
+
109
+
PostgreSQL has by default disabled the `prepared_transactions`. There is a good reason for that.
110
+
You may even locked out of the database of permanently lock a table.
111
+
112
+
You need a mechanism that monitors that monitors any orphaned prepared transactions and takes action.
113
+
114
+
Please read the [documentation](https://www.postgresql.org/docs/current/sql-prepare-transaction.html)
115
+
and [this blog post](https://www.cybertec-postgresql.com/en/prepared-transactions/)
116
+
and [this blog post](https://www.highgo.ca/2020/01/28/understanding-prepared-transactions-and-handling-the-orphans/).
117
+
118
+
Don't be afraid but you should know with what you are dealing with.
119
+
120
+
In order to enable prepared transactions set in `postgresql.conf`
121
+
`max_prepared_transactions` to something larger that zero. Better to set it to the number of `max_connections`
122
+
123
+
Alternatevely, you can set it when you start the postgreSQL server by using the `-c` flag.
124
+
(see the docker-compose.yaml in the `examples` folder).
125
+
126
+
127
+
The library gives you some level of consistency BUT when the process that coordinates the distributed transactions crashes you may leave orphan prepared transactions or having data inconsistency since only some of the
128
+
participants may have finished the commits.
129
+
130
+
Additionally, if one participant manages to commit and the others don't (because of a disk failure for example) then again you may have data incosistency. I recommend to have some monitoring for these cases.
131
+
132
+
133
+
Consider if you actually need to phase commit or you can use maybe Sagas. Both patterns are useful, but
134
+
I believe that Sagas are more generic since in order to use the 2 Phase Commit Protocol all the
135
+
platforms need to implement the protocol. In any case distributed transactions are not trivial and you
136
+
should be careful.
137
+
138
+
88
139
## Contributing
89
140
Contributions to go-sql-2pc are always welcome. If you find a bug or want to suggest a new feature, please open an issue or submit a pull request.
0 commit comments