|
171 | 171 | done |
172 | 172 | } |
173 | 173 |
|
| 174 | +function patch_wrappers { |
| 175 | + local IS_NIX_UPGRADE=$1 |
| 176 | + |
| 177 | + # This is a workaround for older versions of wrappers which don't have the expected |
| 178 | + # naming scheme, containing the version in their library's file name |
| 179 | + # e.g. wrappers-0.1.16.so, rather than wrappers.so |
| 180 | + # pg_upgrade errors out when it doesn't find an equivalent file in the new PG version's |
| 181 | + # library directory, so we're making sure the new version has the expected (old version's) |
| 182 | + # file name. |
| 183 | + # After the upgrade completes, the new version's library file is used. |
| 184 | + # i.e. |
| 185 | + # - old version: wrappers-0.1.16.so |
| 186 | + # - new version: wrappers-0.1.18.so |
| 187 | + # - workaround to make pg_upgrade happy: copy wrappers-0.1.18.so to wrappers-0.1.16.so |
| 188 | + if [ "$IS_NIX_UPGRADE" = "true" ]; then |
| 189 | + OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit) |
| 190 | + OLD_LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH") |
| 191 | + |
| 192 | + find /nix/store/ -name "wrappers*so" -print0 | while read -d $'\0' WRAPPERS_LIB_PATH; do |
| 193 | + if [ -f "$WRAPPERS_LIB_PATH" ]; then |
| 194 | + WRAPPERS_LIB_PATH_DIR=$(dirname "$WRAPPERS_LIB_PATH") |
| 195 | + if [ "$WRAPPERS_LIB_PATH" != "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" ]; then |
| 196 | + echo "Copying $WRAPPERS_LIB_PATH to $WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" |
| 197 | + cp "$WRAPPERS_LIB_PATH" "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" |
| 198 | + fi |
| 199 | + fi |
| 200 | + done |
| 201 | + else |
| 202 | + if [ -d "$PGLIBOLD" ]; then |
| 203 | + WRAPPERS_LIB_PATH=$(find "$PGLIBNEW" -name "wrappers*so" -print -quit) |
| 204 | + if [ -f "$WRAPPERS_LIB_PATH" ]; then |
| 205 | + OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit) |
| 206 | + if [ -f "$OLD_WRAPPER_LIB_PATH" ]; then |
| 207 | + LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH") |
| 208 | + if [ "$WRAPPERS_LIB_PATH" != "$PGLIBNEW/${LIB_FILE_NAME}" ]; then |
| 209 | + echo "Copying $PGLIBNEW/${LIB_FILE_NAME} to $WRAPPERS_LIB_PATH" |
| 210 | + cp "$PGLIBNEW/${LIB_FILE_NAME}" "$PGLIBNEW/${LIB_FILE_NAME}" |
| 211 | + fi |
| 212 | + fi |
| 213 | + fi |
| 214 | + fi |
| 215 | + fi |
| 216 | +} |
| 217 | + |
174 | 218 | function initiate_upgrade { |
175 | 219 | mkdir -p "$MOUNT_POINT" |
176 | 220 | SHARED_PRELOAD_LIBRARIES=$(cat "$POSTGRES_CONFIG_PATH" | grep shared_preload_libraries | sed "s/shared_preload_libraries =\s\{0,1\}'\(.*\)'.*/\1/") |
@@ -324,30 +368,7 @@ function initiate_upgrade { |
324 | 368 | export LD_LIBRARY_PATH="${PGLIBNEW}" |
325 | 369 | fi |
326 | 370 |
|
327 | | - # This is a workaround for older versions of wrappers which don't have the expected |
328 | | - # naming scheme, containing the version in their library's file name |
329 | | - # e.g. wrappers-0.1.16.so, rather than wrappers.so |
330 | | - # pg_upgrade errors out when it doesn't find an equivalent file in the new PG version's |
331 | | - # library directory, so we're making sure the new version has the expected (old version's) |
332 | | - # file name. |
333 | | - # After the upgrade completes, the new version's library file is used. |
334 | | - # i.e. |
335 | | - # - old version: wrappers-0.1.16.so |
336 | | - # - new version: wrappers-0.1.18.so |
337 | | - # - workaround to make pg_upgrade happy: copy wrappers-0.1.18.so to wrappers-0.1.16.so |
338 | | - if [ -d "$PGLIBOLD" ]; then |
339 | | - WRAPPERS_LIB_PATH=$(find "$PGLIBNEW" -name "wrappers*so" -print -quit) |
340 | | - if [ -f "$WRAPPERS_LIB_PATH" ]; then |
341 | | - OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit) |
342 | | - if [ -f "$OLD_WRAPPER_LIB_PATH" ]; then |
343 | | - LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH") |
344 | | - if [ "$WRAPPERS_LIB_PATH" != "$PGLIBNEW/${LIB_FILE_NAME}" ]; then |
345 | | - echo "Copying $OLD_WRAPPER_LIB_PATH to $WRAPPERS_LIB_PATH" |
346 | | - cp "$WRAPPERS_LIB_PATH" "$PGLIBNEW/${LIB_FILE_NAME}" |
347 | | - fi |
348 | | - fi |
349 | | - fi |
350 | | - fi |
| 371 | + patch_wrappers "$IS_NIX_UPGRADE" |
351 | 372 |
|
352 | 373 | echo "9. Creating new data directory, initializing database" |
353 | 374 | chown -R postgres:postgres "$MOUNT_POINT/" |
|
0 commit comments