Пример #1
0
/*
 * Initialize timezone library
 *
 * This is called after initial loading of postgresql.conf.  If no TimeZone
 * setting was found therein, we try to derive one from the environment.
 * Likewise for log_timezone.
 */
void
pg_timezone_initialize(void)
{
	pg_tz	   *def_tz = NULL;

	/* Do we need to try to figure the session timezone? */
	if (pg_strcasecmp(GetConfigOption("timezone", false), "UNKNOWN") == 0)
	{
		/* Select setting */
		def_tz = select_default_timezone();
		session_timezone = def_tz;
		/* Tell GUC about the value. Will redundantly call pg_tzset() */
		SetConfigOption("timezone", pg_get_timezone_name(def_tz),
						PGC_POSTMASTER, PGC_S_ARGV);
	}

	/* What about the log timezone? */
	if (pg_strcasecmp(GetConfigOption("log_timezone", false), "UNKNOWN") == 0)
	{
		/* Select setting, but don't duplicate work */
		if (!def_tz)
			def_tz = select_default_timezone();
		log_timezone = def_tz;
		/* Tell GUC about the value. Will redundantly call pg_tzset() */
		SetConfigOption("log_timezone", pg_get_timezone_name(def_tz),
						PGC_POSTMASTER, PGC_S_ARGV);
	}
}
Пример #2
0
/*
 * Initialize timezone library
 *
 * This is called after initial loading of postgresql.conf.  If no TimeZone
 * setting was found therein, we try to derive one from the environment.
 * Likewise for log_timezone.
 *
 * Note: this is also called from process_config_file, to re-establish valid
 * GUC settings if the GUCs have been reset to default following their
 * removal from postgresql.conf.
 */
void
pg_timezone_initialize(void)
{
	pg_tz* def_tz = NULL;

	/*
	 * Make sure that session_timezone and log_timezone are set.
	 * (session_timezone could still be NULL even if a timezone value was set
	 * in postgresql.conf, if that setting was interval-based rather than
	 * timezone-based.)
	 */
	if (!session_timezone) {
		def_tz = select_default_timezone();
		session_timezone = def_tz;
	}

	if (!log_timezone) {
		/* Don't duplicate work */
		if (!def_tz)
			def_tz = select_default_timezone();

		log_timezone = def_tz;
	}

	/*
	 * Now, set the timezone and log_timezone GUCs if they're still default.
	 * (This will redundantly call pg_tzset().)
	 *
	 * We choose to label these values PGC_S_ENV_VAR, rather than
	 * PGC_S_DYNAMIC_DEFAULT which would be functionally equivalent, because
	 * they came either from getenv("TZ") or from libc behavior that's
	 * determined by process environment of some kind.
	 *
	 * Note: in the case where a setting has just been removed from
	 * postgresql.conf, this code will not do what you might expect, namely
	 * call select_default_timezone() and install that value as the setting.
	 * Rather, the previously active setting --- typically the one from
	 * postgresql.conf --- will be reinstalled, relabeled as PGC_S_ENV_VAR. If
	 * we did try to install the "correct" default value, the effect would be
	 * that each postmaster child would independently run an extremely
	 * expensive search of the timezone database, bringing the database to its
	 * knees for possibly multiple seconds.  This is so unpleasant, and could
	 * so easily be triggered quite unintentionally, that it seems better to
	 * violate the principle of least astonishment.
	 */
	if (reset_guc_opt("timezone") == NULL)
		set_option("timezone",
			pg_get_timezone_name(session_timezone),
			PGC_POSTMASTER,
			PGC_S_ENV_VAR);

	if (reset_guc_opt("log_timezone") == NULL)
		set_option("log_timezone",
			pg_get_timezone_name(log_timezone),
			PGC_POSTMASTER,
			PGC_S_ENV_VAR);
}
Пример #3
0
/*
 * Initialize timezone library
 *
 * This is called after initial loading of postgresql.conf.  If no TimeZone
 * setting was found therein, we try to derive one from the environment.
 * Likewise for log_timezone.
 */
void
pg_timezone_initialize(void)
{
	pg_tz	   *def_tz = NULL;

	/*
	 * Make sure that session_timezone and log_timezone are set.
	 * (session_timezone could still be NULL even if a timezone value was set
	 * in postgresql.conf, if that setting was interval-based rather than
	 * timezone-based.)
	 */
	if (!session_timezone)
	{
		def_tz = select_default_timezone();
		session_timezone = def_tz;
	}
	if (!log_timezone)
	{
		/* Don't duplicate work */
		if (!def_tz)
			def_tz = select_default_timezone();
		log_timezone = def_tz;
	}

	/* Now, set the timezone GUC if it's not already set */
	if (GetConfigOption("timezone", false) == NULL)
	{
		/* Tell GUC about the value. Will redundantly call pg_tzset() */
		SetConfigOption("timezone", pg_get_timezone_name(session_timezone),
						PGC_POSTMASTER, PGC_S_ENV_VAR);
	}

	/* Likewise for log timezone */
	if (GetConfigOption("log_timezone", false) == NULL)
	{
		/* Tell GUC about the value. Will redundantly call pg_tzset() */
		SetConfigOption("log_timezone", pg_get_timezone_name(log_timezone),
						PGC_POSTMASTER, PGC_S_ENV_VAR);
	}
}
Пример #4
0
/*
 * Initialize timezone library
 *
 * This is called after initial loading of postgresql.conf.  If no TimeZone
 * setting was found therein, we try to derive one from the environment.
 */
void
pg_timezone_initialize(void)
{
	/* Do we need to try to figure the timezone? */
	if (pg_strcasecmp(GetConfigOption("timezone"), "UNKNOWN") == 0)
	{
		const char *def_tz;

		/* Select setting */
		def_tz = select_default_timezone();
		/* Tell GUC about the value. Will redundantly call pg_tzset() */
		SetConfigOption("timezone", def_tz, PGC_POSTMASTER, PGC_S_ARGV);
	}
}