in src/main/java/com/google/cloud/spanner/pgadapter/metadata/OptionsMetadata.java [1220:1467]
private CommandLine buildOptions(String[] args) {
Options options = new Options();
options.addOption(
OPTION_SERVER_PORT, "server-port", true, "This proxy's port number (Default 5432).");
options.addOption(
null,
OPTION_SOCKET_DIR,
true,
String.format(
"This proxy's domain socket directory (Default %s). "
+ "Domain sockets are disabled by default on Windows. Set this property to a non-empty value on Windows to enable domain sockets. "
+ "Set this property to the empty string on other operating systems to disable domain sockets.",
DEFAULT_SOCKET_DIR));
options.addOption(
null,
OPTION_MAX_BACKLOG,
true,
String.format(
"Maximum queue length of incoming connections. Defaults to %d.", DEFAULT_MAX_BACKLOG));
options.addOption(
OPTION_PROJECT_ID,
"project",
true,
"The id of the GCP project wherein lives the Spanner database.");
options.addOption(
OPTION_INSTANCE_ID,
"instance",
true,
"The id of the Spanner instance within the GCP project.");
options.addOption(
OPTION_DATABASE_NAME,
"database",
true,
"The default Spanner database within the GCP project to use. "
+ "If specified, PGAdapter will always connect to this database. "
+ "Any database name in the connection request from the client will be ignored. "
+ "Omit this option to be able to connect to different databases using a single "
+ "PGAdapter instance.");
options.addOption(
OPTION_CREDENTIALS_FILE,
"credentials-file",
true,
"The full path of the file location wherein lives the GCP credentials."
+ "If not specified, will try to read application default credentials.");
options.addOption(
OPTION_SPANNER_ENDPOINT, "spanner-endpoint", true, "The Cloud Spanner service endpoint.");
options.addOption(
OPTION_AUTHENTICATE,
"authenticate",
false,
"Whether you wish the proxy to perform an authentication step.");
options.addOption(null, OPTION_ENABLE_OPEN_TELEMETRY, false, "Enable OpenTelemetry tracing.");
options.addOption(
null, OPTION_ENABLE_OPEN_TELEMETRY_METRICS, false, "Enable OpenTelemetry metrics.");
options.addOption(
null,
OPTION_OPEN_TELEMETRY_TRACE_RATIO,
true,
"OpenTelemetry trace sampling ration. Value must be in the range [0.0, 1.0].");
options.addOption(
null,
OPTION_ENABLE_END_TO_END_TRACING,
false,
"Enable end-to-end tracing (true/false) to generate traces for both the time "
+ "that is spent in the client, as well as time that is spent in the Spanner server. "
+ "Server side traces can only be exported to Google Cloud Trace, so to see end to end traces, "
+ "the application should configure an exporter that exports the traces to Google Cloud Trace.");
options.addOption(
OPTION_SSL,
"sslmode",
true,
"Enable SSL connections for this server. SSL only works if you "
+ "have also configured a keystore for the Java Virtual Machine.\n"
+ "See https://github.com/GoogleCloudPlatform/pgadapter/blob/postgresql-dialect/docs/ssl.md "
+ "for more information.");
options.addOption(
null,
OPTION_DISABLE_AUTO_DETECT_CLIENT,
false,
"This option turns off automatic detection of well-known clients. "
+ "Use this option if you do not want PGAdapter to automatically apply query "
+ "replacements based on the client that is connected to PGAdapter.");
options.addOption(
null,
OPTION_DISABLE_DEFAULT_LOCAL_STATEMENTS,
false,
"This option turns off translations for commonly used statements that are "
+ "currently not supported by Cloud Spanner (e.g. `select current_schema`). "
+ "Use this option if you do not want PGAdapter to automatically apply query "
+ "replacements for these statements.");
options.addOption(
null,
OPTION_DISABLE_PG_CATALOG_REPLACEMENTS,
false,
"This option turns off automatic replacement of pg_catalog tables with "
+ "common table expressions for pg_catalog tables that are not yet supported by "
+ "Cloud Spanner. Use this option if you do not want PGAdapter to automatically apply "
+ "replacements for pg_catalog tables.");
options.addOption(
OPTION_PSQL_MODE,
"psql-mode",
false,
"DEPRECATED: PGAdapter will automatically detect connections from psql."
+ " This option turns on PSQL mode. This mode allows better compatibility to PSQL, with an"
+ " added performance cost. PSQL mode is implemented using predefined dynamic matchers"
+ " and as such cannot be used with the option -j. This mode should not be used for"
+ " production, and we do not guarantee its functionality beyond the basics.");
options.addOption(
OPTION_DDL_TRANSACTION_MODE,
"ddl-transaction-mode",
true,
String.format(
"Sets the way PGAdapter should handle DDL statements in implicit and explicit "
+ "transactions. Cloud Spanner does not support DDL transactions. The possible modes "
+ "are:\n"
+ "%s: Only allows single DDL statements outside implicit and explicit transactions.\n"
+ "%s: Allows batches that contain only DDL statements. "
+ "Does not allow mixed batches of DDL and other statements, or DDL statements in transactions.\n"
+ "%s: Allows mixed batches of DDL and other statements. "
+ "Automatically commits the implicit transaction when a DDL statement is encountered in a batch. "
+ "DDL statements in explicit transactions are not allowed.\n"
+ "%s: Allows mixed batches of DDL and other statements. "
+ "Automatically commits the current transaction when a DDL statement is encountered.",
DdlTransactionMode.Single,
DdlTransactionMode.Batch,
DdlTransactionMode.AutocommitImplicitTransaction,
DdlTransactionMode.AutocommitExplicitTransaction));
options.addOption(
OPTION_JDBC_MODE,
"jdbc-mode",
false,
"DEPRECATED: PGAdapter will automatically detect connections from JDBC. "
+ "This option turns on JDBC mode. This mode allows better compatibility with the "
+ "PostgreSQL JDBC driver. It will automatically inspect incoming queries to look for "
+ "known JDBC metadata queries, and replace these with queries that are compatible with "
+ "Cloud Spanner. JDBC mode is implemented using predefined fixed matchers and should "
+ "not be used in combination with options -q (psql mode) or -j (custom matchers). It "
+ "should be enabled if you intend to connect to PGAdapter using the PostgreSQL JDBC "
+ "driver.");
options.addOption(
OPTION_COMMAND_METADATA_FILE,
"options-metadata",
true,
"This option specifies the full path of the file containing the metadata specifications for"
+ " custom dynamic matchers. Each item in this matcher will create a runtime-generated"
+ " command which will translate incoming commands into whatever back-end SQL is"
+ " desired. This feature allows re-writing queries that are outside the user's control"
+ " (e.g: issued by client libraries and / or tools) and are not currently supported by"
+ " the backend with equivalent supported queries, but comes at a performance cost."
+ " This option cannot be used with option -q.");
options.addOption(OPTION_HELP, "help", false, "Print help.");
options.addOption(
OPTION_BINARY_FORMAT,
"force-binary-format",
false,
"DEPRECATED: This option violates the PostgreSQL wire-protocol.\n"
+ "Force the server to send data back in binary PostgreSQL format when no specific "
+ "format has been requested. The PostgreSQL wire protocol specifies that the server "
+ "should send data in text format in those cases. This setting overrides this default "
+ "and should be used with caution, for example for testing purposes, as clients might "
+ "not accept this behavior. This setting only affects query results in extended query "
+ "mode. Queries in simple query mode will always return results in text format. If "
+ "you do not know what extended query mode and simple query mode is, then you should "
+ "probably not be using this setting.");
options.addOption(
OPTION_JDBC_PROPERTIES,
"jdbc-properties",
true,
"This option specifies additional properties that will be used with the JDBC connection. "
+ "They should be in the format <key1>=<value1>;<key2>=<value2>;...");
options.addOption(
OPTION_DISABLE_LOCALHOST_CHECK,
"disable-localhost-check-for-docker",
false,
"By default, for safety, PG Adapter only accepts connections from localhost. "
+ "When running inside docker however the docker host IP will not show as localhost. "
+ "Instead, set this flag and restrict connections from localhost using docker, e.g: "
+ "`-p 127.0.0.1:5432:5432`");
options.addOption(
OPTION_SERVER_VERSION,
"server-version",
true,
"This option specifies what server_version PG Adapter should claim to be. If not specified "
+ " it will default to version "
+ DEFAULT_SERVER_VERSION
+ ".\nBe careful when changing this value. Unless otherwise specified, all clients and drivers that "
+ "have been tested with PGAdapter have been tested using the default value for this option. Changing "
+ "the value of this option could cause a client or driver to alter its behavior and cause unexpected "
+ "errors when used with PGAdapter.");
options.addOption(
OPTION_LOG_GRPC_MESSAGES,
"log-grpc-messages",
false,
"Logs all gRPC messages that are sent by PGAdapter to Spanner to the default log handler (stdout).\n"
+ "This option should only be enabled to debug problems and/or to determine exactly which gRPC messages\n"
+ "are being sent to Spanner. Enabling this in production will cause a large number of messages to be logged.");
options.addOption(
OPTION_ALLOW_SHUTDOWN_STATEMENT,
"allow-shutdown-statement",
false,
"Allows the proxy server to be shutdown by executing the SHUTDOWN [SMART | FAST | IMMEDIATE] statement.");
options.addOption(
OPTION_INTERNAL_DEBUG_MODE,
"internal-debug-mode",
false,
"-- ONLY USE FOR INTERNAL DEBUGGING -- This option only intended for INTERNAL debugging. It will "
+ "instruct the server to keep track of all messages it receives.\n"
+ "You should not enable this option unless you want to debug PGAdapter, for example if"
+ "you are developing a new feature for PGAdapter that you want to test.\n"
+ "This option will NOT enable any additional LOGGING.\n"
+ "You should not enable this option if you are just trying out PGAdapter.");
options.addOption(
OPTION_SKIP_INTERNAL_DEBUG_MODE_WARNING,
"skip-internal-debug-mode-warning",
false,
"Disables the warning that is printed when internal debug mode is enabled.");
options.addOption(
OPTION_DEBUG_MODE,
"debug-mode",
false,
"-- DEPRECATED -- This option currently does not have any effect.\n"
+ "This option used to enable the internal debug mode for PGAdapter.\n"
+ "Use the option -internal_debug to enable internal debug mode.\n"
+ "You most probably do not want to turn internal debug mode on. It is only intended for\n"
+ "internal test cases in PGAdapter that need to verify that it receives the correct \n"
+ "wire-protocol messages.");
options.addOption(
OPTION_LEGACY_LOGGING,
"enable_legacy_logging",
false,
"Enables legacy logging using the default java.util.logging configuration.\n"
+ "This sends all log output to stderr.");
CommandLineParser parser = new DefaultParser();
HelpFormatter help = new HelpFormatter();
help.setWidth(120);
try {
CommandLine commandLine = parser.parse(options, args);
if (commandLine.hasOption(OPTION_HELP)) {
help.printHelp(CLI_ARGS, options);
System.exit(0);
}
printDeprecatedWarnings(commandLine);
return commandLine;
} catch (ParseException e) {
help.printHelp(CLI_ARGS, options);
throw new IllegalArgumentException(e.getMessage());
}
}