|
7 | 7 | edit configuration files, start/stop cluster, execute queries. The
|
8 | 8 | typical flow may look like:
|
9 | 9 |
|
10 |
| - with get_new_node() as node: |
11 |
| - node.init() |
12 |
| - node.start() |
13 |
| - result = node.psql('postgres', 'SELECT 1') |
14 |
| - print(result) |
15 |
| - node.stop() |
| 10 | +>>> with get_new_node() as node: |
| 11 | +... node.init().start() |
| 12 | +... result = node.safe_psql('postgres', 'select 1') |
| 13 | +... print(result.decode('utf-8').strip()) |
| 14 | +... node.stop() |
| 15 | +<testgres.node.PostgresNode object at 0x...> |
| 16 | +1 |
| 17 | +<testgres.node.PostgresNode object at 0x...> |
16 | 18 |
|
17 | 19 | Or:
|
18 | 20 |
|
19 |
| - with get_new_node() as node1: |
20 |
| - node1.init().start() |
21 |
| - with node1.backup() as backup: |
22 |
| - with backup.spawn_primary() as node2: |
23 |
| - res = node2.start().execute('postgres', 'select 2') |
24 |
| - print(res) |
| 21 | +>>> with get_new_node() as master: |
| 22 | +... master.init().start() |
| 23 | +... with master.backup() as backup: |
| 24 | +... with backup.spawn_replica() as replica: |
| 25 | +... replica = replica.start() |
| 26 | +... master.execute('postgres', 'create table test (val int4)') |
| 27 | +... master.execute('postgres', 'insert into test values (0), (1), (2)') |
| 28 | +... replica.catchup() # wait until changes are visible |
| 29 | +... print(replica.execute('postgres', 'select count(*) from test')) |
| 30 | +<testgres.node.PostgresNode object at 0x...> |
| 31 | +[(3,)] |
25 | 32 |
|
26 | 33 | Copyright (c) 2016, Postgres Professional
|
27 | 34 | """
|
|
0 commit comments