summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2014-12-16 07:59:28 +0000
committerPavan Deolasee2015-04-15 05:46:42 +0000
commita31269284f8abd9990cfa9d3226dc2a13ce6accb (patch)
tree2b75ade8bf437d5447296e23c98bfc3cada53d1a
parent3d8af6f439a0bdda6bd01bcc6b59041809ae5f41 (diff)
Add a new "minimal" option to "prepare" command of pgxc_ctl.
If this option is provided then prepare will create a template config file suitable for setting up a localhost-only XL cluster of GTM, 1 GTM proxy, 2 Coordinators and 2 Datanodes, all running locally. There is also a "complete" option, which is also the default, to create a more complete template suitable for multi-node setup
-rw-r--r--contrib/pgxc_ctl/config.c23
-rw-r--r--contrib/pgxc_ctl/config.h1
-rw-r--r--contrib/pgxc_ctl/do_command.c46
-rw-r--r--contrib/pgxc_ctl/pgxc_ctl_bash.c274
-rw-r--r--doc-xc/src/sgml/pgxc_ctl-ref.sgmlin19
5 files changed, 325 insertions, 38 deletions
diff --git a/contrib/pgxc_ctl/config.c b/contrib/pgxc_ctl/config.c
index aa29b1486d..81edb6bdcc 100644
--- a/contrib/pgxc_ctl/config.c
+++ b/contrib/pgxc_ctl/config.c
@@ -30,8 +30,6 @@
#include "utils.h"
#include "do_shell.h"
-extern char *pgxc_ctl_conf_prototype[];
-
static void addServer(char **name);
static void verifyResource(void);
@@ -203,27 +201,6 @@ void read_selected_vars(FILE *conf, char *selectThis[])
}
/*
- * Build the configuraiton file prototype.
- */
-void install_conf_prototype(char *path)
-{
- char cmd[MAXPATH+1];
- FILE *pgxc_config_proto = fopen(path, "w");
- int i;
-
- if (!pgxc_config_proto)
- {
- elog(ERROR, "ERROR Could not open configuration prototype to %s. %s\n", path, strerror(errno));
- return;
- }
- for (i = 0; pgxc_ctl_conf_prototype[i]; i++)
- fprintf(pgxc_config_proto, "%s\n", pgxc_ctl_conf_prototype[i]);
- fclose(pgxc_config_proto);
- snprintf(cmd, MAXPATH, "chmod +x %s", path);
- system(cmd);
-}
-
-/*
* Get all the servers --> VAR_allServers
*/
static void addServer(char **name)
diff --git a/contrib/pgxc_ctl/config.h b/contrib/pgxc_ctl/config.h
index 039f953138..543070b91c 100644
--- a/contrib/pgxc_ctl/config.h
+++ b/contrib/pgxc_ctl/config.h
@@ -23,7 +23,6 @@ typedef enum NodeType {
NodeType_SERVER} NodeType;
void read_vars(FILE *conf);
-void install_conf_prototype(char *path);
void check_configuration(void);
void read_selected_vars(FILE *conf, char *selectThis[]);
char *get_word(char *line, char **token);
diff --git a/contrib/pgxc_ctl/do_command.c b/contrib/pgxc_ctl/do_command.c
index 715b31fac0..9201d8c035 100644
--- a/contrib/pgxc_ctl/do_command.c
+++ b/contrib/pgxc_ctl/do_command.c
@@ -39,6 +39,7 @@
#include "monitor.h"
extern char *pgxc_ctl_conf_prototype[];
+extern char *pgxc_ctl_conf_prototype_minimal[];
#define Exit(c) exit(myWEXITSTATUS(c))
#define GetToken() (line = get_word(line, &token))
@@ -62,18 +63,24 @@ static void stop_all(char *immediate);
static int show_Resource(char *datanodeName, char *databasename, char *username);
static void do_show_help(char *line);
+typedef enum ConfigType
+{
+ CONFIG_MINIMAL,
+ CONFIG_COMPLETE
+} ConfigType;
+
static void do_echo_command(char * line)
{
printf("do_echo_command\n");
}
-static void do_prepareConfFile(char *Path)
+static void do_prepareConfFile(char *Path, ConfigType config_type)
{
char *path = NULL;
FILE *conf;
int ii;
+ char **my_pgxc_conf_prototype;
-
if (Path)
path = Path;
else
@@ -92,9 +99,15 @@ static void do_prepareConfFile(char *Path)
elog(ERROR, "ERROR: Could not open the configuration file \"%s\", %s.\n", path, strerror(errno));
return;
}
- for (ii = 0; pgxc_ctl_conf_prototype[ii]; ii++)
+
+ if (config_type == CONFIG_MINIMAL)
+ my_pgxc_conf_prototype = pgxc_ctl_conf_prototype_minimal;
+ else
+ my_pgxc_conf_prototype = pgxc_ctl_conf_prototype;
+
+ for (ii = 0; my_pgxc_conf_prototype[ii]; ii++)
{
- fprintf(conf, "%s\n", pgxc_ctl_conf_prototype[ii]);
+ fprintf(conf, "%s\n", my_pgxc_conf_prototype[ii]);
}
fclose(conf);
return;
@@ -2341,14 +2354,23 @@ int do_singleLine(char *buf, char *wkline)
}
else if (TestToken("prepare"))
{
- if (GetToken() == NULL)
- do_prepareConfFile(NULL);
- if (!TestToken("config"))
- do_prepareConfFile(token);
- else if (GetToken() == NULL)
- do_prepareConfFile(NULL);
- else
- do_prepareConfFile(token);
+ char *config_path = NULL;
+ ConfigType config_type = CONFIG_COMPLETE;
+
+ if (GetToken() != NULL)
+ {
+ if (TestToken("config"))
+ GetToken();
+
+ if (TestToken("minimal"))
+ config_type = CONFIG_MINIMAL;
+ else if (TestToken("complete"))
+ config_type = CONFIG_COMPLETE;
+ else if (token)
+ config_path = strdup(token);
+ }
+
+ do_prepareConfFile(config_path, config_type);
return 0;
}
else if (TestToken("kill"))
diff --git a/contrib/pgxc_ctl/pgxc_ctl_bash.c b/contrib/pgxc_ctl/pgxc_ctl_bash.c
index d3acfc1454..67997045ac 100644
--- a/contrib/pgxc_ctl/pgxc_ctl_bash.c
+++ b/contrib/pgxc_ctl/pgxc_ctl_bash.c
@@ -352,7 +352,6 @@ NULL
* It should be self descripting. Can be extracted to your pgxc_ctl
* work directory with 'prepare config' command.
*/
-
char *pgxc_ctl_conf_prototype[] = {
"#!/bin/bash",
"#",
@@ -407,7 +406,7 @@ char *pgxc_ctl_conf_prototype[] = {
"pgxcInstallDir=$HOME/pgxc",
"#---- OVERALL -----------------------------------------------------------------------------",
"#",
-"pgxcOwner=koichi # owner of the Postgres-XC databaseo cluster. Here, we use this",
+"pgxcOwner=$USER # owner of the Postgres-XC databaseo cluster. Here, we use this",
" # both as linus user and database user. This must be",
" # the super user of each coordinator and datanode.",
"pgxcUser=$pgxcOwner # OS user of Postgres-XC owner",
@@ -680,3 +679,274 @@ char *pgxc_ctl_conf_prototype[] = {
"#=============<< End of future extension demonistration >> ========================================================",
NULL
};
+
+char *pgxc_ctl_conf_prototype_minimal[] = {
+"#!/bin/bash",
+"#",
+"# Postgres-XC Configuration file for pgxc_ctl utility. ",
+"#",
+"# Configuration file can be specified as -c option from pgxc_ctl command. Default is",
+"# $PGXC_CTL_HOME/pgxc_ctl.org.",
+"#",
+"# This is bash script so you can make any addition for your convenience to configure",
+"# your Postgres-XC cluster.",
+"#",
+"# Please understand that pgxc_ctl provides only a subset of configuration which pgxc_ctl",
+"# provide. Here's several several assumptions/restrictions pgxc_ctl depends on.",
+"#",
+"# 1) All the resources of pgxc nodes has to be owned by the same user. Same user means",
+"# user with the same user name. User ID may be different from server to server.",
+"# This must be specified as a variable $pgxcOwner.",
+"#",
+"# 2) All the servers must be reacheable via ssh without password. It is highly recommended",
+"# to setup key-based authentication among all the servers.",
+"#",
+"# 3) All the databases in coordinator/datanode has at least one same superuser. Pgxc_ctl",
+"# uses this user to connect to coordinators and datanodes. Again, no password should",
+"# be used to connect. You have many options to do this, pg_hba.conf, pg_ident.conf and",
+"# others. Pgxc_ctl provides a way to configure pg_hba.conf but not pg_ident.conf. This",
+"# will be implemented in the later releases.",
+"#",
+"# 4) Gtm master and slave can have different port to listen, while coordinator and datanode",
+"# slave should be assigned the same port number as master.",
+"#",
+"# 5) Port nuber of a coordinator slave must be the same as its master.",
+"#",
+"# 6) Master and slave are connected using synchronous replication. Asynchronous replication",
+"# have slight (almost none) chance to bring total cluster into inconsistent state.",
+"# This chance is very low and may be negligible. Support of asynchronous replication",
+"# may be supported in the later release.",
+"#",
+"# 7) Each coordinator and datanode can have only one slave each. Cascaded replication and",
+"# multiple slave are not supported in the current pgxc_ctl.",
+"#",
+"# 8) Killing nodes may end up with IPC resource leak, such as semafor and shared memory.",
+"# Only listening port (socket) will be cleaned with clean command.",
+"#",
+"# 9) Backup and restore are not supported in pgxc_ctl at present. This is a big task and",
+"# may need considerable resource.",
+"#",
+"#========================================================================================",
+"#",
+"#",
+"# pgxcInstallDir variable is needed if you invoke \"deploy\" command from pgxc_ctl utility.",
+"# If don't you don't need this variable.",
+"pgxcInstallDir=$HOME/pgxc",
+"#---- OVERALL -----------------------------------------------------------------------------",
+"#",
+"pgxcOwner=$USER # owner of the Postgres-XC databaseo cluster. Here, we use this",
+" # both as linus user and database user. This must be",
+" # the super user of each coordinator and datanode.",
+"pgxcUser=$pgxcOwner # OS user of Postgres-XC owner",
+"",
+"tmpDir=/tmp # temporary dir used in XC servers",
+"localTmpDir=$tmpDir # temporary dir used here locally",
+"",
+"configBackup=n # If you want config file backup, specify y to this value.",
+"configBackupHost=pgxc-linker # host to backup config file",
+"configBackupDir=$HOME/pgxc # Backup directory",
+"configBackupFile=pgxc_ctl.bak # Backup file name --> Need to synchronize when original changed.",
+"",
+"dataDirRoot=$HOME/DATA/pgxl/nodes",
+"",
+"#---- GTM ------------------------------------------------------------------------------------",
+"",
+"# GTM is mandatory. You must have at least (and only) one GTM master in your Postgres-XC cluster.",
+"# If GTM crashes and you need to reconfigure it, you can do it by pgxc_update_gtm command to update",
+"# GTM master with others. Of course, we provide pgxc_remove_gtm command to remove it. This command",
+"# will not stop the current GTM. It is up to the operator.",
+"",
+"#---- Overall -------",
+"gtmName=gtm",
+"",
+"#---- GTM Master -----------------------------------------------",
+"",
+"#---- Overall ----",
+"gtmMasterServer=localhost",
+"gtmMasterPort=20001",
+"gtmMasterDir=$dataDirRoot/gtm",
+"",
+"#---- Configuration ---",
+"gtmExtraConfig=none # Will be added gtm.conf for both Master and Slave (done at initilization only)",
+"gtmMasterSpecificExtraConfig=none # Will be added to Master's gtm.conf (done at initialization only)",
+"",
+"#---- GTM Slave -----------------------------------------------",
+"",
+"# Because GTM is a key component to maintain database consistency, you may want to configure GTM slave",
+"# for backup.",
+"",
+"#---- Overall ------",
+"gtmSlave=n # Specify y if you configure GTM Slave. Otherwise, GTM slave will not be configured and",
+" # all the following variables will be reset.",
+"gtmSlaveName=gtmSlave",
+"gtmSlaveServer=localhost # value none means GTM slave is not available. Give none if you don't configure GTM Slave.",
+"gtmSlavePort=20002 # Not used if you don't configure GTM slave.",
+"gtmSlaveDir=$dataDirRoot/gtm_slv # Not used if you don't configure GTM slave.",
+"# Please note that when you have GTM failover, then there will be no slave available until you configure the slave",
+"# again. (pgxc_add_gtm_slave function will handle it)",
+"",
+"#---- Configuration ----",
+"#gtmSlaveSpecificExtraConfig=none # Will be added to Slave's gtm.conf (done at initialization only)",
+"",
+"#---- GTM Proxy -------------------------------------------------------------------------------------------------------",
+"# GTM proxy will be selected based upon which server each component runs on.",
+"# When fails over to the slave, the slave inherits its master's gtm proxy. It should be",
+"# reconfigured based upon the new location.",
+"#",
+"# To do so, slave should be restarted. So pg_ctl promote -> (edit postgresql.conf and recovery.conf) -> pg_ctl restart",
+"#",
+"# You don't have to configure GTM Proxy if you dont' configure GTM slave or you are happy if every component connects",
+"# to GTM Master directly. If you configure GTL slave, you must configure GTM proxy too.",
+"",
+"#---- Shortcuts ------",
+"gtmProxyDir=$dataDirRoot/gtm_pxy",
+"",
+"#---- Overall -------",
+"gtmProxy=y # Specify y if you conifugre at least one GTM proxy. You may not configure gtm proxies",
+" # only when you dont' configure GTM slaves.",
+" # If you specify this value not to y, the following parameters will be set to default empty values.",
+" # If we find there're no valid Proxy server names (means, every servers are specified",
+" # as none), then gtmProxy value will be set to \"n\" and all the entries will be set to",
+" # empty values.",
+"gtmProxyNames=(gtm_pxy1) # No used if it is not configured",
+"gtmProxyServers=(localhost) # Specify none if you dont' configure it.",
+"gtmProxyPorts=(20101) # Not used if it is not configured.",
+"gtmProxyDirs=($gtmProxyDir.1) # Not used if it is not configured.",
+"",
+"#---- Configuration ----",
+"gtmPxyExtraConfig=n # Extra configuration parameter for gtm_proxy. Coordinator section has an example.",
+"",
+"#---- Coordinators ----------------------------------------------------------------------------------------------------",
+"",
+"#---- shortcuts ----------",
+"coordMasterDir=$dataDirRoot/coord_master",
+"coordSlaveDir=$HOME/coord_slave",
+"coordArchLogDir=$HOME/coord_archlog",
+"",
+"#---- Overall ------------",
+"coordNames=(coord1 coord2) # Master and slave use the same name",
+"coordPorts=(30001 30002) # Master server listening ports",
+"poolerPorts=(30011 30012) # Master pooler ports",
+"coordPgHbaEntries=(::1/128) # Assumes that all the coordinator (master/slave) accepts",
+" # the same connection",
+" # This entry allows only $pgxcOwner to connect.",
+" # If you'd like to setup another connection, you should",
+" # supply these entries through files specified below.",
+"#coordPgHbaEntries=(127.0.0.1/32) # Same as above but for IPv4 connections",
+"",
+"#---- Master -------------",
+"coordMasterServers=(localhost localhost) # none means this master is not available",
+"coordMasterDirs=($coordMasterDir.1 $coordMasterDir.2)",
+"coordMaxWALsender=5 # max_wal_senders: needed to configure slave. If zero value is specified,",
+" # it is expected to supply this parameter explicitly by external files",
+" # specified in the following. If you don't configure slaves, leave this value to zero.",
+"coordMaxWALSenders=($coordMaxWALsender $coordMaxWALsender)",
+" # max_wal_senders configuration for each coordinator.",
+"",
+"#---- Slave -------------",
+"coordSlave=n # Specify y if you configure at least one coordiantor slave. Otherwise, the following",
+" # configuration parameters will be set to empty values.",
+" # If no effective server names are found (that is, every servers are specified as none),",
+" # then coordSlave value will be set to n and all the following values will be set to",
+" # empty values.",
+"coordSlaveSync=y # Specify to connect with synchronized mode.",
+"coordSlaveServers=(localhost localhost) # none means this slave is not available",
+"coordSlavePorts=(30101 30102) # coordinator slave listening ports",
+"coordSlavePoolerPorts=(30111 30112) # coordinator slave pooler ports",
+"coordSlaveDirs=($coordSlaveDir.1 $coordSlaveDir.2)",
+"coordArchLogDirs=($coordArchLogDir.1 $coordArchLogDir.2)",
+"",
+"#---- Configuration files---",
+"# Need these when you'd like setup specific non-default configuration ",
+"# These files will go to corresponding files for the master.",
+"# You may supply your bash script to setup extra config lines and extra pg_hba.conf entries ",
+"# Or you may supply these files manually.",
+"coordExtraConfig=coordExtraConfig # Extra configuration file for coordinators. ",
+" # This file will be added to all the coordinators'",
+" # postgresql.conf",
+"# Pleae note that the following sets up minimum parameters which you may want to change.",
+"# You can put your postgresql.conf lines here.",
+"cat > $coordExtraConfig <<EOF",
+"#================================================",
+"# Added to all the coordinator postgresql.conf",
+"# Original: $coordExtraConfig",
+"log_destination = 'stderr'",
+"logging_collector = on",
+"log_directory = 'pg_log'",
+"listen_addresses = '*'",
+"max_connections = 100",
+"hot_standby = off",
+"EOF",
+"",
+"# Additional Configuration file for specific coordinator master.",
+"# You can define each setting by similar means as above.",
+"coordSpecificExtraConfig=(none none)",
+"coordSpecificExtraPgHba=(none none)",
+"",
+"#---- Datanodes -------------------------------------------------------------------------------------------------------",
+"",
+"#---- Shortcuts --------------",
+"datanodeMasterDir=$dataDirRoot/dn_master",
+"datanodeSlaveDir=$dataDirRoot/dn_slave",
+"datanodeArchLogDir=$dataDirRoot/datanode_archlog",
+"",
+"#---- Overall ---------------",
+"primaryDatanode=datanode_1 # Primary Node.",
+"datanodeNames=(datanode_1 datanode_2)",
+"datanodePorts=(40001 40002) # Master and slave use the same port!",
+"datanodePoolerPorts=(40011 40012) # Master and slave use the same port!",
+"datanodePgHbaEntries=(::1/128) # Assumes that all the coordinator (master/slave) accepts",
+" # the same connection",
+" # This list sets up pg_hba.conf for $pgxcOwner user.",
+" # If you'd like to setup other entries, supply them",
+" # through extra configuration files specified below.",
+"#datanodePgHbaEntries=(127.0.0.1/32) # Same as above but for IPv4 connections",
+"",
+"#---- Master ----------------",
+"datanodeMasterServers=(localhost localhost) # none means this master is not available.",
+" # This means that there should be the master but is down.",
+" # The cluster is not operational until the master is",
+" # recovered and ready to run. ",
+"datanodeMasterDirs=($datanodeMasterDir.1 $datanodeMasterDir.2)",
+"datanodeMaxWalSender=5 # max_wal_senders: needed to configure slave. If zero value is ",
+" # specified, it is expected this parameter is explicitly supplied",
+" # by external configuration files.",
+" # If you don't configure slaves, leave this value zero.",
+"datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender)",
+" # max_wal_senders configuration for each datanode",
+"",
+"#---- Slave -----------------",
+"#datanodeSlave=n # Specify y if you configure at least one coordiantor slave. Otherwise, the following",
+" # configuration parameters will be set to empty values.",
+" # If no effective server names are found (that is, every servers are specified as none),",
+" # then datanodeSlave value will be set to n and all the following values will be set to",
+" # empty values.",
+"#datanodeSlaveServers=(localhost localhost) # value none means this slave is not available",
+"#datanodeSlavePorts=(40101 40102) # Master and slave use the same port!",
+"#datanodeSlavePoolerPorts=(40111 40112) # Master and slave use the same port!",
+"#datanodeSlaveSync=y # If datanode slave is connected in synchronized mode",
+"#datanodeSlaveDirs=($datanodeSlaveDir.1 $datanodeSlaveDir.2)",
+"#datanodeArchLogDirs=( $datanodeArchLogDir.1 $datanodeArchLogDir.2)",
+"",
+"# ---- Configuration files ---",
+"# You may supply your bash script to setup extra config lines and extra pg_hba.conf entries here.",
+"# These files will go to corresponding files for the master.",
+"# Or you may supply these files manually.",
+"datanodeExtraConfig=datanodeExtraConfig ",
+"cat > $datanodeExtraConfig <<EOF",
+"#================================================",
+"# Added to all the datanode postgresql.conf",
+"# Original: $datanodeExtraConfig",
+"log_destination = 'stderr'",
+"logging_collector = on",
+"log_directory = 'pg_log'",
+"listen_addresses = '*'",
+"max_connections = 100",
+"hot_standby = off",
+"EOF",
+"# Additional Configuration file for specific datanode master.",
+"# You can define each setting by similar means as above.",
+"datanodeSpecificExtraConfig=(none none)",
+"datanodeSpecificExtraPgHba=(none none)",
+NULL
+};
diff --git a/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin b/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin
index 94fb14c631..9eb92cdf80 100644
--- a/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin
+++ b/doc-xc/src/sgml/pgxc_ctl-ref.sgmlin
@@ -216,6 +216,15 @@ or
PGXC$ prepare config my_pgxc.conf
PGXC$
</programlisting>
+
+You may also generate a template configuration file suitable for testing
+<application>Postgres-XL</application> on the localhost. Use option
+<literal>minimal</literal> to generate a such a template configuration file.
+<programlisting>
+PGXC$ prepare config minimal
+PGXC$ prepare config minimal my_minimal_pgxc.conf
+</programlisting>
+
A more detailed syntax of the command will be described in a later section.
</para>
@@ -768,6 +777,16 @@ PGXC$ prepare config my_config.conf
to define the cluster configuration.
With template values and comments, it will be easy to understand
what they mean.
+ </para>
+ <para>
+ You can also generate a minimal configuration file, god enough to test
+<application>Postgres-XL</application> on the localhost by specifying
+<literal>minimal</literal>. For example:
+<programlisting>
+PGXC$ prepare config minimal
+PGXC$ prepare config minimal my_minimal_config.conf
+</programlisting>
+
The following describes each variable in the order you find in the
configuration template.
</para>