Initialize cluster.
(self, **settings)
| 130 | return await asyncpg.connect(loop=loop, **conn_info) |
| 131 | |
| 132 | def init(self, **settings): |
| 133 | """Initialize cluster.""" |
| 134 | if self.get_status() != 'not-initialized': |
| 135 | raise ClusterError( |
| 136 | 'cluster in {!r} has already been initialized'.format( |
| 137 | self._data_dir)) |
| 138 | |
| 139 | settings = dict(settings) |
| 140 | if 'encoding' not in settings: |
| 141 | settings['encoding'] = 'UTF-8' |
| 142 | |
| 143 | if settings: |
| 144 | settings_args = ['--{}={}'.format(k, v) |
| 145 | for k, v in settings.items()] |
| 146 | extra_args = ['-o'] + [' '.join(settings_args)] |
| 147 | else: |
| 148 | extra_args = [] |
| 149 | |
| 150 | os.makedirs(self._data_dir, exist_ok=True) |
| 151 | process = subprocess.run( |
| 152 | [self._pg_ctl, 'init', '-D', self._data_dir] + extra_args, |
| 153 | stdout=subprocess.PIPE, |
| 154 | stderr=subprocess.STDOUT, |
| 155 | cwd=self._data_dir, |
| 156 | ) |
| 157 | |
| 158 | output = process.stdout |
| 159 | |
| 160 | if process.returncode != 0: |
| 161 | raise ClusterError( |
| 162 | 'pg_ctl init exited with status {:d}:\n{}'.format( |
| 163 | process.returncode, output.decode())) |
| 164 | |
| 165 | return output.decode() |
| 166 | |
| 167 | def start(self, wait=60, *, server_settings={}, **opts): |
| 168 | """Start the cluster.""" |
no test coverage detected