| 329 | self._connection_spec_override = kwargs |
| 330 | |
| 331 | def reset_wal(self, *, oid=None, xid=None): |
| 332 | status = self.get_status() |
| 333 | if status == 'not-initialized': |
| 334 | raise ClusterError( |
| 335 | 'cannot modify WAL status: cluster is not initialized') |
| 336 | |
| 337 | if status == 'running': |
| 338 | raise ClusterError( |
| 339 | 'cannot modify WAL status: cluster is running') |
| 340 | |
| 341 | opts = [] |
| 342 | if oid is not None: |
| 343 | opts.extend(['-o', str(oid)]) |
| 344 | if xid is not None: |
| 345 | opts.extend(['-x', str(xid)]) |
| 346 | if not opts: |
| 347 | return |
| 348 | |
| 349 | opts.append(self._data_dir) |
| 350 | |
| 351 | try: |
| 352 | reset_wal = self._find_pg_binary('pg_resetwal') |
| 353 | except ClusterError: |
| 354 | reset_wal = self._find_pg_binary('pg_resetxlog') |
| 355 | |
| 356 | process = subprocess.run( |
| 357 | [reset_wal] + opts, |
| 358 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 359 | |
| 360 | stderr = process.stderr |
| 361 | |
| 362 | if process.returncode != 0: |
| 363 | raise ClusterError( |
| 364 | 'pg_resetwal exited with status {:d}: {}'.format( |
| 365 | process.returncode, stderr.decode())) |
| 366 | |
| 367 | def reset_hba(self): |
| 368 | """Remove all records from pg_hba.conf.""" |