void pgstrom_init_opencl_server(void) { BackgroundWorker worker; /* number of opencl server threads */ DefineCustomIntVariable("pg_strom.opencl_num_threads", "number of opencl server threads", NULL, &opencl_num_threads, 0, /* auto selection */ 0, INT_MAX, PGC_POSTMASTER, GUC_NOT_IN_SAMPLE, NULL, NULL, NULL); /* launch a background worker process */ memset(&worker, 0, sizeof(BackgroundWorker)); strcpy(worker.bgw_name, "PG-Strom OpenCL Server"); worker.bgw_flags = BGWORKER_SHMEM_ACCESS; worker.bgw_start_time = BgWorkerStart_PostmasterStart; worker.bgw_restart_time = BGW_NEVER_RESTART; worker.bgw_main = pgstrom_opencl_main; worker.bgw_main_arg = 0; RegisterBackgroundWorker(&worker); /* acquire shared memory */ RequestAddinShmemSpace(MAXALIGN(sizeof(*opencl_serv_shm_values))); shmem_startup_hook_next = shmem_startup_hook; shmem_startup_hook = pgstrom_startup_opencl_server; }
/* * Module load callback */ void _PG_init(void) { /* * In order to create our shared memory area, we have to be loaded via * shared_preload_libraries. If not, fall out without hooking into any of * the main system. (We don't throw error here because it seems useful to * allow the repmgr functions to be created even when the * module isn't active. The functions must protect themselves against * being called then, however.) */ if (!process_shared_preload_libraries_in_progress) return; /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in repmgr_shmem_startup(). */ RequestAddinShmemSpace(repmgr_memsize()); RequestAddinLWLocks(1); /* * Install hooks. */ prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = repmgr_shmem_startup; }
void _PG_init(void) { EmitWarningsOnPlaceholders("orafce"); RequestAddinShmemSpace(SHMEMMSGSZ); RequestAddinLWLocks(1); /* Define custom GUC variables. */ DefineCustomStringVariable("orafce.nls_date_format", "Emulate oracle's date output behaviour.", NULL, &nls_date_format, NULL, PGC_USERSET, 0, NULL, NULL, NULL); DefineCustomStringVariable("orafce.timezone", "Specify timezone used for sysdate function.", NULL, &orafce_timezone, "GMT", PGC_USERSET, 0, check_timezone, NULL, show_timezone); }
/* * InitializeBackendManagement requests the necessary shared memory * from Postgres and sets up the shared memory startup hook. */ void InitializeBackendManagement(void) { /* allocate shared memory */ if (!IsUnderPostmaster) { RequestAddinShmemSpace(BackendManagementShmemSize()); } prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = BackendManagementShmemInit; }
/* * Module load callback */ void _PG_init(void) { /* */ if (! process_shared_preload_libraries_in_progress) { elog(ERROR, "shared_ispell has to be loaded using shared_preload_libraries"); return; } /* Define custom GUC variables. */ /* How much memory should we preallocate for the dictionaries (limits how many * dictionaries you can load into the shared segment). */ DefineCustomIntVariable("shared_ispell.max_size", "amount of memory to pre-allocate for ispell dictionaries", NULL, &max_ispell_mem_size, (32*1024*1024), (1024*1024), INT_MAX, PGC_POSTMASTER, GUC_UNIT_BLOCKS, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); EmitWarningsOnPlaceholders("shared_ispell"); /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in ispell_shmem_startup(). */ RequestAddinShmemSpace(max_ispell_mem_size); RequestAddinLWLocks(1); /* Install hooks. */ prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = ispell_shmem_startup; }
void _PG_init(void) { if (!process_shared_preload_libraries_in_progress) return; RequestAddinShmemSpace(getMemstatSize()); RequestNamedLWLockTranche("memstat", PROCARRAY_MAXPROCS); prev_ExecutorStart = ExecutorStart_hook; ExecutorStart_hook = collectLocalMemoryStats; prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = allocShmem; DefineCustomIntVariable("memstat.period", "Sets period to collect memory statistics", "zero means collecting after each query", &ticPeriod, 10, 0, 60*60*24*31, PGC_SUSET, GUC_UNIT_S, NULL, NULL, NULL); }
/* * Module load callback */ void _PG_init(void) { /* can be preloaded only from postgresql.conf */ if (! process_shared_preload_libraries_in_progress) elog(ERROR, "connection_limits_shared has to be loaded using " "shared_preload_libraries"); DefineCustomIntVariable("connection_limits.per_database", "Default number of connections per database.", "Zero disables this check.", &default_per_database, 0, 0, MaxBackends, PGC_POSTMASTER, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); DefineCustomIntVariable("connection_limits.per_user", "Default number of connections per user.", "Zero disables this check.", &default_per_role, 0, 0, MaxBackends, PGC_POSTMASTER, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); DefineCustomIntVariable("connection_limits.per_ip", "Default number of connections per IP.", "Zero disables this check.", &default_per_ip, 0, 0, MaxBackends, PGC_POSTMASTER, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); EmitWarningsOnPlaceholders("connection_limits"); /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in pg_limits_shmem_startup(). */ RequestAddinShmemSpace(SEGMENT_SIZE); RequestAddinLWLocks(1); /* single lock guarding the rules state */ /* Install shared memory startup hook. */ prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = pg_limits_shmem_startup; /* Install client authentication hook. */ prev_client_auth_hook = ClientAuthentication_hook; ClientAuthentication_hook = check_rules; }
/* * Module load callback */ void _PG_init(void) { /* * In order to create our shared memory area, we have to be loaded via * shared_preload_libraries. If not, fall out without hooking into any of * the main system. (We don't throw error here because it seems useful to * allow the pg_stat_statements functions to be created even when the * module isn't active. The functions must protect themselves against * being called then, however.) */ if (!process_shared_preload_libraries_in_progress) return; /* * Define (or redefine) custom GUC variables. */ DefineCustomIntVariable("pg_stat_statements.max", "Sets the maximum number of statements tracked by pg_stat_statements.", NULL, &pgss_max, 1000, 100, INT_MAX, PGC_POSTMASTER, 0, NULL, NULL); DefineCustomEnumVariable("pg_stat_statements.track", "Selects which statements are tracked by pg_stat_statements.", NULL, &pgss_track, PGSS_TRACK_TOP, track_options, PGC_SUSET, 0, NULL, NULL); DefineCustomBoolVariable("pg_stat_statements.track_utility", "Selects whether utility commands are tracked by pg_stat_statements.", NULL, &pgss_track_utility, true, PGC_SUSET, 0, NULL, NULL); DefineCustomBoolVariable("pg_stat_statements.save", "Save pg_stat_statements statistics across server shutdowns.", NULL, &pgss_save, true, PGC_SIGHUP, 0, NULL, NULL); EmitWarningsOnPlaceholders("pg_stat_statements"); /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in pgss_shmem_startup(). */ RequestAddinShmemSpace(pgss_memsize()); RequestAddinLWLocks(1); /* * Install hooks. */ prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = pgss_shmem_startup; prev_ExecutorStart = ExecutorStart_hook; ExecutorStart_hook = pgss_ExecutorStart; prev_ExecutorRun = ExecutorRun_hook; ExecutorRun_hook = pgss_ExecutorRun; prev_ExecutorEnd = ExecutorEnd_hook; ExecutorEnd_hook = pgss_ExecutorEnd; prev_ProcessUtility = ProcessUtility_hook; ProcessUtility_hook = pgss_ProcessUtility; }
/* * Module load callback */ void _PG_init(void) { /* */ if (!process_shared_preload_libraries_in_progress) return; /* Define custom GUC variables. */ DefineCustomBoolVariable("query_histogram.dynamic", "Dynamic histogram may be modified on the fly.", NULL, &default_histogram_dynamic, false, PGC_BACKEND, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); /* Define custom GUC variables. */ DefineCustomBoolVariable("query_histogram.track_utility", "Selects whether utility commands are tracked.", NULL, &default_histogram_utility, true, PGC_SUSET, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif &set_histogram_track_utility, NULL); DefineCustomIntVariable("query_histogram.bin_count", "Sets the number of bins of the histogram.", "Zero disables collecting the histogram.", &default_histogram_bins, 100, 0, 1000, PGC_SUSET, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif &set_histogram_bins_count_hook, NULL); DefineCustomIntVariable("query_histogram.bin_width", "Sets the width of the histogram bin.", NULL, &default_histogram_step, 100, 1, 1000, PGC_SUSET, GUC_UNIT_MS, #if (PG_VERSION_NUM >= 90100) NULL, #endif &set_histogram_bins_width_hook, NULL); DefineCustomIntVariable("query_histogram.sample_pct", "What portion of the queries should be sampled (in percent).", NULL, &default_histogram_sample_pct, 5, 1, 100, PGC_SUSET, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif &set_histogram_sample_hook, NULL); DefineCustomEnumVariable("query_histogram.histogram_type", "Type of the histogram (how the bin width is computed).", NULL, &default_histogram_type, HISTOGRAM_LINEAR, histogram_type_options, PGC_SUSET, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif &set_histogram_type_hook, NULL); EmitWarningsOnPlaceholders("query_histogram"); /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in histogram_shmem_startup(). */ RequestAddinShmemSpace(get_histogram_size()); RequestAddinLWLocks(1); /* Install hooks. */ prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = histogram_shmem_startup; prev_ExecutorStart = ExecutorStart_hook; ExecutorStart_hook = explain_ExecutorStart; prev_ExecutorRun = ExecutorRun_hook; ExecutorRun_hook = explain_ExecutorRun; #if (PG_VERSION_NUM >= 90100) prev_ExecutorFinish = ExecutorFinish_hook; ExecutorFinish_hook = explain_ExecutorFinish; #endif prev_ExecutorEnd = ExecutorEnd_hook; ExecutorEnd_hook = explain_ExecutorEnd; prev_ProcessUtility = ProcessUtility_hook; ProcessUtility_hook = queryhist_ProcessUtility; }
void _PG_init(void) { /* * In order to create our shared memory area, we have to be loaded via * shared_preload_libraries. If not, fall out without hooking into any of * the main system. (We don't throw error here because it seems useful to * allow the cs_* functions to be created even when the * module isn't active. The functions must protect themselves against * being called then, however.) */ if (!process_shared_preload_libraries_in_progress) return; DefineCustomIntVariable( "multimaster.workers", "Number of multimaster executor workers per node", NULL, &MMWorkers, 8, 1, INT_MAX, PGC_BACKEND, 0, NULL, NULL, NULL ); DefineCustomIntVariable( "multimaster.queue_size", "Multimaster queue size", NULL, &MMQueueSize, 1024*1024, 1024, INT_MAX, PGC_BACKEND, 0, NULL, NULL, NULL ); DefineCustomIntVariable( "multimaster.local_xid_reserve", "Number of XIDs reserved by node for local transactions", NULL, &DtmLocalXidReserve, 100, 1, INT_MAX, PGC_BACKEND, 0, NULL, NULL, NULL ); DefineCustomIntVariable( "multimaster.buffer_size", "Size of sockhub buffer for connection to DTM daemon, if 0, then direct connection will be used", NULL, &DtmBufferSize, 0, 0, INT_MAX, PGC_BACKEND, 0, NULL, NULL, NULL ); DefineCustomStringVariable( "multimaster.arbiters", "The comma separated host:port pairs where arbiters reside", NULL, &Arbiters, "127.0.0.1:5431", PGC_BACKEND, // context 0, // flags, NULL, // GucStringCheckHook check_hook, NULL, // GucStringAssignHook assign_hook, NULL // GucShowHook show_hook ); DefineCustomStringVariable( "multimaster.conn_strings", "Multimaster node connection strings separated by commas, i.e. 'replication=database dbname=postgres host=localhost port=5001,replication=database dbname=postgres host=localhost port=5002'", NULL, &MMConnStrs, "", PGC_BACKEND, // context 0, // flags, NULL, // GucStringCheckHook check_hook, NULL, // GucStringAssignHook assign_hook, NULL // GucShowHook show_hook ); DefineCustomIntVariable( "multimaster.node_id", "Multimaster node ID", NULL, &MMNodeId, 1, 1, INT_MAX, PGC_BACKEND, 0, NULL, NULL, NULL ); /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in dtm_shmem_startup(). */ RequestAddinShmemSpace(DTM_SHMEM_SIZE + MMQueueSize); RequestAddinLWLocks(2); MMNodes = MMStartReceivers(MMConnStrs, MMNodeId); if (MMNodes < 2) { elog(ERROR, "Multimaster should have at least two nodes"); } BgwPoolStart(MMWorkers, MMPoolConstructor); ArbitersCopy = strdup(Arbiters); if (DtmBufferSize != 0) { ArbiterConfig(Arbiters, Unix_socket_directories); RegisterBackgroundWorker(&DtmWorker); } else ArbiterConfig(Arbiters, NULL); /* * Install hooks. */ PreviousShmemStartupHook = shmem_startup_hook; shmem_startup_hook = DtmShmemStartup; PreviousExecutorFinishHook = ExecutorFinish_hook; ExecutorFinish_hook = MMExecutorFinish; PreviousProcessUtilityHook = ProcessUtility_hook; ProcessUtility_hook = MMProcessUtility; }
/* * Module load callback */ void _PG_init(void) { /* can be preloaded only from postgresql.conf */ if (!process_shared_preload_libraries_in_progress) return; /* Define custom GUC variables. */ DefineCustomStringVariable("query_recorder.filename", "Base filename to write the recorded queries.", NULL, &base_filename, false, PGC_BACKEND, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); DefineCustomIntVariable("query_recorder.max_files", "How many files will be rotated.", NULL, &max_files, 100, 1, 1000, PGC_BACKEND, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); DefineCustomIntVariable("query_recorder.size_limit", "File size limit (will create multiple files .000 - .999)", NULL, &max_file_size, 1024*1024*1024/BLCKSZ, /* 1GB */ 1024*1024/BLCKSZ, 1024*1024*1024/BLCKSZ, /* 1MB - 1GB */ PGC_BACKEND, GUC_UNIT_BLOCKS, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); DefineCustomIntVariable("query_recorder.buffer_size", "Size of the buffer used to collect queries.", NULL, &buffer_size, 1024*1024/BLCKSZ, /* 1MB */ 1, 16*1024*1024/BLCKSZ, /* 1 block - 16MB */ PGC_BACKEND, GUC_UNIT_BLOCKS, #if (PG_VERSION_NUM >= 90100) NULL, #endif NULL, NULL); /* Define custom GUC variables. */ DefineCustomBoolVariable("query_recorder.normalize", "Replace line breaks and carriage returns with spaces.", NULL, &normalize, false, PGC_BACKEND, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif &set_enabled, NULL); /* Define custom GUC variables. */ DefineCustomBoolVariable("query_recorder.enabled", "Enable or disable recording of queries.", NULL, &enabled, false, PGC_SUSET, 0, #if (PG_VERSION_NUM >= 90100) NULL, #endif &set_enabled, (GucShowHook)(&show_enabled)); EmitWarningsOnPlaceholders("query_recorder"); /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in pg_record_shmem_startup(). */ RequestAddinShmemSpace(SEGMENT_SIZE); RequestAddinLWLocks(1); /* Install hooks. */ prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = pg_record_shmem_startup; prev_ExecutorStart = ExecutorStart_hook; ExecutorStart_hook = explain_ExecutorStart; prev_ExecutorRun = ExecutorRun_hook; ExecutorRun_hook = explain_ExecutorRun; #if (PG_VERSION_NUM >= 90100) prev_ExecutorFinish = ExecutorFinish_hook; ExecutorFinish_hook = explain_ExecutorFinish; #endif prev_ExecutorEnd = ExecutorEnd_hook; ExecutorEnd_hook = explain_ExecutorEnd; prev_ProcessUtility = ProcessUtility_hook; ProcessUtility_hook = pg_record_ProcessUtility; }
/* * Module load callback */ void _PG_init(void) { /* * In order to create our shared memory area, we have to be loaded via * shared_preload_libraries. If not, fall out without hooking into any of * the main system. (We don't throw error here because it seems useful to * allow the query_histogram functions to be created even when the * module isn't active. The functions must protect themselves against * being called then, however.) */ if (!process_shared_preload_libraries_in_progress) return; /* Define custom GUC variables. */ DefineCustomBoolVariable("query_histogram.dynamic", "Dynamic histogram may be modified on the fly.", NULL, &default_histogram_dynamic, false, PGC_BACKEND, 0, NULL, NULL, NULL); /* Define custom GUC variables. */ DefineCustomBoolVariable("query_histogram.track_utility", "Selects whether utility commands are tracked.", NULL, &default_histogram_utility, true, PGC_SUSET, 0, NULL, &set_histogram_track_utility, &show_histogram_track_utility); DefineCustomIntVariable("query_histogram.bin_count", "Sets the number of bins of the histogram.", "Zero disables collecting the histogram.", &default_histogram_bins, 100, 0, 1000, PGC_SUSET, 0, NULL, &set_histogram_bins_count_hook, &show_histogram_bins_count_hook); DefineCustomIntVariable("query_histogram.bin_width", "Sets the width of the histogram bin.", NULL, &default_histogram_step, 100, 1, 1000, PGC_SUSET, GUC_UNIT_MS, NULL, &set_histogram_bins_width_hook, &show_histogram_bins_width_hook); DefineCustomIntVariable("query_histogram.sample_pct", "What portion of the queries should be sampled (in percent).", NULL, &default_histogram_sample_pct, 5, 1, 100, PGC_SUSET, 0, NULL, &set_histogram_sample_hook, &show_histogram_sample_hook); DefineCustomEnumVariable("query_histogram.histogram_type", "Type of the histogram (how the bin width is computed).", NULL, &default_histogram_type, HISTOGRAM_LINEAR, histogram_type_options, PGC_SUSET, 0, NULL, &set_histogram_type_hook, &show_histogram_type_hook); EmitWarningsOnPlaceholders("query_histogram"); /* * Request additional shared resources. (These are no-ops if we're not in * the postmaster process.) We'll allocate or attach to the shared * resources in histogram_shmem_startup(). */ RequestAddinShmemSpace(get_histogram_size()); RequestNamedLWLockTranche("query_histogram", 1); /* Install hooks. */ prev_shmem_startup_hook = shmem_startup_hook; shmem_startup_hook = histogram_shmem_startup; prev_ExecutorStart = ExecutorStart_hook; ExecutorStart_hook = histogram_ExecutorStart; prev_ExecutorRun = ExecutorRun_hook; ExecutorRun_hook = histogram_ExecutorRun; prev_ExecutorFinish = ExecutorFinish_hook; ExecutorFinish_hook = histogram_ExecutorFinish; prev_ExecutorEnd = ExecutorEnd_hook; ExecutorEnd_hook = histogram_ExecutorEnd; prev_ProcessUtility = ProcessUtility_hook; ProcessUtility_hook = queryhist_ProcessUtility; }