PageRenderTime 78ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/src/bin/pg_upgrade/test.sh

https://gitlab.com/kush/jarulraj-postgresql-cpp
Shell | 229 lines | 161 code | 36 blank | 32 comment | 19 complexity | 27e7f7500446156c2ba4d44ac17e1cac MD5 | raw file
  1. #!/bin/sh
  2. # src/bin/pg_upgrade/test.sh
  3. #
  4. # Test driver for pg_upgrade. Initializes a new database cluster,
  5. # runs the regression tests (to put in some data), runs pg_dumpall,
  6. # runs pg_upgrade, runs pg_dumpall again, compares the dumps.
  7. #
  8. # Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
  9. # Portions Copyright (c) 1994, Regents of the University of California
  10. set -e
  11. : ${MAKE=make}
  12. # Guard against parallel make issues (see comments in pg_regress.c)
  13. unset MAKEFLAGS
  14. unset MAKELEVEL
  15. # Run a given "initdb" binary and overlay the regression testing
  16. # authentication configuration.
  17. standard_initdb() {
  18. "$1" -N
  19. if [ -n "$TEMP_CONFIG" -a -r "$TEMP_CONFIG" ]
  20. then
  21. cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf"
  22. fi
  23. ../../test/regress/pg_regress --config-auth "$PGDATA"
  24. }
  25. # Establish how the server will listen for connections
  26. testhost=`uname -s`
  27. case $testhost in
  28. MINGW*)
  29. LISTEN_ADDRESSES="localhost"
  30. PGHOST=localhost
  31. ;;
  32. *)
  33. LISTEN_ADDRESSES=""
  34. # Select a socket directory. The algorithm is from the "configure"
  35. # script; the outcome mimics pg_regress.c:make_temp_sockdir().
  36. PGHOST=$PG_REGRESS_SOCK_DIR
  37. if [ "x$PGHOST" = x ]; then
  38. {
  39. dir=`(umask 077 &&
  40. mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null` &&
  41. [ -d "$dir" ]
  42. } ||
  43. {
  44. dir=/tmp/pg_upgrade_check-$$-$RANDOM
  45. (umask 077 && mkdir "$dir")
  46. } ||
  47. {
  48. echo "could not create socket temporary directory in \"/tmp\""
  49. exit 1
  50. }
  51. PGHOST=$dir
  52. trap 'rm -rf "$PGHOST"' 0
  53. trap 'exit 3' 1 2 13 15
  54. fi
  55. ;;
  56. esac
  57. POSTMASTER_OPTS="-F -c listen_addresses=$LISTEN_ADDRESSES -k \"$PGHOST\""
  58. export PGHOST
  59. # don't rely on $PWD here, as old shells don't set it
  60. temp_root=`pwd`/tmp_check
  61. if [ "$1" = '--install' ]; then
  62. temp_install=$temp_root/install
  63. bindir=$temp_install/$bindir
  64. libdir=$temp_install/$libdir
  65. "$MAKE" -s -C ../.. install DESTDIR="$temp_install"
  66. # platform-specific magic to find the shared libraries; see pg_regress.c
  67. LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH
  68. export LD_LIBRARY_PATH
  69. DYLD_LIBRARY_PATH=$libdir:$DYLD_LIBRARY_PATH
  70. export DYLD_LIBRARY_PATH
  71. LIBPATH=$libdir:$LIBPATH
  72. export LIBPATH
  73. PATH=$libdir:$PATH
  74. # We need to make it use psql from our temporary installation,
  75. # because otherwise the installcheck run below would try to
  76. # use psql from the proper installation directory, which might
  77. # be outdated or missing. But don't override anything else that's
  78. # already in EXTRA_REGRESS_OPTS.
  79. EXTRA_REGRESS_OPTS="$EXTRA_REGRESS_OPTS --bindir='$bindir'"
  80. export EXTRA_REGRESS_OPTS
  81. fi
  82. : ${oldbindir=$bindir}
  83. : ${oldsrc=../../..}
  84. oldsrc=`cd "$oldsrc" && pwd`
  85. newsrc=`cd ../../.. && pwd`
  86. PATH=$bindir:$PATH
  87. export PATH
  88. BASE_PGDATA=$temp_root/data
  89. PGDATA="$BASE_PGDATA.old"
  90. export PGDATA
  91. rm -rf "$BASE_PGDATA" "$PGDATA"
  92. logdir=`pwd`/log
  93. rm -rf "$logdir"
  94. mkdir "$logdir"
  95. # Clear out any environment vars that might cause libpq to connect to
  96. # the wrong postmaster (cf pg_regress.c)
  97. #
  98. # Some shells, such as NetBSD's, return non-zero from unset if the variable
  99. # is already unset. Since we are operating under 'set -e', this causes the
  100. # script to fail. To guard against this, set them all to an empty string first.
  101. PGDATABASE=""; unset PGDATABASE
  102. PGUSER=""; unset PGUSER
  103. PGSERVICE=""; unset PGSERVICE
  104. PGSSLMODE=""; unset PGSSLMODE
  105. PGREQUIRESSL=""; unset PGREQUIRESSL
  106. PGCONNECT_TIMEOUT=""; unset PGCONNECT_TIMEOUT
  107. PGHOSTADDR=""; unset PGHOSTADDR
  108. # Select a non-conflicting port number, similarly to pg_regress.c
  109. PG_VERSION_NUM=`grep '#define PG_VERSION_NUM' "$newsrc"/src/include/pg_config.h | awk '{print $3}'`
  110. PGPORT=`expr $PG_VERSION_NUM % 16384 + 49152`
  111. export PGPORT
  112. i=0
  113. while psql -X postgres </dev/null 2>/dev/null
  114. do
  115. i=`expr $i + 1`
  116. if [ $i -eq 16 ]
  117. then
  118. echo port $PGPORT apparently in use
  119. exit 1
  120. fi
  121. PGPORT=`expr $PGPORT + 1`
  122. export PGPORT
  123. done
  124. # buildfarm may try to override port via EXTRA_REGRESS_OPTS ...
  125. EXTRA_REGRESS_OPTS="$EXTRA_REGRESS_OPTS --port=$PGPORT"
  126. export EXTRA_REGRESS_OPTS
  127. # enable echo so the user can see what is being executed
  128. set -x
  129. standard_initdb "$oldbindir"/initdb
  130. "$oldbindir"/pg_ctl start -l "$logdir/postmaster1.log" -o "$POSTMASTER_OPTS" -w
  131. if "$MAKE" -C "$oldsrc" installcheck; then
  132. pg_dumpall -f "$temp_root"/dump1.sql || pg_dumpall1_status=$?
  133. if [ "$newsrc" != "$oldsrc" ]; then
  134. oldpgversion=`psql -A -t -d regression -c "SHOW server_version_num"`
  135. fix_sql=""
  136. case $oldpgversion in
  137. 804??)
  138. fix_sql="UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%'; DROP FUNCTION public.myfunc(integer);"
  139. ;;
  140. 900??)
  141. fix_sql="SET bytea_output TO escape; UPDATE pg_proc SET probin = replace(probin::text, '$oldsrc', '$newsrc')::bytea WHERE probin LIKE '$oldsrc%';"
  142. ;;
  143. 901??)
  144. fix_sql="UPDATE pg_proc SET probin = replace(probin, '$oldsrc', '$newsrc') WHERE probin LIKE '$oldsrc%';"
  145. ;;
  146. esac
  147. psql -d regression -c "$fix_sql;" || psql_fix_sql_status=$?
  148. mv "$temp_root"/dump1.sql "$temp_root"/dump1.sql.orig
  149. sed "s;$oldsrc;$newsrc;g" "$temp_root"/dump1.sql.orig >"$temp_root"/dump1.sql
  150. fi
  151. else
  152. make_installcheck_status=$?
  153. fi
  154. "$oldbindir"/pg_ctl -m fast stop
  155. if [ -n "$make_installcheck_status" ]; then
  156. exit 1
  157. fi
  158. if [ -n "$psql_fix_sql_status" ]; then
  159. exit 1
  160. fi
  161. if [ -n "$pg_dumpall1_status" ]; then
  162. echo "pg_dumpall of pre-upgrade database cluster failed"
  163. exit 1
  164. fi
  165. PGDATA=$BASE_PGDATA
  166. standard_initdb 'initdb'
  167. pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" -p "$PGPORT" -P "$PGPORT"
  168. pg_ctl start -l "$logdir/postmaster2.log" -o "$POSTMASTER_OPTS" -w
  169. case $testhost in
  170. MINGW*) cmd /c analyze_new_cluster.bat ;;
  171. *) sh ./analyze_new_cluster.sh ;;
  172. esac
  173. pg_dumpall -f "$temp_root"/dump2.sql || pg_dumpall2_status=$?
  174. pg_ctl -m fast stop
  175. # no need to echo commands anymore
  176. set +x
  177. echo
  178. if [ -n "$pg_dumpall2_status" ]; then
  179. echo "pg_dumpall of post-upgrade database cluster failed"
  180. exit 1
  181. fi
  182. case $testhost in
  183. MINGW*) cmd /c delete_old_cluster.bat ;;
  184. *) sh ./delete_old_cluster.sh ;;
  185. esac
  186. if diff "$temp_root"/dump1.sql "$temp_root"/dump2.sql >/dev/null; then
  187. echo PASSED
  188. exit 0
  189. else
  190. echo "Files $temp_root/dump1.sql and $temp_root/dump2.sql differ"
  191. echo "dumps were not identical"
  192. exit 1
  193. fi