Skip to content

Commit f970d52

Browse files
author
Asif Rehman
committed
adding a switch to initdb to select between postgres, oracle compatibility modes
1 parent 4254750 commit f970d52

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@
716716
# default configuration for text search
717717
#default_text_search_config = 'pg_catalog.simple'
718718

719+
# default configuration for compatibility mode
720+
#compatible_mode = postgres # postgres, oracle
721+
719722
# - Shared Library Preloading -
720723

721724
#local_preload_libraries = ''

src/bin/initdb/initdb.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ static const char *const auth_methods_local[] = {
115115
NULL
116116
};
117117

118+
/*
119+
* Compatibility options. Ideally this would be in a .h file, but it
120+
* hardly seems worth the trouble.
121+
*/
122+
static const char *const compat_options[] = {
123+
"postgres", "oracle", NULL
124+
};
125+
118126
/*
119127
* these values are passed in by makefile defines
120128
*/
@@ -147,6 +155,7 @@ static bool data_checksums = false;
147155
static char *xlog_dir = NULL;
148156
static char *str_wal_segment_size_mb = NULL;
149157
static int wal_segment_size_mb;
158+
static char *compatible_mode = NULL;
150159

151160

152161
/* internal vars */
@@ -277,6 +286,8 @@ static void check_locale_name(int category, const char *locale,
277286
char **canonname);
278287
static bool check_locale_encoding(const char *locale, int encoding);
279288
static void setlocales(void);
289+
static void check_compatible_mode(const char *option,
290+
const char *const *valid_options);
280291
static void usage(const char *progname);
281292
void setup_pgdata(void);
282293
void setup_bin_paths(const char *argv0);
@@ -1211,6 +1222,15 @@ setup_config(void)
12111222
"log_file_mode = 0640");
12121223
}
12131224

1225+
/* set compatibility mode */
1226+
if (compatible_mode != NULL)
1227+
{
1228+
check_compatible_mode(compatible_mode, compat_options);
1229+
conflines = replace_token(conflines,
1230+
"#compatible_mode = postgres",
1231+
"compatible_mode = oracle");
1232+
}
1233+
12141234
snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data);
12151235

12161236
writefile(path, conflines);
@@ -2263,6 +2283,22 @@ setlocales(void)
22632283
#endif
22642284
}
22652285

2286+
static void
2287+
check_compatible_mode(const char *option, const char *const *valid_options)
2288+
{
2289+
const char *const *p;
2290+
2291+
for (p = valid_options; *p; p++)
2292+
{
2293+
if (pg_strcasecmp(option, *p) == 0)
2294+
return;
2295+
}
2296+
2297+
pg_log_error("invalid option specified \"%s\" for compatible-mode",
2298+
option);
2299+
exit(1);
2300+
}
2301+
22662302
/*
22672303
* print help text
22682304
*/
@@ -2293,6 +2329,7 @@ usage(const char *progname)
22932329
printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
22942330
printf(_(" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
22952331
printf(_(" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
2332+
printf(_(" -c, --compatible-mode compatibility mode (postgres (default), oracle)\n"));
22962333
printf(_("\nLess commonly used options:\n"));
22972334
printf(_(" -d, --debug generate lots of debugging output\n"));
22982335
printf(_(" --discard-caches set debug_discard_caches=1\n"));
@@ -2980,6 +3017,7 @@ main(int argc, char *argv[])
29803017
{"data-checksums", no_argument, NULL, 'k'},
29813018
{"allow-group-access", no_argument, NULL, 'g'},
29823019
{"discard-caches", no_argument, NULL, 14},
3020+
{"compatible-mode", required_argument, NULL, 'c'},
29833021
{NULL, 0, NULL, 0}
29843022
};
29853023

@@ -3021,7 +3059,7 @@ main(int argc, char *argv[])
30213059

30223060
/* process command-line options */
30233061

3024-
while ((c = getopt_long(argc, argv, "A:dD:E:gkL:nNsST:U:WX:", long_options, &option_index)) != -1)
3062+
while ((c = getopt_long(argc, argv, "A:dD:E:gkL:nNsST:U:WX:c:", long_options, &option_index)) != -1)
30253063
{
30263064
switch (c)
30273065
{
@@ -3126,6 +3164,9 @@ main(int argc, char *argv[])
31263164
extra_options,
31273165
"-c debug_discard_caches=1");
31283166
break;
3167+
case 'c':
3168+
compatible_mode = pg_strdup(optarg);
3169+
break;
31293170
default:
31303171
/* getopt_long already emitted a complaint */
31313172
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),

0 commit comments

Comments
 (0)