Initialize cluster.
(self, **settings)
| 648 | self._pg_basebackup = self._find_pg_binary('pg_basebackup') |
| 649 | |
| 650 | def init(self, **settings): |
| 651 | """Initialize cluster.""" |
| 652 | if self.get_status() != 'not-initialized': |
| 653 | raise ClusterError( |
| 654 | 'cluster in {!r} has already been initialized'.format( |
| 655 | self._data_dir)) |
| 656 | |
| 657 | process = subprocess.run( |
| 658 | [self._pg_basebackup, '-h', self._master['host'], |
| 659 | '-p', self._master['port'], '-D', self._data_dir, |
| 660 | '-U', self._repl_user], |
| 661 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 662 | |
| 663 | output = process.stdout |
| 664 | |
| 665 | if process.returncode != 0: |
| 666 | raise ClusterError( |
| 667 | 'pg_basebackup init exited with status {:d}:\n{}'.format( |
| 668 | process.returncode, output.decode())) |
| 669 | |
| 670 | if self._pg_version < (12, 0): |
| 671 | with open(os.path.join(self._data_dir, 'recovery.conf'), 'w') as f: |
| 672 | f.write(textwrap.dedent("""\ |
| 673 | standby_mode = 'on' |
| 674 | primary_conninfo = 'host={host} port={port} user={user}' |
| 675 | """.format( |
| 676 | host=self._master['host'], |
| 677 | port=self._master['port'], |
| 678 | user=self._repl_user))) |
| 679 | else: |
| 680 | f = open(os.path.join(self._data_dir, 'standby.signal'), 'w') |
| 681 | f.close() |
| 682 | |
| 683 | return output.decode() |
| 684 | |
| 685 | def start(self, wait=60, *, server_settings={}, **opts): |
| 686 | if self._pg_version >= (12, 0): |
nothing calls this directly
no test coverage detected