Skip to content

Commit 45334b9

Browse files
committed
README update
1 parent a2ec174 commit 45334b9

File tree

1 file changed

+96
-31
lines changed

1 file changed

+96
-31
lines changed

README.md

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,113 @@
1-
0) Design
1+
# pg_dtm
22

3-
General concept oberview. wiki link. This repo implements Snapshot Sharing mechnism.
4-
Protocol description. README.protocol
5-
Presentation
3+
### Design
64

7-
1) Installing
5+
This repo implements distributed transaction manager using Snapshot Sharing mechanism. General concepts and alternative approaches described in postgres wiki https://wiki.postgresql.org/wiki/DTM.
86

9-
* patch postgres
10-
* install extension
11-
* configure two postgreses
12-
* run dtmd
13-
* run postgreses
7+
Backend-DTM protocol description can be found in [dtmd/README](dtmd/README).
148

15-
1b) Automatic provisioning
9+
### Installation
1610

17-
* For a wide deploy we use ansible. Layouts/Farms. More details later.
18-
19-
2) Usage
11+
* Patch postgres using xtm.patch. After that build and install postgres in usual way.
12+
```bash
13+
cd ~/code/postgres
14+
patch -p1 < ~/code/pg_dtm/xtm.patch
15+
```
16+
* Install pg_dtm extension.
17+
```bash
18+
export PATH=/path/to/pgsql/bin/:$PATH
19+
cd ~/code/pg_dtm
20+
make && make install
21+
```
22+
* Run dtmd.
23+
```bash
24+
cd ~/code/pg_dtm/dtmd
25+
make
26+
./bin/dtmd &
27+
```
28+
* To run something meaningful you need at leat two postgres instances. Also pg_dtm requires
29+
```bash
30+
initdb -D ./install/data1
31+
initdb -D ./install/data2
32+
echo "port = 5433" >> ./install/data2/postgresql.conf
33+
echo "shared_preload_libraries = 'pg_dtm'" >> ./install/data1/postgresql.conf
34+
echo "shared_preload_libraries = 'pg_dtm'" >> ./install/data2/postgresql.conf
35+
pg_ctl -D ./install/data1 -l ./install/data1/log start
36+
pg_ctl -D ./install/data2 -l ./install/data2/log start
37+
```
2038

21-
now you can use global tx between this two nodes
39+
#### Automatic provisioning
2240

23-
table with two columns
24-
```sql
25-
example
26-
```
41+
For a cluster-wide deploy we use ansible, more details in tests/deploy_layouts. (Ansible instructions will be later)
2742

28-
3) Consistency testing
43+
### Usage
2944

30-
To ensure consistency we use simple bank test: perform a lot of simultaneous transfers between accounts on different servers, while constantly checking total amount of money on all accounts.
45+
Now cluster is running and you can use global tx between two nodes.
3146

32-
go run ...
3347

34-
also there is the test for measuring select performance.
48+
```sql
49+
create extension pg_dtm; -- node1
50+
create extension pg_dtm; -- node2
51+
select dtm_begin_transaction(); -- node1, returns global xid, e.g. 42
52+
select dtm_join_transaction(42); -- node2, join global tx
53+
begin; -- node1
54+
begin; -- node2
55+
update accounts set amount=amount-100 where user_id=1; -- node1, transfer money from user#1
56+
update accounts set amount=amount+100 where user_id=2; -- node2, to user#2
57+
commit; -- node1
58+
commit; -- node2
59+
```
3560

36-
4) Using with fdw.
61+
### Consistency testing
62+
63+
To ensure consistency we use simple bank test: perform a lot of simultaneous transfers between accounts on different servers, while constantly checking total amount of money on all accounts. This test can be found in tests/perf.
64+
65+
```bash
66+
> go run ./perf/*
67+
-C value
68+
Connection string (repeat for multiple connections)
69+
-a int
70+
The number of bank accounts (default 100000)
71+
-b string
72+
Backend to use. Possible optinos: transfers, fdw, pgshard, readers. (default "transfers")
73+
-g Use DTM to keep global consistency
74+
-i Init database
75+
-l Use 'repeatable read' isolation level instead of 'read committed'
76+
-n int
77+
The number updates each writer (reader in case of Reades backend) performs (default 10000)
78+
-p Use parallel execs
79+
-r int
80+
The number of readers (default 1)
81+
-s int
82+
StartID. Script will update rows starting from this value
83+
-v Show progress and other stuff for mortals
84+
-w int
85+
The number of writers (default 8)
86+
```
3787
38-
patch
39-
go run ...
88+
So previous installation can be initialized with:
89+
```
90+
go run ./perf/*.go \
91+
-C "dbname=postgres port=5432" \
92+
-C "dbname=postgres port=5433" \
93+
-g -i
94+
```
95+
and tested with:
96+
```
97+
go run ./perf/*.go \
98+
-C "dbname=postgres port=5432" \
99+
-C "dbname=postgres port=5433" \
100+
-g
101+
```
40102
41-
5) Using with pg_shard
103+
### Using with postres_fdw.
42104
43-
checkout repo
44-
go run ...
105+
We also provide a patch, that enables support of global transactions with postres_fdw. After patching and installing postres_fdw it is possible to run same test via fdw usig key ```-b fdw```.
45106
46-
6) Results
107+
### Using with pg_shard
47108
48-
Some graphs
109+
Citus Data have branch in their pg_shard repo, that interacts with transaction manager. https://github.com/citusdata/pg_shard/tree/transaction_manager_integration
110+
To use this feature one should have following line in postgresql.conf (or set it via GUC)
111+
```
112+
pg_shard.use_dtm_transactions = 1
113+
```

0 commit comments

Comments
 (0)