PostgreSQL Source Code  git master
variable.c File Reference
#include "postgres.h"
#include <ctype.h>
#include "access/htup_details.h"
#include "access/parallel.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "access/xlogprefetcher.h"
#include "catalog/pg_authid.h"
#include "common/string.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
#include "storage/bufmgr.h"
#include "utils/acl.h"
#include "utils/backend_status.h"
#include "utils/datetime.h"
#include "utils/fmgrprotos.h"
#include "utils/guc_hooks.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
#include "utils/timestamp.h"
#include "utils/tzparser.h"
#include "utils/varlena.h"
Include dependency graph for variable.c:

Go to the source code of this file.

Data Structures

struct  role_auth_extra
 

Functions

bool check_datestyle (char **newval, void **extra, GucSource source)
 
void assign_datestyle (const char *newval, void *extra)
 
bool check_timezone (char **newval, void **extra, GucSource source)
 
void assign_timezone (const char *newval, void *extra)
 
const char * show_timezone (void)
 
bool check_log_timezone (char **newval, void **extra, GucSource source)
 
void assign_log_timezone (const char *newval, void *extra)
 
const char * show_log_timezone (void)
 
bool check_timezone_abbreviations (char **newval, void **extra, GucSource source)
 
void assign_timezone_abbreviations (const char *newval, void *extra)
 
bool check_transaction_read_only (bool *newval, void **extra, GucSource source)
 
bool check_transaction_isolation (int *newval, void **extra, GucSource source)
 
bool check_transaction_deferrable (bool *newval, void **extra, GucSource source)
 
bool check_random_seed (double *newval, void **extra, GucSource source)
 
void assign_random_seed (double newval, void *extra)
 
const char * show_random_seed (void)
 
bool check_client_encoding (char **newval, void **extra, GucSource source)
 
void assign_client_encoding (const char *newval, void *extra)
 
bool check_session_authorization (char **newval, void **extra, GucSource source)
 
void assign_session_authorization (const char *newval, void *extra)
 
bool check_role (char **newval, void **extra, GucSource source)
 
void assign_role (const char *newval, void *extra)
 
const char * show_role (void)
 
bool check_canonical_path (char **newval, void **extra, GucSource source)
 
bool check_application_name (char **newval, void **extra, GucSource source)
 
void assign_application_name (const char *newval, void *extra)
 
bool check_cluster_name (char **newval, void **extra, GucSource source)
 
void assign_maintenance_io_concurrency (int newval, void *extra)
 
const char * show_data_directory_mode (void)
 
const char * show_log_file_mode (void)
 
const char * show_unix_socket_permissions (void)
 
bool check_bonjour (bool *newval, void **extra, GucSource source)
 
bool check_default_with_oids (bool *newval, void **extra, GucSource source)
 
bool check_effective_io_concurrency (int *newval, void **extra, GucSource source)
 
bool check_maintenance_io_concurrency (int *newval, void **extra, GucSource source)
 
bool check_ssl (bool *newval, void **extra, GucSource source)
 

Variables

char * role_string
 

Function Documentation

◆ assign_application_name()

void assign_application_name ( const char *  newval,
void *  extra 
)

Definition at line 1075 of file variable.c.

1076 {
1077  /* Update the pg_stat_activity view */
1079 }
void pgstat_report_appname(const char *appname)
#define newval

References newval, and pgstat_report_appname().

◆ assign_client_encoding()

void assign_client_encoding ( const char *  newval,
void *  extra 
)

Definition at line 756 of file variable.c.

757 {
758  int encoding = *((int *) extra);
759 
760  /*
761  * Parallel workers send data to the leader, not the client. They always
762  * send data using the database encoding.
763  */
764  if (IsParallelWorker())
765  {
766  /*
767  * During parallel worker startup, we want to accept the leader's
768  * client_encoding setting so that anyone who looks at the value in
769  * the worker sees the same value that they would see in the leader.
770  */
772  return;
773 
774  /*
775  * A change other than during startup, for example due to a SET clause
776  * attached to a function definition, should be rejected, as there is
777  * nothing we can do inside the worker to make it take effect.
778  */
779  ereport(ERROR,
780  (errcode(ERRCODE_INVALID_TRANSACTION_STATE),
781  errmsg("cannot change client_encoding during a parallel operation")));
782  }
783 
784  /* We do not expect an error if PrepareClientEncoding succeeded */
785  if (SetClientEncoding(encoding) < 0)
786  elog(LOG, "SetClientEncoding(%d) failed", encoding);
787 }
bool InitializingParallelWorker
Definition: parallel.c:118
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define LOG
Definition: elog.h:31
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
#define IsParallelWorker()
Definition: parallel.h:60
int SetClientEncoding(int encoding)
Definition: mbutils.c:208
int32 encoding
Definition: pg_database.h:41

References elog, encoding, ereport, errcode(), errmsg(), ERROR, InitializingParallelWorker, IsParallelWorker, LOG, and SetClientEncoding().

◆ assign_datestyle()

void assign_datestyle ( const char *  newval,
void *  extra 
)

Definition at line 244 of file variable.c.

245 {
246  int *myextra = (int *) extra;
247 
248  DateStyle = myextra[0];
249  DateOrder = myextra[1];
250 }
int DateStyle
Definition: globals.c:122
int DateOrder
Definition: globals.c:123

References DateOrder, and DateStyle.

◆ assign_log_timezone()

void assign_log_timezone ( const char *  newval,
void *  extra 
)

Definition at line 454 of file variable.c.

455 {
456  log_timezone = *((pg_tz **) extra);
457 }
PGDLLIMPORT pg_tz * log_timezone
Definition: pgtz.c:31
Definition: pgtz.h:66

References log_timezone.

◆ assign_maintenance_io_concurrency()

void assign_maintenance_io_concurrency ( int  newval,
void *  extra 
)

Definition at line 1111 of file variable.c.

1112 {
1113 #ifdef USE_PREFETCH
1114  /*
1115  * Reconfigure recovery prefetching, because a setting it depends on
1116  * changed.
1117  */
1119  if (AmStartupProcess())
1121 #endif
1122 }
int maintenance_io_concurrency
Definition: bufmgr.c:153
#define AmStartupProcess()
Definition: miscadmin.h:382
void XLogPrefetchReconfigure(void)

References AmStartupProcess, maintenance_io_concurrency, newval, and XLogPrefetchReconfigure().

◆ assign_random_seed()

void assign_random_seed ( double  newval,
void *  extra 
)

Definition at line 660 of file variable.c.

661 {
662  /* We'll do this at most once for any setting of the GUC variable */
663  if (*((int *) extra))
665  *((int *) extra) = 0;
666 }
Datum Float8GetDatum(float8 X)
Definition: fmgr.c:1816
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:642
Datum setseed(PG_FUNCTION_ARGS)

References DirectFunctionCall1, Float8GetDatum(), newval, and setseed().

◆ assign_role()

void assign_role ( const char *  newval,
void *  extra 
)

Definition at line 995 of file variable.c.

996 {
997  role_auth_extra *myextra = (role_auth_extra *) extra;
998 
999  SetCurrentRoleId(myextra->roleid, myextra->is_superuser);
1000 }
void SetCurrentRoleId(Oid roleid, bool is_superuser)
Definition: miscinit.c:945
bool is_superuser
Definition: variable.c:798

References role_auth_extra::is_superuser, role_auth_extra::roleid, and SetCurrentRoleId().

◆ assign_session_authorization()

void assign_session_authorization ( const char *  newval,
void *  extra 
)

Definition at line 885 of file variable.c.

886 {
887  role_auth_extra *myextra = (role_auth_extra *) extra;
888 
889  /* Do nothing for the boot_val default of NULL */
890  if (!myextra)
891  return;
892 
893  SetSessionAuthorization(myextra->roleid, myextra->is_superuser);
894 }
void SetSessionAuthorization(Oid userid, bool is_superuser)
Definition: miscinit.c:908

References role_auth_extra::is_superuser, role_auth_extra::roleid, and SetSessionAuthorization().

◆ assign_timezone()

void assign_timezone ( const char *  newval,
void *  extra 
)

Definition at line 381 of file variable.c.

382 {
383  session_timezone = *((pg_tz **) extra);
384 }
PGDLLIMPORT pg_tz * session_timezone
Definition: pgtz.c:28

References session_timezone.

◆ assign_timezone_abbreviations()

void assign_timezone_abbreviations ( const char *  newval,
void *  extra 
)

Definition at line 517 of file variable.c.

518 {
519  /* Do nothing for the boot_val default of NULL */
520  if (!extra)
521  return;
522 
524 }
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
Definition: datetime.c:4946

References InstallTimeZoneAbbrevs().

◆ check_application_name()

bool check_application_name ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1049 of file variable.c.

1050 {
1051  char *clean;
1052  char *ret;
1053 
1054  /* Only allow clean ASCII chars in the application name */
1056  if (!clean)
1057  return false;
1058 
1059  ret = guc_strdup(WARNING, clean);
1060  if (!ret)
1061  {
1062  pfree(clean);
1063  return false;
1064  }
1065 
1066  pfree(clean);
1067  *newval = ret;
1068  return true;
1069 }
#define WARNING
Definition: elog.h:36
#define MCXT_ALLOC_NO_OOM
Definition: fe_memutils.h:17
char * guc_strdup(int elevel, const char *src)
Definition: guc.c:679
void pfree(void *pointer)
Definition: mcxt.c:1508
char * pg_clean_ascii(const char *str, int alloc_flags)
Definition: string.c:86

References guc_strdup(), MCXT_ALLOC_NO_OOM, newval, pfree(), pg_clean_ascii(), and WARNING.

◆ check_bonjour()

bool check_bonjour ( bool newval,
void **  extra,
GucSource  source 
)

Definition at line 1172 of file variable.c.

1173 {
1174 #ifndef USE_BONJOUR
1175  if (*newval)
1176  {
1177  GUC_check_errmsg("Bonjour is not supported by this build");
1178  return false;
1179  }
1180 #endif
1181  return true;
1182 }
#define GUC_check_errmsg
Definition: guc.h:443

References GUC_check_errmsg, and newval.

◆ check_canonical_path()

bool check_canonical_path ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1028 of file variable.c.

1029 {
1030  /*
1031  * Since canonicalize_path never enlarges the string, we can just modify
1032  * newval in-place. But watch out for NULL, which is the default value
1033  * for external_pid_file.
1034  */
1035  if (*newval)
1037  return true;
1038 }
void canonicalize_path(char *path)
Definition: path.c:264

References canonicalize_path(), and newval.

◆ check_client_encoding()

bool check_client_encoding ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 680 of file variable.c.

681 {
682  int encoding;
683  const char *canonical_name;
684 
685  /* Look up the encoding by name */
687  if (encoding < 0)
688  return false;
689 
690  /* Get the canonical name (no aliases, uniform case) */
691  canonical_name = pg_encoding_to_char(encoding);
692 
693  /*
694  * If we are not within a transaction then PrepareClientEncoding will not
695  * be able to look up the necessary conversion procs. If we are still
696  * starting up, it will return "OK" anyway, and InitializeClientEncoding
697  * will fix things once initialization is far enough along. After
698  * startup, we'll fail. This would only happen if someone tries to change
699  * client_encoding in postgresql.conf and then SIGHUP existing sessions.
700  * It seems like a bad idea for client_encoding to change that way anyhow,
701  * so we don't go out of our way to support it.
702  *
703  * Note: in the postmaster, or any other process that never calls
704  * InitializeClientEncoding, PrepareClientEncoding will always succeed,
705  * and so will SetClientEncoding; but they won't do anything, which is OK.
706  */
708  {
709  if (IsTransactionState())
710  {
711  /* Must be a genuine no-such-conversion problem */
712  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
713  GUC_check_errdetail("Conversion between %s and %s is not supported.",
714  canonical_name,
716  }
717  else
718  {
719  /* Provide a useful complaint */
720  GUC_check_errdetail("Cannot change client_encoding now.");
721  }
722  return false;
723  }
724 
725  /*
726  * Replace the user-supplied string with the encoding's canonical name.
727  * This gets rid of aliases and case-folding variations.
728  *
729  * XXX Although canonicalizing seems like a good idea in the abstract, it
730  * breaks pre-9.1 JDBC drivers, which expect that if they send "UNICODE"
731  * as the client_encoding setting then it will read back the same way. As
732  * a workaround, don't replace the string if it's "UNICODE". Remove that
733  * hack when pre-9.1 JDBC drivers are no longer in use.
734  */
735  if (strcmp(*newval, canonical_name) != 0 &&
736  strcmp(*newval, "UNICODE") != 0)
737  {
738  guc_free(*newval);
739  *newval = guc_strdup(LOG, canonical_name);
740  if (!*newval)
741  return false;
742  }
743 
744  /*
745  * Save the encoding's ID in *extra, for use by assign_client_encoding.
746  */
747  *extra = guc_malloc(LOG, sizeof(int));
748  if (!*extra)
749  return false;
750  *((int *) *extra) = encoding;
751 
752  return true;
753 }
int pg_valid_client_encoding(const char *name)
Definition: encnames.c:485
void GUC_check_errcode(int sqlerrcode)
Definition: guc.c:6729
void * guc_malloc(int elevel, size_t size)
Definition: guc.c:640
void guc_free(void *ptr)
Definition: guc.c:691
#define GUC_check_errdetail
Definition: guc.h:447
int PrepareClientEncoding(int encoding)
Definition: mbutils.c:110
const char * GetDatabaseEncodingName(void)
Definition: mbutils.c:1267
#define pg_encoding_to_char
Definition: pg_wchar.h:630
bool IsTransactionState(void)
Definition: xact.c:384

References encoding, GetDatabaseEncodingName(), GUC_check_errcode(), GUC_check_errdetail, guc_free(), guc_malloc(), guc_strdup(), IsTransactionState(), LOG, newval, pg_encoding_to_char, pg_valid_client_encoding(), and PrepareClientEncoding().

◆ check_cluster_name()

bool check_cluster_name ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 1085 of file variable.c.

1086 {
1087  char *clean;
1088  char *ret;
1089 
1090  /* Only allow clean ASCII chars in the cluster name */
1092  if (!clean)
1093  return false;
1094 
1095  ret = guc_strdup(WARNING, clean);
1096  if (!ret)
1097  {
1098  pfree(clean);
1099  return false;
1100  }
1101 
1102  pfree(clean);
1103  *newval = ret;
1104  return true;
1105 }

References guc_strdup(), MCXT_ALLOC_NO_OOM, newval, pfree(), pg_clean_ascii(), and WARNING.

◆ check_datestyle()

bool check_datestyle ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 52 of file variable.c.

53 {
54  int newDateStyle = DateStyle;
55  int newDateOrder = DateOrder;
56  bool have_style = false;
57  bool have_order = false;
58  bool ok = true;
59  char *rawstring;
60  int *myextra;
61  char *result;
62  List *elemlist;
63  ListCell *l;
64 
65  /* Need a modifiable copy of string */
66  rawstring = pstrdup(*newval);
67 
68  /* Parse string into list of identifiers */
69  if (!SplitIdentifierString(rawstring, ',', &elemlist))
70  {
71  /* syntax error in list */
72  GUC_check_errdetail("List syntax is invalid.");
73  pfree(rawstring);
74  list_free(elemlist);
75  return false;
76  }
77 
78  foreach(l, elemlist)
79  {
80  char *tok = (char *) lfirst(l);
81 
82  /* Ugh. Somebody ought to write a table driven version -- mjl */
83 
84  if (pg_strcasecmp(tok, "ISO") == 0)
85  {
86  if (have_style && newDateStyle != USE_ISO_DATES)
87  ok = false; /* conflicting styles */
88  newDateStyle = USE_ISO_DATES;
89  have_style = true;
90  }
91  else if (pg_strcasecmp(tok, "SQL") == 0)
92  {
93  if (have_style && newDateStyle != USE_SQL_DATES)
94  ok = false; /* conflicting styles */
95  newDateStyle = USE_SQL_DATES;
96  have_style = true;
97  }
98  else if (pg_strncasecmp(tok, "POSTGRES", 8) == 0)
99  {
100  if (have_style && newDateStyle != USE_POSTGRES_DATES)
101  ok = false; /* conflicting styles */
102  newDateStyle = USE_POSTGRES_DATES;
103  have_style = true;
104  }
105  else if (pg_strcasecmp(tok, "GERMAN") == 0)
106  {
107  if (have_style && newDateStyle != USE_GERMAN_DATES)
108  ok = false; /* conflicting styles */
109  newDateStyle = USE_GERMAN_DATES;
110  have_style = true;
111  /* GERMAN also sets DMY, unless explicitly overridden */
112  if (!have_order)
113  newDateOrder = DATEORDER_DMY;
114  }
115  else if (pg_strcasecmp(tok, "YMD") == 0)
116  {
117  if (have_order && newDateOrder != DATEORDER_YMD)
118  ok = false; /* conflicting orders */
119  newDateOrder = DATEORDER_YMD;
120  have_order = true;
121  }
122  else if (pg_strcasecmp(tok, "DMY") == 0 ||
123  pg_strncasecmp(tok, "EURO", 4) == 0)
124  {
125  if (have_order && newDateOrder != DATEORDER_DMY)
126  ok = false; /* conflicting orders */
127  newDateOrder = DATEORDER_DMY;
128  have_order = true;
129  }
130  else if (pg_strcasecmp(tok, "MDY") == 0 ||
131  pg_strcasecmp(tok, "US") == 0 ||
132  pg_strncasecmp(tok, "NONEURO", 7) == 0)
133  {
134  if (have_order && newDateOrder != DATEORDER_MDY)
135  ok = false; /* conflicting orders */
136  newDateOrder = DATEORDER_MDY;
137  have_order = true;
138  }
139  else if (pg_strcasecmp(tok, "DEFAULT") == 0)
140  {
141  /*
142  * Easiest way to get the current DEFAULT state is to fetch the
143  * DEFAULT string from guc.c and recursively parse it.
144  *
145  * We can't simply "return check_datestyle(...)" because we need
146  * to handle constructs like "DEFAULT, ISO".
147  */
148  char *subval;
149  void *subextra = NULL;
150 
151  subval = guc_strdup(LOG, GetConfigOptionResetString("datestyle"));
152  if (!subval)
153  {
154  ok = false;
155  break;
156  }
157  if (!check_datestyle(&subval, &subextra, source))
158  {
159  guc_free(subval);
160  ok = false;
161  break;
162  }
163  myextra = (int *) subextra;
164  if (!have_style)
165  newDateStyle = myextra[0];
166  if (!have_order)
167  newDateOrder = myextra[1];
168  guc_free(subval);
169  guc_free(subextra);
170  }
171  else
172  {
173  GUC_check_errdetail("Unrecognized key word: \"%s\".", tok);
174  pfree(rawstring);
175  list_free(elemlist);
176  return false;
177  }
178  }
179 
180  pfree(rawstring);
181  list_free(elemlist);
182 
183  if (!ok)
184  {
185  GUC_check_errdetail("Conflicting \"datestyle\" specifications.");
186  return false;
187  }
188 
189  /*
190  * Prepare the canonical string to return. GUC wants it guc_malloc'd.
191  */
192  result = (char *) guc_malloc(LOG, 32);
193  if (!result)
194  return false;
195 
196  switch (newDateStyle)
197  {
198  case USE_ISO_DATES:
199  strcpy(result, "ISO");
200  break;
201  case USE_SQL_DATES:
202  strcpy(result, "SQL");
203  break;
204  case USE_GERMAN_DATES:
205  strcpy(result, "German");
206  break;
207  default:
208  strcpy(result, "Postgres");
209  break;
210  }
211  switch (newDateOrder)
212  {
213  case DATEORDER_YMD:
214  strcat(result, ", YMD");
215  break;
216  case DATEORDER_DMY:
217  strcat(result, ", DMY");
218  break;
219  default:
220  strcat(result, ", MDY");
221  break;
222  }
223 
224  guc_free(*newval);
225  *newval = result;
226 
227  /*
228  * Set up the "extra" struct actually used by assign_datestyle.
229  */
230  myextra = (int *) guc_malloc(LOG, 2 * sizeof(int));
231  if (!myextra)
232  return false;
233  myextra[0] = newDateStyle;
234  myextra[1] = newDateOrder;
235  *extra = (void *) myextra;
236 
237  return true;
238 }
bool check_datestyle(char **newval, void **extra, GucSource source)
Definition: variable.c:52
const char * GetConfigOptionResetString(const char *name)
Definition: guc.c:4348
void list_free(List *list)
Definition: list.c:1546
char * pstrdup(const char *in)
Definition: mcxt.c:1683
#define USE_SQL_DATES
Definition: miscadmin.h:236
#define USE_POSTGRES_DATES
Definition: miscadmin.h:234
#define USE_ISO_DATES
Definition: miscadmin.h:235
#define DATEORDER_DMY
Definition: miscadmin.h:242
#define DATEORDER_MDY
Definition: miscadmin.h:243
#define DATEORDER_YMD
Definition: miscadmin.h:241
#define USE_GERMAN_DATES
Definition: miscadmin.h:237
#define lfirst(lc)
Definition: pg_list.h:172
static rewind_source * source
Definition: pg_rewind.c:89
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
Definition: pg_list.h:54
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3457

References DateOrder, DATEORDER_DMY, DATEORDER_MDY, DATEORDER_YMD, DateStyle, GetConfigOptionResetString(), GUC_check_errdetail, guc_free(), guc_malloc(), guc_strdup(), lfirst, list_free(), LOG, newval, pfree(), pg_strcasecmp(), pg_strncasecmp(), pstrdup(), source, SplitIdentifierString(), USE_GERMAN_DATES, USE_ISO_DATES, USE_POSTGRES_DATES, and USE_SQL_DATES.

◆ check_default_with_oids()

bool check_default_with_oids ( bool newval,
void **  extra,
GucSource  source 
)

Definition at line 1185 of file variable.c.

1186 {
1187  if (*newval)
1188  {
1189  /* check the GUC's definition for an explanation */
1190  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
1191  GUC_check_errmsg("tables declared WITH OIDS are not supported");
1192 
1193  return false;
1194  }
1195 
1196  return true;
1197 }

References GUC_check_errcode(), GUC_check_errmsg, and newval.

◆ check_effective_io_concurrency()

bool check_effective_io_concurrency ( int *  newval,
void **  extra,
GucSource  source 
)

Definition at line 1200 of file variable.c.

1201 {
1202 #ifndef USE_PREFETCH
1203  if (*newval != 0)
1204  {
1205  GUC_check_errdetail("effective_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
1206  return false;
1207  }
1208 #endif /* USE_PREFETCH */
1209  return true;
1210 }

References GUC_check_errdetail, and newval.

◆ check_log_timezone()

bool check_log_timezone ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 416 of file variable.c.

417 {
418  pg_tz *new_tz;
419 
420  /*
421  * Assume it is a timezone name, and try to load it.
422  */
423  new_tz = pg_tzset(*newval);
424 
425  if (!new_tz)
426  {
427  /* Doesn't seem to be any great value in errdetail here */
428  return false;
429  }
430 
431  if (!pg_tz_acceptable(new_tz))
432  {
433  GUC_check_errmsg("time zone \"%s\" appears to use leap seconds",
434  *newval);
435  GUC_check_errdetail("PostgreSQL does not support leap seconds.");
436  return false;
437  }
438 
439  /*
440  * Pass back data for assign_log_timezone to use
441  */
442  *extra = guc_malloc(LOG, sizeof(pg_tz *));
443  if (!*extra)
444  return false;
445  *((pg_tz **) *extra) = new_tz;
446 
447  return true;
448 }
bool pg_tz_acceptable(pg_tz *tz)
Definition: localtime.c:1890
pg_tz * pg_tzset(const char *tzname)
Definition: pgtz.c:234

References GUC_check_errdetail, GUC_check_errmsg, guc_malloc(), LOG, newval, pg_tz_acceptable(), and pg_tzset().

◆ check_maintenance_io_concurrency()

bool check_maintenance_io_concurrency ( int *  newval,
void **  extra,
GucSource  source 
)

Definition at line 1213 of file variable.c.

1214 {
1215 #ifndef USE_PREFETCH
1216  if (*newval != 0)
1217  {
1218  GUC_check_errdetail("maintenance_io_concurrency must be set to 0 on platforms that lack posix_fadvise().");
1219  return false;
1220  }
1221 #endif /* USE_PREFETCH */
1222  return true;
1223 }

References GUC_check_errdetail, and newval.

◆ check_random_seed()

bool check_random_seed ( double *  newval,
void **  extra,
GucSource  source 
)

Definition at line 648 of file variable.c.

649 {
650  *extra = guc_malloc(LOG, sizeof(int));
651  if (!*extra)
652  return false;
653  /* Arm the assign only if source of value is an interactive SET */
654  *((int *) *extra) = (source >= PGC_S_INTERACTIVE);
655 
656  return true;
657 }
@ PGC_S_INTERACTIVE
Definition: guc.h:120

References guc_malloc(), LOG, PGC_S_INTERACTIVE, and source.

◆ check_role()

bool check_role ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 907 of file variable.c.

908 {
909  HeapTuple roleTup;
910  Oid roleid;
911  bool is_superuser;
912  role_auth_extra *myextra;
913  Form_pg_authid roleform;
914 
915  if (strcmp(*newval, "none") == 0)
916  {
917  /* hardwired translation */
918  roleid = InvalidOid;
919  is_superuser = false;
920  }
921  else
922  {
923  if (!IsTransactionState())
924  {
925  /*
926  * Can't do catalog lookups, so fail. The result of this is that
927  * role cannot be set in postgresql.conf, which seems like a good
928  * thing anyway, so we don't work hard to avoid it.
929  */
930  return false;
931  }
932 
933  /*
934  * When source == PGC_S_TEST, we don't throw a hard error for a
935  * nonexistent user name or insufficient privileges, only a NOTICE.
936  * See comments in guc.h.
937  */
938 
939  /* Look up the username */
940  roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(*newval));
941  if (!HeapTupleIsValid(roleTup))
942  {
943  if (source == PGC_S_TEST)
944  {
945  ereport(NOTICE,
946  (errcode(ERRCODE_UNDEFINED_OBJECT),
947  errmsg("role \"%s\" does not exist", *newval)));
948  return true;
949  }
950  GUC_check_errmsg("role \"%s\" does not exist", *newval);
951  return false;
952  }
953 
954  roleform = (Form_pg_authid) GETSTRUCT(roleTup);
955  roleid = roleform->oid;
956  is_superuser = roleform->rolsuper;
957 
958  ReleaseSysCache(roleTup);
959 
960  /*
961  * Verify that session user is allowed to become this role, but skip
962  * this in parallel mode, where we must blindly recreate the parallel
963  * leader's state.
964  */
967  {
968  if (source == PGC_S_TEST)
969  {
970  ereport(NOTICE,
971  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
972  errmsg("permission will be denied to set role \"%s\"",
973  *newval)));
974  return true;
975  }
976  GUC_check_errcode(ERRCODE_INSUFFICIENT_PRIVILEGE);
977  GUC_check_errmsg("permission denied to set role \"%s\"",
978  *newval);
979  return false;
980  }
981  }
982 
983  /* Set up "extra" struct for assign_role to use */
984  myextra = (role_auth_extra *) guc_malloc(LOG, sizeof(role_auth_extra));
985  if (!myextra)
986  return false;
987  myextra->roleid = roleid;
988  myextra->is_superuser = is_superuser;
989  *extra = (void *) myextra;
990 
991  return true;
992 }
bool member_can_set_role(Oid member, Oid role)
Definition: acl.c:5162
#define NOTICE
Definition: elog.h:35
@ PGC_S_TEST
Definition: guc.h:121
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
Oid GetSessionUserId(void)
Definition: miscinit.c:548
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
static bool is_superuser(Archive *fout)
Definition: pg_dump.c:4634
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218

References ereport, errcode(), errmsg(), GetSessionUserId(), GETSTRUCT, GUC_check_errcode(), GUC_check_errmsg, guc_malloc(), HeapTupleIsValid, InitializingParallelWorker, InvalidOid, role_auth_extra::is_superuser, is_superuser(), IsTransactionState(), LOG, member_can_set_role(), newval, NOTICE, PGC_S_TEST, PointerGetDatum(), ReleaseSysCache(), role_auth_extra::roleid, SearchSysCache1(), and source.

◆ check_session_authorization()

bool check_session_authorization ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 802 of file variable.c.

803 {
804  HeapTuple roleTup;
805  Form_pg_authid roleform;
806  Oid roleid;
807  bool is_superuser;
808  role_auth_extra *myextra;
809 
810  /* Do nothing for the boot_val default of NULL */
811  if (*newval == NULL)
812  return true;
813 
814  if (!IsTransactionState())
815  {
816  /*
817  * Can't do catalog lookups, so fail. The result of this is that
818  * session_authorization cannot be set in postgresql.conf, which seems
819  * like a good thing anyway, so we don't work hard to avoid it.
820  */
821  return false;
822  }
823 
824  /*
825  * When source == PGC_S_TEST, we don't throw a hard error for a
826  * nonexistent user name or insufficient privileges, only a NOTICE. See
827  * comments in guc.h.
828  */
829 
830  /* Look up the username */
831  roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(*newval));
832  if (!HeapTupleIsValid(roleTup))
833  {
834  if (source == PGC_S_TEST)
835  {
836  ereport(NOTICE,
837  (errcode(ERRCODE_UNDEFINED_OBJECT),
838  errmsg("role \"%s\" does not exist", *newval)));
839  return true;
840  }
841  GUC_check_errmsg("role \"%s\" does not exist", *newval);
842  return false;
843  }
844 
845  roleform = (Form_pg_authid) GETSTRUCT(roleTup);
846  roleid = roleform->oid;
847  is_superuser = roleform->rolsuper;
848 
849  ReleaseSysCache(roleTup);
850 
851  /*
852  * Only superusers may SET SESSION AUTHORIZATION a role other than itself.
853  * Note that in case of multiple SETs in a single session, the original
854  * authenticated user's superuserness is what matters.
855  */
856  if (roleid != GetAuthenticatedUserId() &&
858  {
859  if (source == PGC_S_TEST)
860  {
861  ereport(NOTICE,
862  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
863  errmsg("permission will be denied to set session authorization \"%s\"",
864  *newval)));
865  return true;
866  }
867  GUC_check_errcode(ERRCODE_INSUFFICIENT_PRIVILEGE);
868  GUC_check_errmsg("permission denied to set session authorization \"%s\"",
869  *newval);
870  return false;
871  }
872 
873  /* Set up "extra" struct for assign_session_authorization to use */
874  myextra = (role_auth_extra *) guc_malloc(LOG, sizeof(role_auth_extra));
875  if (!myextra)
876  return false;
877  myextra->roleid = roleid;
878  myextra->is_superuser = is_superuser;
879  *extra = (void *) myextra;
880 
881  return true;
882 }
Oid GetAuthenticatedUserId(void)
Definition: miscinit.c:583
bool superuser_arg(Oid roleid)
Definition: superuser.c:56

References ereport, errcode(), errmsg(), GetAuthenticatedUserId(), GETSTRUCT, GUC_check_errcode(), GUC_check_errmsg, guc_malloc(), HeapTupleIsValid, role_auth_extra::is_superuser, is_superuser(), IsTransactionState(), LOG, newval, NOTICE, PGC_S_TEST, PointerGetDatum(), ReleaseSysCache(), role_auth_extra::roleid, SearchSysCache1(), source, and superuser_arg().

◆ check_ssl()

bool check_ssl ( bool newval,
void **  extra,
GucSource  source 
)

Definition at line 1226 of file variable.c.

1227 {
1228 #ifndef USE_SSL
1229  if (*newval)
1230  {
1231  GUC_check_errmsg("SSL is not supported by this build");
1232  return false;
1233  }
1234 #endif
1235  return true;
1236 }

References GUC_check_errmsg, and newval.

◆ check_timezone()

bool check_timezone ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 261 of file variable.c.

262 {
263  pg_tz *new_tz;
264  long gmtoffset;
265  char *endptr;
266  double hours;
267 
268  if (pg_strncasecmp(*newval, "interval", 8) == 0)
269  {
270  /*
271  * Support INTERVAL 'foo'. This is for SQL spec compliance, not
272  * because it has any actual real-world usefulness.
273  */
274  const char *valueptr = *newval;
275  char *val;
277 
278  valueptr += 8;
279  while (isspace((unsigned char) *valueptr))
280  valueptr++;
281  if (*valueptr++ != '\'')
282  return false;
283  val = pstrdup(valueptr);
284  /* Check and remove trailing quote */
285  endptr = strchr(val, '\'');
286  if (!endptr || endptr[1] != '\0')
287  {
288  pfree(val);
289  return false;
290  }
291  *endptr = '\0';
292 
293  /*
294  * Try to parse it. XXX an invalid interval format will result in
295  * ereport(ERROR), which is not desirable for GUC. We did what we
296  * could to guard against this in flatten_set_variable_args, but a
297  * string coming in from postgresql.conf might contain anything.
298  */
302  Int32GetDatum(-1)));
303 
304  pfree(val);
305  if (interval->month != 0)
306  {
307  GUC_check_errdetail("Cannot specify months in time zone interval.");
308  pfree(interval);
309  return false;
310  }
311  if (interval->day != 0)
312  {
313  GUC_check_errdetail("Cannot specify days in time zone interval.");
314  pfree(interval);
315  return false;
316  }
317 
318  /* Here we change from SQL to Unix sign convention */
319  gmtoffset = -(interval->time / USECS_PER_SEC);
320  new_tz = pg_tzset_offset(gmtoffset);
321 
322  pfree(interval);
323  }
324  else
325  {
326  /*
327  * Try it as a numeric number of hours (possibly fractional).
328  */
329  hours = strtod(*newval, &endptr);
330  if (endptr != *newval && *endptr == '\0')
331  {
332  /* Here we change from SQL to Unix sign convention */
333  gmtoffset = -hours * SECS_PER_HOUR;
334  new_tz = pg_tzset_offset(gmtoffset);
335  }
336  else
337  {
338  /*
339  * Otherwise assume it is a timezone name, and try to load it.
340  */
341  new_tz = pg_tzset(*newval);
342 
343  if (!new_tz)
344  {
345  /* Doesn't seem to be any great value in errdetail here */
346  return false;
347  }
348 
349  if (!pg_tz_acceptable(new_tz))
350  {
351  GUC_check_errmsg("time zone \"%s\" appears to use leap seconds",
352  *newval);
353  GUC_check_errdetail("PostgreSQL does not support leap seconds.");
354  return false;
355  }
356  }
357  }
358 
359  /* Test for failure in pg_tzset_offset, which we assume is out-of-range */
360  if (!new_tz)
361  {
362  GUC_check_errdetail("UTC timezone offset is out of range.");
363  return false;
364  }
365 
366  /*
367  * Pass back data for assign_timezone to use
368  */
369  *extra = guc_malloc(LOG, sizeof(pg_tz *));
370  if (!*extra)
371  return false;
372  *((pg_tz **) *extra) = new_tz;
373 
374  return true;
375 }
Datum interval_in(PG_FUNCTION_ARGS)
Definition: timestamp.c:900
#define SECS_PER_HOUR
Definition: timestamp.h:127
#define USECS_PER_SEC
Definition: timestamp.h:134
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:646
long val
Definition: informix.c:670
pg_tz * pg_tzset_offset(long gmtoffset)
Definition: pgtz.c:320
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static Interval * DatumGetIntervalP(Datum X)
Definition: timestamp.h:40

References CStringGetDatum(), DatumGetIntervalP(), DirectFunctionCall3, GUC_check_errdetail, GUC_check_errmsg, guc_malloc(), Int32GetDatum(), interval_in(), InvalidOid, LOG, interval::month, newval, ObjectIdGetDatum(), pfree(), pg_strncasecmp(), pg_tz_acceptable(), pg_tzset(), pg_tzset_offset(), pstrdup(), SECS_PER_HOUR, interval::time, USECS_PER_SEC, and val.

◆ check_timezone_abbreviations()

bool check_timezone_abbreviations ( char **  newval,
void **  extra,
GucSource  source 
)

Definition at line 485 of file variable.c.

486 {
487  /*
488  * The boot_val for timezone_abbreviations is NULL. When we see that we
489  * just do nothing. If the value isn't overridden from the config file
490  * then pg_timezone_abbrev_initialize() will eventually replace it with
491  * "Default". This hack has two purposes: to avoid wasting cycles loading
492  * values that might soon be overridden from the config file, and to avoid
493  * trying to read the timezone abbrev files during InitializeGUCOptions().
494  * The latter doesn't work in an EXEC_BACKEND subprocess because
495  * my_exec_path hasn't been set yet and so we can't locate PGSHAREDIR.
496  */
497  if (*newval == NULL)
498  {
500  return true;
501  }
502 
503  /* OK, load the file and produce a guc_malloc'd TimeZoneAbbrevTable */
504  *extra = load_tzoffsets(*newval);
505 
506  /* tzparser.c returns NULL on failure, reporting via GUC_check_errmsg */
507  if (!*extra)
508  return false;
509 
510  return true;
511 }
@ PGC_S_DEFAULT
Definition: guc.h:109
Assert(fmt[strlen(fmt) - 1] !='\n')
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
Definition: tzparser.c:447

References Assert(), load_tzoffsets(), newval, PGC_S_DEFAULT, and source.

◆ check_transaction_deferrable()

bool check_transaction_deferrable ( bool newval,
void **  extra,
GucSource  source 
)

Definition at line 620 of file variable.c.

621 {
622  if (IsSubTransaction())
623  {
624  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
625  GUC_check_errmsg("SET TRANSACTION [NOT] DEFERRABLE cannot be called within a subtransaction");
626  return false;
627  }
628  if (FirstSnapshotSet)
629  {
630  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
631  GUC_check_errmsg("SET TRANSACTION [NOT] DEFERRABLE must be called before any query");
632  return false;
633  }
634 
635  return true;
636 }
bool FirstSnapshotSet
Definition: snapmgr.c:135
bool IsSubTransaction(void)
Definition: xact.c:5001

References FirstSnapshotSet, GUC_check_errcode(), GUC_check_errmsg, and IsSubTransaction().

◆ check_transaction_isolation()

bool check_transaction_isolation ( int *  newval,
void **  extra,
GucSource  source 
)

Definition at line 583 of file variable.c.

584 {
585  int newXactIsoLevel = *newval;
586 
587  if (newXactIsoLevel != XactIsoLevel && IsTransactionState())
588  {
589  if (FirstSnapshotSet)
590  {
591  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
592  GUC_check_errmsg("SET TRANSACTION ISOLATION LEVEL must be called before any query");
593  return false;
594  }
595  /* We ignore a subtransaction setting it to the existing value. */
596  if (IsSubTransaction())
597  {
598  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
599  GUC_check_errmsg("SET TRANSACTION ISOLATION LEVEL must not be called in a subtransaction");
600  return false;
601  }
602  /* Can't go to serializable mode while recovery is still active */
603  if (newXactIsoLevel == XACT_SERIALIZABLE && RecoveryInProgress())
604  {
605  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
606  GUC_check_errmsg("cannot use serializable mode in a hot standby");
607  GUC_check_errhint("You can use REPEATABLE READ instead.");
608  return false;
609  }
610  }
611 
612  return true;
613 }
#define GUC_check_errhint
Definition: guc.h:451
int XactIsoLevel
Definition: xact.c:77
#define XACT_SERIALIZABLE
Definition: xact.h:39
bool RecoveryInProgress(void)
Definition: xlog.c:6201

References FirstSnapshotSet, GUC_check_errcode(), GUC_check_errhint, GUC_check_errmsg, IsSubTransaction(), IsTransactionState(), newval, RecoveryInProgress(), XACT_SERIALIZABLE, and XactIsoLevel.

◆ check_transaction_read_only()

bool check_transaction_read_only ( bool newval,
void **  extra,
GucSource  source 
)

Definition at line 544 of file variable.c.

545 {
547  {
548  /* Can't go to r/w mode inside a r/o transaction */
549  if (IsSubTransaction())
550  {
551  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
552  GUC_check_errmsg("cannot set transaction read-write mode inside a read-only transaction");
553  return false;
554  }
555  /* Top level transaction can't change to r/w after first snapshot. */
556  if (FirstSnapshotSet)
557  {
558  GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
559  GUC_check_errmsg("transaction read-write mode must be set before any query");
560  return false;
561  }
562  /* Can't go to r/w mode while recovery is still active */
563  if (RecoveryInProgress())
564  {
565  GUC_check_errcode(ERRCODE_FEATURE_NOT_SUPPORTED);
566  GUC_check_errmsg("cannot set transaction read-write mode during recovery");
567  return false;
568  }
569  }
570 
571  return true;
572 }
bool XactReadOnly
Definition: xact.c:80

References FirstSnapshotSet, GUC_check_errcode(), GUC_check_errmsg, InitializingParallelWorker, IsSubTransaction(), IsTransactionState(), newval, RecoveryInProgress(), and XactReadOnly.

◆ show_data_directory_mode()

const char* show_data_directory_mode ( void  )

Definition at line 1133 of file variable.c.

1134 {
1135  static char buf[12];
1136 
1137  snprintf(buf, sizeof(buf), "%04o", data_directory_mode);
1138  return buf;
1139 }
int data_directory_mode
Definition: globals.c:74
static char * buf
Definition: pg_test_fsync.c:73
#define snprintf
Definition: port.h:238

References buf, data_directory_mode, and snprintf.

◆ show_log_file_mode()

const char* show_log_file_mode ( void  )

Definition at line 1145 of file variable.c.

1146 {
1147  static char buf[12];
1148 
1149  snprintf(buf, sizeof(buf), "%04o", Log_file_mode);
1150  return buf;
1151 }
int Log_file_mode
Definition: syslogger.c:76

References buf, Log_file_mode, and snprintf.

◆ show_log_timezone()

const char* show_log_timezone ( void  )

Definition at line 463 of file variable.c.

464 {
465  const char *tzn;
466 
467  /* Always show the zone's canonical name */
469 
470  if (tzn != NULL)
471  return tzn;
472 
473  return "unknown";
474 }
const char * pg_get_timezone_name(pg_tz *tz)
Definition: localtime.c:1875

References log_timezone, and pg_get_timezone_name().

◆ show_random_seed()

const char* show_random_seed ( void  )

Definition at line 669 of file variable.c.

670 {
671  return "unavailable";
672 }

◆ show_role()

const char* show_role ( void  )

Definition at line 1003 of file variable.c.

1004 {
1005  /*
1006  * Check whether SET ROLE is active; if not return "none". This is a
1007  * kluge to deal with the fact that SET SESSION AUTHORIZATION logically
1008  * resets SET ROLE to NONE, but we cannot set the GUC role variable from
1009  * assign_session_authorization (because we haven't got enough info to
1010  * call set_config_option).
1011  */
1012  if (!OidIsValid(GetCurrentRoleId()))
1013  return "none";
1014 
1015  /* Otherwise we can just use the GUC string */
1016  return role_string ? role_string : "none";
1017 }
char * role_string
Definition: guc_tables.c:618
#define OidIsValid(objectId)
Definition: c.h:762
Oid GetCurrentRoleId(void)
Definition: miscinit.c:924

References GetCurrentRoleId(), OidIsValid, and role_string.

◆ show_timezone()

const char* show_timezone ( void  )

Definition at line 390 of file variable.c.

391 {
392  const char *tzn;
393 
394  /* Always show the zone's canonical name */
396 
397  if (tzn != NULL)
398  return tzn;
399 
400  return "unknown";
401 }

References pg_get_timezone_name(), and session_timezone.

◆ show_unix_socket_permissions()

const char* show_unix_socket_permissions ( void  )

Definition at line 1157 of file variable.c.

1158 {
1159  static char buf[12];
1160 
1161  snprintf(buf, sizeof(buf), "%04o", Unix_socket_permissions);
1162  return buf;
1163 }
int Unix_socket_permissions
Definition: pqcomm.c:105

References buf, snprintf, and Unix_socket_permissions.

Variable Documentation

◆ role_string

char* role_string
extern

Definition at line 618 of file guc_tables.c.

Referenced by show_role().