async def _configure(schema, conn, cluster, *, insecure=False, testmode=False): scripts = [] if not testmode: memory_kb = psutil.virtual_memory().total // 1024 settings = { 'shared_buffers': f'"{int(memory_kb * 0.2)}kB"', 'effective_cache_size': f'"{int(memory_kb * 0.5)}kB"', 'query_work_mem': f'"{6 * (2 ** 10)}kB"', } for setting, value in settings.items(): scripts.append(f''' CONFIGURE SYSTEM SET {setting} := {value}; ''') else: settings = {} if insecure: scripts.append(''' CONFIGURE SYSTEM INSERT Auth { priority := 0, method := (INSERT Trust), }; ''') config_spec = config.get_settings() for script in scripts: _, sql = compiler.compile_bootstrap_script( schema, schema, script, single_statement=True) if debug.flags.bootstrap: debug.header('Bootstrap') debug.dump_code(sql, lexer='sql') config_op_data = await conn.fetchval(sql) if config_op_data is not None and isinstance(config_op_data, str): config_op = config.Operation.from_json(config_op_data) settings = config_op.apply(config_spec, immutables.Map()) config_json = config.to_json(config_spec, settings) block = dbops.PLTopBlock() dbops.UpdateMetadata( dbops.Database(name=edbdef.EDGEDB_TEMPLATE_DB), {'sysconfig': json.loads(config_json)}, ).generate(block) await _execute_block(conn, block)
async def _configure( schema: s_schema.Schema, compiler: edbcompiler.Compiler, conn: asyncpg_con.Connection, cluster: pgcluster.BaseCluster, *, insecure: bool = False, ) -> None: config_spec = config.get_settings() scripts = [] settings: Mapping[str, config.SettingValue] = {} if insecure: scripts.append(''' CONFIGURE SYSTEM INSERT Auth { priority := 0, method := (INSERT Trust), }; ''') for script in scripts: _, sql = compile_bootstrap_script( compiler, schema, script, single_statement=True, ) if debug.flags.bootstrap: debug.header('Bootstrap') debug.dump_code(sql, lexer='sql') config_op_data = await conn.fetchval(sql) if config_op_data is not None and isinstance(config_op_data, str): config_op = config.Operation.from_json(config_op_data) settings = config_op.apply(config_spec, immutables.Map()) config_json = config.to_json(config_spec, settings, include_source=False) block = dbops.PLTopBlock() dbops.UpdateMetadata( dbops.Database(name=edbdef.EDGEDB_TEMPLATE_DB), { 'sysconfig': json.loads(config_json) }, ).generate(block) await _execute_block(conn, block)
async def _configure( ctx: BootstrapContext, config_spec: config.Spec, schema: s_schema.Schema, compiler: edbcompiler.Compiler, ) -> None: settings: Mapping[str, config.SettingValue] = {} config_json = config.to_json(config_spec, settings, include_source=False) block = dbops.PLTopBlock() metadata = {'sysconfig': json.loads(config_json)} if ctx.cluster.get_runtime_params().has_create_database: dbops.UpdateMetadata( dbops.Database( name=ctx.cluster.get_db_name(edbdef.EDGEDB_SYSTEM_DB) ), metadata, ).generate(block) else: dbops.UpdateSingleDBMetadata( edbdef.EDGEDB_SYSTEM_DB, metadata, ).generate(block) await _execute_block(ctx.conn, block) backend_params = ctx.cluster.get_runtime_params() for setname in config_spec: setting = config_spec[setname] if ( setting.backend_setting and setting.default is not None and ( # Do not attempt to run CONFIGURE INSTANCE on # backends that don't support it. # TODO: this should be replaced by instance-wide # emulation at backend connection time. backend_params.has_configfile_access ) ): if isinstance(setting.default, statypes.Duration): val = f'<std::duration>"{setting.default.to_iso8601()}"' else: val = repr(setting.default) script = f''' CONFIGURE INSTANCE SET {setting.name} := {val}; ''' schema, sql = compile_bootstrap_script(compiler, schema, script) await _execute_ddl(ctx.conn, sql)