Merge TRAFODION-2570/2572
diff --git a/core/sqf/build-scripts/build.branch b/core/sqf/build-scripts/build.branch
index 3bd2981..463475e 100755
--- a/core/sqf/build-scripts/build.branch
+++ b/core/sqf/build-scripts/build.branch
@@ -52,8 +52,8 @@
     branch=$ZUUL_BRANCH;
   fi
 else
-  rev=$PV_BUILDID
-  branch="git_unavailable"
+  rev=`date +"%Y%m%d"`
+  branch="no_branch"
 fi
 if [ $f = 1 ]; then
   branch=`echo $branch | sed 's|\/|_sl_|g' | sed 's|-|_dh_|g'`
diff --git a/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc b/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc
index ef05776..e4e37ee 100644
--- a/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc
+++ b/docs/sql_reference/src/asciidoc/_chapters/sql_functions_and_expressions.adoc
@@ -53,7 +53,7 @@
 *) or the number of rows that contain a distinct value in the one-column

 table derived from the expression argument of the function (optionally

 distinct values).

-| <<group_concat_function,GROUP_CONCAT Function>> | This function returns a string result with the concatenated non-NULL 

+| <<group_concat_function,GROUP_CONCAT Function>> | This function returns a string result with the concatenated non-NULL

 values from a group.

 | <<max_function,MAX/MAXIMUM Function>> | Determines a maximum value from the group of values derived from the

 evaluation of the expression argument.

@@ -64,7 +64,7 @@
 The numbers can be weighted.

 | <<sum_function,SUM Function>>                 | Computes the sum of a group of numbers derived from the evaluation of

 the expression argument of the function.

-"VARIANCE Function" 

+"VARIANCE Function"

 Computes the statistical variance of a group of numbers derived from the

 evaluation of the expression argument of the function. The numbers can

 be weighted.

@@ -152,11 +152,11 @@
 

 [cols="25%,75%"]

 |===

-| <<add_months_function,ADD_MONTHS Function>>                               | Adds the integer number of months specified by _intr_expr_ 

+| <<add_months_function,ADD_MONTHS Function>>                               | Adds the integer number of months specified by _intr_expr_

 to _datetime_expr_ and normalizes the result.

 | <<converttimestamp_function,CONVERTTIMESTAMP Function>>                   | Converts a Julian timestamp to a TIMESTAMP value.

 | <<current_function,CURRENT Function>> | Returns the current timestamp. You can also use the

-<<current_timestamp_function,CURRENT_TIMESTAMP Function>>. 

+<<current_timestamp_function,CURRENT_TIMESTAMP Function>>.

 | <<current_date_function,CURRENT_DATE Function>>                           | Returns the current date.

 | <<current_time_function,CURRENT_TIME Function>>                           | Returns the current time.

 | <<current_timestamp_function,CURRENT_TIMESTAMP Function>> | Returns the current timestamp. You can also use the <<current_function,CURRENT Function>>.

@@ -221,7 +221,7 @@
 

 [cols="25%,75%"]

 |===

-| <<abs_function,ABS Function>>         | Returns the absolute value of a numeric value expression. 

+| <<abs_function,ABS Function>>         | Returns the absolute value of a numeric value expression.

 | <<acos_function,ACOS Function>>       | Returns the arccosine of a numeric value expression as an angle expressed in radians.

 | <<asin_function,ASIN Function>>       | Returns the arcsine of a numeric value expression as an angle expressed in radians.

 | <<atan_function,ATAN Function>>       | Returns the arctangent of a numeric value expression as an angle expressed in radians.

@@ -256,7 +256,7 @@
 [[encryption_functions]]

  == Encryption Functions

  Use these functions within an SQL value expression to do data encryption or hashing:

- 

+

  [cols="25%,75%"]

  |===

  | <<md5_function,MD5 Function>>         | Returns MD5 checksum

@@ -352,7 +352,7 @@
 | <<bitand_function,BITAND Function>>                             | Performs 'and' operation on corresponding bits of the two operands.

 | <<case_expression,CASE (Conditional) Expression>>               | A conditional expression. The two forms of the CASE expression are simple and searched.

 | <<cast_expression,CAST Expression>>                             | Converts a value from one data type to another data type that you specify.

-| <<coalesce_function,COALESCE Function>>                         | Returns the value of the first expression in the list that does not have a NULL value or if all 

+| <<coalesce_function,COALESCE Function>>                         | Returns the value of the first expression in the list that does not have a NULL value or if all

 the expressions have NULL values, the function returns a NULL value.

 | <<converttohex_function,CONVERTTOHEX Function>>                 | Converts the specified value expression to hexadecimal for display purposes.

 | <<current_user_function,CURRENT_USER Function>>                 | Returns the database user name of the current user who invoked the function.

@@ -365,7 +365,7 @@
 | <<inet_ntoa_function, INET_NTOA Function>>                      | Given a numeric IPv4 network address in network byte order, returns the dotted-quad string representation of the address as a nonbinary string in the connection character set. INET_NTOA() returns NULL if it does not understand its argument.

 | <<nullif_function,NULLIF Function>>                             | Returns the value of the first operand if the two operands are not equal, otherwise it returns NULL.

 | <<nvl_function,NVL Function>>                                   | Returns the value of the first operand unless it is NULL, in which case it returns the value of the second operand.

-| <<user_function,USER Function>>                                 | Returns either the database user name of the current user who invoked the function or the database user name 

+| <<user_function,USER Function>>                                 | Returns either the database user name of the current user who invoked the function or the database user name

 associated with the specified user ID number.

 |===

 

@@ -406,7 +406,7 @@
 The ACOS function returns the arccosine of a numeric value expression as

 an angle expressed in radians.

 

-ACOS is a {project-name} SQL extension. 

+ACOS is a {project-name} SQL extension.

 

 ```

 ACOS (numeric-expression)

@@ -415,7 +415,7 @@
 * `_numeric-expression_`

 +

 is an SQL numeric value expression that specifies the value for the

-argument of the ACOS  function. The range for the value of the argument is 

+argument of the ACOS  function. The range for the value of the argument is

 from -1 to +1. See <<numeric_value_expressions,Numeric Value_Expressions>>.

 

 [[examples_of_acos]]

@@ -509,7 +509,7 @@
 ASCII is a {project-name} SQL extension.

 

 ```

-ASCII (character-expression) 

+ASCII (character-expression)

 ```

 

 * `_character-expression`

@@ -1136,7 +1136,7 @@
 The CAST expression converts data to the data type you specify.

 

 ```

-CAST ({expression | NULL} AS data-type) 

+CAST ({expression | NULL} AS data-type)

 ```

 

 * `_expression_ | NULL`

@@ -1870,38 +1870,38 @@
 <<<

 [[crc32_function]]

  == CRC32 Function

- 

-Computes a cyclic redundancy check value and returns a 32-bit unsigned value. 

-The result is NULL if the argument is NULL. The argument is expected to be a 

+

+Computes a cyclic redundancy check value and returns a 32-bit unsigned value.

+The result is NULL if the argument is NULL. The argument is expected to be a

 string and (if possible) is treated as one if it is not.

- 

+

 ```

 CRC32{ expression)}

 ```

- 

+

 * `_expression_`

 +

 specifies a value expression that determines the values to count. The

-_expression_ cannot contain an aggregate function or a subquery. 

+_expression_ cannot contain an aggregate function or a subquery.

 See <<expressions,Expressions>>.

- 

+

 [[examples_of_crc32]]

 === examples of CR32

 ```

 >>SELECT CRC32('Trafodion') from dual;

- 

+

  (EXPR)

  ----------

- 

+

  1960931967

- 

+

 >>SELECT CRC32(2016) from dual;

- 

+

  (EXPR)

  ----------

- 

+

  2177070256

- 

+

 ```

 <<<

 [[current_function]]

@@ -3043,7 +3043,7 @@
 The DIFF1 function is a sequence function that calculates the amount of

 change in an expression from row to row in an intermediate result table

 ordered by a sequence by clause in a select statement.

-See <<sequence_by_clause,SEQUENCE BY Clause>>. 

+See <<sequence_by_clause,SEQUENCE BY Clause>>.

 

 DIFF1 is a {project-name} SQL extension.

 

@@ -3593,8 +3593,8 @@
 [[group_concat_function]]

 == GROUP_CONCAT Function

 

-This function returns a string result with the concatenated non-NULL values from a group. 

-It returns NULL if there are no non-NULL values. 

+This function returns a string result with the concatenated non-NULL values from a group.

+It returns NULL if there are no non-NULL values.

 The syntax is as follows:

 

 ```

@@ -3604,13 +3604,13 @@
              [SEPARATOR str_val])

 ```

 

-Get the concatenated values of expression combinations. To eliminate duplicate values, 

-use the DISTINCT clause. 

-To sort values in the result, use the ORDER BY clause. To sort in reverse order, add 

-the DESC (descending) keyword to the name of the column you are sorting by in the 

+Get the concatenated values of expression combinations. To eliminate duplicate values,

+use the DISTINCT clause.

+To sort values in the result, use the ORDER BY clause. To sort in reverse order, add

+the DESC (descending) keyword to the name of the column you are sorting by in the

 ORDER BY clause. The default is ascending order; this may be specified explicitly using

-the ASC keyword. The default separator between values in a group is comma (,). To specify 

-a separator explicitly, use SEPARATOR followed by the string literal value that should be 

+the ASC keyword. The default separator between values in a group is comma (,). To specify

+a separator explicitly, use SEPARATOR followed by the string literal value that should be

 inserted between group values. To eliminate the separator altogether, specify SEPARATOR ''.

 

 [[examples_of_group_concat]]

@@ -3697,7 +3697,7 @@
 [[is_ipv4_function]]

 == IS_IPV4 Function

 

-For a given argument, if it is a valid IPV4 string, IS_IPV4() returns 1 else returns 0. 

+For a given argument, if it is a valid IPV4 string, IS_IPV4() returns 1 else returns 0.

 ```

 IS_IPV4( expression )

 ```

@@ -3712,7 +3712,7 @@
 [[examples_of_is_ipv4]]

 === Examples of IS_IPV4

 

-This function returns 1 for the first input argument, since it is a valid IPV4 string; 

+This function returns 1 for the first input argument, since it is a valid IPV4 string;

 0 for the second input argument, since it is an invalid IPV4 string.

 

 ```

@@ -3726,7 +3726,7 @@
 [[is_ipv6_function]]

 == IS_IPV6 Function

 

-Returns 1 if the argument is a valid IPv6 address specified as a string, 0 otherwise. 

+Returns 1 if the argument is a valid IPv6 address specified as a string, 0 otherwise.

 This function does not consider IPv4 addresses to be valid IPv6 addresses.

 

 ```

@@ -3743,7 +3743,7 @@
 [[examples_of_is_ipv6]]

 === Examples of IS_IPV6

 

-This function returns 0 for the second input argument, since it is a valid IPV6 string; 

+This function returns 0 for the second input argument, since it is a valid IPV6 string;

 1 for the second input argument, since it is an invalid IPVr6 string.

 

 ```

@@ -3756,8 +3756,8 @@
  +[[inet_aton_function]]

  +== INET_ATON Function

  +

- +Given the dotted-quad representation of an IPv4 network address as a string, 

- +returns an integer that represents the numeric value of the address in network 

+ +Given the dotted-quad representation of an IPv4 network address as a string,

+ +returns an integer that represents the numeric value of the address in network

  +byte order (big endian). INET_ATON() returns NULL if it does not understand its argument.

  +

  +```

@@ -3780,15 +3780,15 @@
  +

  +(EXPR)

  +-----------

- +167773449 

+ +167773449

  +```

  +<<<

  +[[inet_ntoa_function]]

  +== INET_NTOA Function

  +

- +Given a numeric IPv4 network address in network byte order, returns the 

- +dotted-quad string representation of the address as a nonbinary string in 

- +the connection character set. INET_NTOA() returns NULL if it does 

+ +Given a numeric IPv4 network address in network byte order, returns the

+ +dotted-quad string representation of the address as a nonbinary string in

+ +the connection character set. INET_NTOA() returns NULL if it does

  +not understand its argument.

  +

  +```

@@ -3798,15 +3798,15 @@
  +* `_expression_`

  ++

  +specifies an expression that determines the values to include in the

- +conversion of the number to IP address. The _expression_ cannot contain 

- +an aggregate function or a subquery. If the input value is NULL, INET_NTOA 

- +returns NULL. 

+ +conversion of the number to IP address. The _expression_ cannot contain

+ +an aggregate function or a subquery. If the input value is NULL, INET_NTOA

+ +returns NULL.

  +See <<expressions,Expressions>>.

  +

  +[[examples_of_inet_ntoa]]

  +=== Examples of INET_NTOA

  +

- +this function will convert an integer into  the dotted-quad string 

+ +this function will convert an integer into  the dotted-quad string

  +representation of the IP address.

  +

  +```

@@ -4433,7 +4433,7 @@
 == MD5 Function

 

 Calculates an MD5 128-bit checksum for the string. The value is returned

-as a string of 32 hexadecimal digits, or NULL if the argument was NULL. 

+as a string of 32 hexadecimal digits, or NULL if the argument was NULL.

 

 ```

 MD5( _expression_)

@@ -4446,7 +4446,7 @@
 See <<expressions,Expressions>>.

 

 [[examples_of_md5]]

-=== Examples of MD5 

+=== Examples of MD5

 The return value is a nonbinary string in the connection character set.

 ```

 >>SELECT MD5('testing') from dual;

@@ -6748,9 +6748,9 @@
 [[sha_function]]

 == SHA Function

 

-Calculates an SHA-1 160-bit checksum for the string, as described in 

-RFC 3174 (Secure Hash Algorithm). The value is returned as a string of 

-40 hexadecimal digits, or NULL if the argument was NULL. 

+Calculates an SHA-1 160-bit checksum for the string, as described in

+RFC 3174 (Secure Hash Algorithm). The value is returned as a string of

+40 hexadecimal digits, or NULL if the argument was NULL.

 

 [[examples_of_sha]]

 === examples of SHA

@@ -6766,13 +6766,13 @@
 [[sha2_function]]

 == SHA2 Function

 

-Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, 

-and SHA-512). The first argument is the cleartext string to be hashed. 

-The second argument indicates the desired bit length of the result, which 

+Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384,

+and SHA-512). The first argument is the cleartext string to be hashed.

+The second argument indicates the desired bit length of the result, which

 must have a value of 224, 256, 384, 512.

-If either argument is NULL or the hash length is not one of the permitted values, 

-the return value is NULL. Otherwise, the function result is a hash value containing 

-the desired number of bits. See the notes at the beginning of this section 

+If either argument is NULL or the hash length is not one of the permitted values,

+the return value is NULL. Otherwise, the function result is a hash value containing

+the desired number of bits. See the notes at the beginning of this section

 about storing hash values efficiently.

 

 [[examples_of_sha2]]

@@ -7780,20 +7780,20 @@
 ```

 TO_TIME ('17:05:01', 'HH24:MI:SS')

 ```
-			
+
 <<<
 [[to_timestamp_function]]
 == TO_TIMESTAMP Function
 
 The TO_TIMESTAMP function converts a character value to a timestamp.
-	
+
 ```
 TO_TIMESTAMP(character-expression)
 ```
 
 * `_character-expression_`
 +
-is an expression that gives a character value. The expression ia assumed to have the format YYYY-MM-DD HH:MI:SS[.FFFFFFF],
+is an expression that gives a character value. The expression ia assumed to have the format YYYY-MM-DD HH:MI:SS[.FFFFFF],
 where YYYY is a 4-digit year, MM is a 2-digit month, DD is a 2-digit day, HH is a 2-digit hours field, MI is a 2-digit
 minutes field, SS is a two-digit seconds field and FFFFFF is an optional microseconds field.
 

@@ -7805,7 +7805,7 @@
 ```

 TO_TIMESTAMP ('2016-12-07 10:01:00')

 ```
-	

+

 <<<

 [[translate_function]]

 == TRANSLATE Function

@@ -8058,7 +8058,7 @@
 <<character_value_expressions,Character Value Expressions>>.

 

 [[examples_of_upshift]]

-=== Examples of UPSHIFT   

+=== Examples of UPSHIFT

 

 * Suppose that your CUSTOMER table includes an entry for Hotel Oregon.

 Select the column CUSTNAME and return a result in uppercase and

@@ -8405,4 +8405,3 @@
 ```

 ZEROIFNULL (salary)

 ```

-

diff --git a/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc b/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc
index b7fe71e..f260e3d 100644
--- a/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc
+++ b/docs/sql_reference/src/asciidoc/_chapters/sql_language_elements.adoc
@@ -1874,7 +1874,7 @@
 

 <<<

 [[identity_column]]

-== Indentity Column

+== Identity Column

 

 A identity column is an auto-increment column, which is defined to a column of a table with identity attribute and used to automatically generate increasing or decreasing sequential numeric value for a column with each row insertion into the table.

 

@@ -1892,7 +1892,7 @@
 ```

 

 [[syntax_description_of_identity_column]]

-=== Syntax Description of Indentity Column

+=== Syntax Description of Identity Column

 

 * `ALWAYS`

 +

@@ -1905,7 +1905,7 @@
 The options above serve the same purposes as they serve when you create a sequence. For more information, see <<create_sequence_statement,CREATE SEQUENCE Statement>>.

 

 [[examples_of_identity_column]]

-=== Examples of Indentity Column

+=== Examples of Identity Column

 

 * Example of `ALWAYS`

 +

diff --git a/docs/sql_reference/src/asciidoc/_chapters/sql_statements.adoc b/docs/sql_reference/src/asciidoc/_chapters/sql_statements.adoc
index 6ea3fde..d712dec 100644
--- a/docs/sql_reference/src/asciidoc/_chapters/sql_statements.adoc
+++ b/docs/sql_reference/src/asciidoc/_chapters/sql_statements.adoc
@@ -6642,6 +6642,7 @@
   | query-expr-and-order

 

 query-specification is:

+[with-clause]

 SELECT [ "[" ANY N "]" | "[" FIRST N "]" ] [ALL | DISTINCT] select-list

    FROM table-ref [,table-ref]...

    [WHERE search-condition]

@@ -6652,9 +6653,18 @@
       [,colname [ASC[ENDING] | DESC[ENDING]]]...]

    [GROUP BY {colname | colnum} [,{colname | colnum}]...]

    [HAVING search-condition]

-   [access-clause ]

+   [access-clause]

    [mode-clause]

 

+With-clause is:

+WITH with_clause_elements

+

+with_clause_elements is: 

+with_clause_element [,with_clause_element] …

+

+with_clause_element is: 

+cte-table-name AS (sql-query)

+

 query-expr-and-order is:

     query-expr [order-by-clause] [access-clause] [mode-clause]

 

@@ -6758,6 +6768,26 @@
 [[select_syntax]]

 === Syntax Description of SELECT

 

+* with-clause

+

++

+With-clause, known as Common Table Expressions (CTEs) or subquery factoring clause, was introduced in the SQL-99 standard and has been implemented into Trafodion R2.1.

+

++

+The with-clause assigns an alias to a complex expression. The alias is treated like a temporary table or an inline view that lasts only for the duration of the query and can be referenced multiple times in the same query.

+

++

+By abstracting the complicated parts of the query into simpler, separate and logical blocks, and possibly materializing the results of these parts to avoid recomputing it multiple times, the with-clause has following advantages:

+

+** Simplifies complicated queries, increasing readability and reducing repeated references.

+** Builds reusable units and decreases maintenance cost.

+** Shortens response time and enhances performance of the query.

+** Improves  compatibility with other systems which support with-clause as well.

+

+* cte-table-name

++

+specifies the unique name of the CTE to be created, which is a valid SQL identifier with a maximum of 128 characters. Duplicate names are not allowed in a single with-clause.

+

 * `"[" ANY _N_ "]" | "[" FIRST _N_ "]"`

 +

 specifies that _N_ rows are to be returned (assuming the table has at least _N_ rows and that the qualification

@@ -7303,6 +7333,15 @@
 SELECT sum(distinct a), avg(distinct b), sum(c) from T group by d;

 ```

 

+[[select_considerations_for_with-clause]]

+==== Considerations for with-clause

+

+* Materialization of CTEs in temporary tables is not yet enabled by default. 

+

+* Trafodion only supports non-recursive common table expressions, which means with-clause cannot be self-referencing, but it can reference a previously defined CTE within the same with-clause.

+

+* The with-clause in Trafodion can be specified only once, at the beginning of a SELECT statement. INSERT, UPDATE, DELETE and CREATE VIEW statements are not supported yet.

+

 [[select_considerations_for_select_list]]

 ==== Considerations for Select List

 

@@ -7436,6 +7475,79 @@
 [[select_examples]]

 === Examples of SELECT

 

+* The following example defines two CTEs, w1 and w2. w2 references w1 which is defined before w2.

+```

+>>select * from t1

+

+ C1 C2

+ ----------

+

+  1 1

+  2 2

+  3 3

+  4 4

+  5 5

+

+ --- SQL operation complete.

+

+>>with w1 as (select * from t1),

+>>w2 as (select * from w1)

+>>select * from w2;

+

+ C1 C2

+ ----------

+

+  1 1

+  2 2

+  3 3

+  4 4

+  5 5

+

+ --- SQL operation complete.

+```

+

+* The following example defines two CTEs, w1 and w2, and then perform a JOIN between them.

+```

+>>select * from t1

+

+ C1 C2

+ ----------

+

+  1 1

+  2 2

+  3 3

+  4 4

+  5 5

+

+ --- SQL operation complete.

+

+>>select * from t2

+

+ C1 C2

+ ----------

+

+  3 3

+  4 4

+  5 5

+  6 6

+  7 7

+

+ --- SQL operation complete.

+

+>>with w1 as (select c1, c2 from t1),

+>>w2 as (select c1, c2 from t2)

+>>select * from w1, w2 where w1.c1 = w2.c1;

+

+ C1 C2 C1 C2

+ ----------

+

+  3 3 3 3

+  4 4 4 4

+  5 5 5 5

+

+ --- SQL operation complete.

+```

+

 * Retrieve information from the EMPLOYEE table for employees with a job code greater than 500 and who are in departments

 with numbers less than or equal to 3000, displaying the results in ascending order by job code:

 +

diff --git a/install/python-installer/scripts/constants.py b/install/python-installer/scripts/constants.py
index b7d3096..1f18e99 100644
--- a/install/python-installer/scripts/constants.py
+++ b/install/python-installer/scripts/constants.py
@@ -41,6 +41,8 @@
 DBCFG_FILE = INSTALLER_LOC + '/db_config'
 DBCFG_TMP_FILE = INSTALLER_LOC + '/.db_config_temp'
 
+SSH_CONFIG_FILE = '/etc/ssh/sshd_config'
+
 SSHKEY_FILE = '/tmp/id_rsa'
 TMP_DIR = '/tmp/.trafodion_install_temp'
 
diff --git a/install/python-installer/scripts/traf_check.py b/install/python-installer/scripts/traf_check.py
index 31d62a9..6463589 100755
--- a/install/python-installer/scripts/traf_check.py
+++ b/install/python-installer/scripts/traf_check.py
@@ -28,6 +28,7 @@
 import sys
 import os
 from common import run_cmd, cmd_output, err, Version
+from constants import SSH_CONFIG_FILE
 
 class Check(object):
     """ check system envs """
@@ -40,6 +41,11 @@
         """ check sudo access """
         run_cmd('sudo -n echo -n "check sudo access" > /dev/null 2>&1')
 
+    def check_ssh_pam(self):
+        """ check if UsePAM is set to yes in sshd_config """
+        if not cmd_output('grep "^UsePAM yes" %s' % SSH_CONFIG_FILE):
+            err('\'UsePAM\' should be set to \'yes\' in %s' % SSH_CONFIG_FILE)
+
     def check_hbase_xml(self):
         """ check if hbase-site.xml file exists """
         hbase_xml_file = self.dbcfgs['hbase_xml_file']
diff --git a/install/python-installer/scripts/traf_user.py b/install/python-installer/scripts/traf_user.py
index 09a346a..05b132c 100755
--- a/install/python-installer/scripts/traf_user.py
+++ b/install/python-installer/scripts/traf_user.py
@@ -43,13 +43,12 @@
     elif 'APACHE' in distro:
         hadoop_type = 'apache'
 
-    traf_user = dbcfgs['traf_user']
-    traf_group = traf_user
-    home_dir = cmd_output('cat /etc/default/useradd |grep HOME |cut -d "=" -f 2').strip()
+    home_dir = cmd_output('cat /etc/default/useradd |grep HOME |cut -d "=" -f 2')
     # customize trafodion home dir
     if dbcfgs.has_key('home_dir') and dbcfgs['home_dir']:
         home_dir = dbcfgs['home_dir']
 
+    traf_user = dbcfgs['traf_user']
     traf_user_dir = '%s/%s' % (home_dir, traf_user)
     traf_dirname = dbcfgs['traf_dirname']
     traf_home = '%s/%s' % (traf_user_dir, traf_dirname)
@@ -60,13 +59,18 @@
     ulimits_file = '/etc/security/limits.d/%s.conf' % traf_user
 
     # create trafodion user and group
-    if not cmd_output('getent group %s' % traf_group):
-        run_cmd('groupadd %s > /dev/null 2>&1' % traf_group)
-
-    if not cmd_output('getent passwd %s' % traf_user):
+    if cmd_output('getent passwd %s' % traf_user):
+        # trafodion user exists, set actual trafodion group
+        traf_group = cmd_output('id -ng %s' % traf_user)
+    else:
+        # default trafodion group
+        traf_group = traf_user
+        if not cmd_output('getent group %s' % traf_group):
+            run_cmd('groupadd %s > /dev/null 2>&1' % traf_group)
         traf_pwd = dbcfgs['traf_pwd']
         run_cmd('useradd --shell /bin/bash -m %s -g %s --home %s --password "$(openssl passwd %s)"' % (traf_user, traf_group, traf_user_dir, traf_pwd))
-    elif not os.path.exists(traf_user_dir):
+
+    if not os.path.exists(traf_user_dir):
         run_cmd('mkdir -p %s' % traf_user_dir)
         run_cmd('chmod 700 %s' % traf_user_dir)