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
Copy file name to clipboardExpand all lines: README.md
+34-16Lines changed: 34 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,20 +39,31 @@ python my_tests.py
39
39
40
40
### Logging
41
41
42
-
By default, `cleanup()` removes all temporary files (DB files, logs etc) that were created by testgres' API methods. If you'd like to keep logs, execute `configure_testgres(node_cleanup_full=False)` before running any tests.
42
+
By default, `cleanup()` removes all temporary files (DB files, logs etc) that were created by testgres' API methods.
43
+
If you'd like to keep logs, execute `configure_testgres(node_cleanup_full=False)` before running any tests.
with testgres.get_new_node('master', '/path/to/DB') as node:
82
93
```
83
94
84
-
where `master` is a node's name, not a DB's name. Name matters if you're testing something like replication. Function `get_new_node()` only creates directory structure in specified directory (or somewhere in '/tmp' if we did not specify base directory) for cluster. After that, we have to initialize the PostgreSQL cluster:
95
+
where `master` is a node's name, not a DB's name. Name matters if you're testing something like replication.
96
+
Function `get_new_node()` only creates directory structure in specified directory (or somewhere in '/tmp' if
97
+
we did not specify base directory) for cluster. After that, we have to initialize the PostgreSQL cluster:
85
98
86
99
```python
87
100
node.init()
88
101
```
89
102
90
-
This function runs `initdb` command and adds some basic configuration to `postgresql.conf` and `pg_hba.conf` files. Function `init()` accepts optional parameter `allows_streaming` which configures cluster for streaming replication (default is `False`).
103
+
This function runs `initdb` command and adds some basic configuration to `postgresql.conf` and `pg_hba.conf` files.
104
+
Function `init()` accepts optional parameter `allows_streaming` which configures cluster for streaming replication (default is `False`).
91
105
Now we are ready to start:
92
106
93
107
```python
@@ -126,29 +140,33 @@ It's quite easy to create a backup and start a new replica:
126
140
with testgres.get_new_node('master') as master:
127
141
master.init().start()
128
142
with master.backup() as backup:
143
+
# create and start a new replica
129
144
replica = backup.spawn_replica('replica').start()
130
-
replica.catchup() # catch up with master
145
+
146
+
# catch up with master node
147
+
replica.catchup()
148
+
149
+
# execute a dummy query
131
150
print(replica.execute('postgres', 'select 1'))
132
151
```
133
152
134
-
> Note: you could take a look at [`pg_pathman`](https://github.com/postgrespro/pg_pathman) to get an idea of `testgres`' capabilities.
135
-
136
153
### Benchmarks
137
154
138
155
`testgres` also can help you to make benchmarks using `pgbench` from postgres installation:
139
156
140
157
```python
141
158
with testgres.get_new_node('master') as master:
142
-
# start new node
159
+
# start a new node
143
160
master.init().start()
144
161
145
-
# initialize database for TPC-B
162
+
# initialize default database for TPC-B
146
163
master.pgbench_run(options=['-i'])
147
164
148
165
# run benchmark for 20 seconds and show results
149
166
print(master.pgbench_run(options=['-T', '20']))
150
167
```
151
168
169
+
152
170
## Authors
153
171
154
172
[Ildar Musin](https://github.com/zilder) <i.musin(at)postgrespro.ru> Postgres Professional Ltd., Russia
0 commit comments