Пример #1
0
def wipe(*, postgres_dsn, data_dir, yes, dry_run):
    if postgres_dsn:
        cluster = pgcluster.get_remote_pg_cluster(postgres_dsn)
    elif data_dir:
        cluster = pgcluster.get_local_pg_cluster(data_dir)
        cluster.set_connection_params(
            pgconnparams.ConnectionParameters(
                user='******',
                database='template1',
            ), )
    else:
        raise click.UsageError(
            'either --postgres-dsn or --data-dir is required')

    if not yes and not click.confirm(
            'This will DELETE all EdgeDB data from the target '
            'PostgreSQL instance.  ARE YOU SURE?'):
        click.echo('OK. Not proceeding.')

    status = cluster.get_status()
    cluster_started_by_us = False
    if status != 'running':
        if isinstance(cluster, pgcluster.RemoteCluster):
            click.secho(f'Remote cluster is not running', fg='red')
            sys.exit(1)
        else:
            cluster.start(port=edbcluster.find_available_port())
            cluster_started_by_us = True

    try:
        asyncio.run(do_wipe(cluster, dry_run))
    finally:
        if cluster_started_by_us:
            cluster.stop()
Пример #2
0
    def setUpClass(cls):
        super().setUpClass()

        cls.http_host = '127.0.0.1'
        cls.http_port = cluster.find_available_port()
        dbname = cls.get_database_name()

        cls.loop.run_until_complete(
            cls.con.execute(f'''
                    CONFIGURE SYSTEM INSERT Port {{
                        protocol := "{cls.get_port_proto()}",
                        database := "{dbname}",
                        address := "{cls.http_host}",
                        port := {cls.http_port},
                        user := "******",
                        concurrency := 4,
                    }};
                '''))

        cls.http_addr = f'http://127.0.0.1:{cls.http_port}'
Пример #3
0
    def test_server_ops_detect_postgres_pool_size(self):
        port = edgedb_cluster.find_available_port()
        actual = random.randint(50, 100)

        async def test(host):
            bootstrap_command = (
                r'CONFIGURE SYSTEM INSERT Auth '
                r'{ priority := 0, method := (INSERT Trust) }')
            async with tb.start_edgedb_server(
                    auto_shutdown=True,
                    bootstrap_command=bootstrap_command,
                    max_allowed_connections=None,
                    postgres_dsn=f'postgres:///?user=postgres&port={port}&'
                    f'host={host}',
            ) as sd:
                con = await edgedb.async_connect(user='******',
                                                 host=sd.host,
                                                 port=sd.port)
                try:
                    max_connections = await con.query_one(
                        'SELECT cfg::SystemConfig.__pg_max_connections '
                        'LIMIT 1')  # TODO: remove LIMIT 1 after #2402
                    self.assertEqual(int(max_connections), actual)
                finally:
                    await con.aclose()

        with tempfile.TemporaryDirectory() as td:
            cluster = pgcluster.get_local_pg_cluster(td,
                                                     max_connections=actual)
            cluster.set_connection_params(
                pgconnparams.ConnectionParameters(
                    user='******',
                    database='template1',
                ), )
            self.assertTrue(cluster.ensure_initialized())
            cluster.start(port=port)
            try:
                self.loop.run_until_complete(test(td))
            finally:
                cluster.stop()