|
| 1 | +# testgres - pg_probackup2 |
| 2 | + |
| 3 | +Ccontrol and testing utility for [pg_probackup2](https://github.com/postgrespro/pg_probackup). Python 3.5+ is supported. |
| 4 | + |
| 5 | + |
| 6 | +## Installation |
| 7 | + |
| 8 | +To install `testgres`, run: |
| 9 | + |
| 10 | +``` |
| 11 | +pip install testgres-pg_probackup |
| 12 | +``` |
| 13 | + |
| 14 | +We encourage you to use `virtualenv` for your testing environment. |
| 15 | +The package requires testgres~=1.9.3. |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +### Environment |
| 20 | + |
| 21 | +> Note: by default testgres runs `initdb`, `pg_ctl`, `psql` provided by `PATH`. |
| 22 | +
|
| 23 | +There are several ways to specify a custom postgres installation: |
| 24 | + |
| 25 | +* export `PG_CONFIG` environment variable pointing to the `pg_config` executable; |
| 26 | +* export `PG_BIN` environment variable pointing to the directory with executable files. |
| 27 | + |
| 28 | +Example: |
| 29 | + |
| 30 | +```bash |
| 31 | +export PG_BIN=$HOME/pg/bin |
| 32 | +python my_tests.py |
| 33 | +``` |
| 34 | + |
| 35 | + |
| 36 | +### Examples |
| 37 | + |
| 38 | +Here is an example of what you can do with `testgres-pg_probackup2`: |
| 39 | + |
| 40 | +```python |
| 41 | +# You can see full script here plugins/pg_probackup2/pg_probackup2/tests/basic_test.py |
| 42 | +def test_full_backup(self): |
| 43 | + # Setting up a simple test node |
| 44 | + node = self.pg_node.make_simple('node', pg_options={"fsync": "off", "synchronous_commit": "off"}) |
| 45 | + |
| 46 | + # Initialize and configure Probackup |
| 47 | + self.pb.init() |
| 48 | + self.pb.add_instance('node', node) |
| 49 | + self.pb.set_archiving('node', node) |
| 50 | + |
| 51 | + # Start the node and initialize pgbench |
| 52 | + node.slow_start() |
| 53 | + node.pgbench_init(scale=100, no_vacuum=True) |
| 54 | + |
| 55 | + # Perform backup and validation |
| 56 | + backup_id = self.pb.backup_node('node', node) |
| 57 | + out = self.pb.validate('node', backup_id) |
| 58 | + |
| 59 | + # Check if the backup is valid |
| 60 | + self.assertIn(f"INFO: Backup {backup_id} is valid", out) |
| 61 | +``` |
| 62 | + |
| 63 | +## Authors |
| 64 | + |
| 65 | +[Postgres Professional](https://postgrespro.ru/about) |
0 commit comments