├── .gitignore ├── LICENSE.md ├── README.md ├── bin └── pgenv └── patch ├── 8.0 └── 8.0.plperl.patch └── index ├── patch.8.0 └── patch.8.1 /.gitignore: -------------------------------------------------------------------------------- 1 | /pgsql* 2 | /src/ 3 | /.pgenv.* -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 iovation, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pgenv - PostgreSQL binary manager 2 | ================================= 3 | 4 | Synopsis 5 | -------- 6 | 7 | pgenv help 8 | 9 | # Check dependencies 10 | pgenv check 11 | 12 | # Show versions available to build 13 | pgenv available 14 | 15 | # Build PostgreSQL server 16 | pgenv build 10.4 17 | 18 | # Use PostgreSQL version 19 | pgenv use 10.4 20 | 21 | # Stop current version 22 | pgenv stop 23 | 24 | # Start current version 25 | pgenv start 26 | 27 | # Restart current version 28 | pgenv restart 29 | 30 | # Show current version 31 | pgenv version 32 | 33 | # List built versions 34 | pgenv versions 35 | 36 | # Clear current version 37 | pgenv clear 38 | 39 | # Remove PostgreSQL version 40 | pgenv remove 8.0.25 41 | 42 | Description 43 | ----------- 44 | 45 | pgenv is a simple utility to build and run different releases of [PostgreSQL]. 46 | This makes it easy to switch between versions when testing applications for 47 | compatibility. 48 | 49 | Installation 50 | ------------ 51 | 52 | 1. Check out pgenv into `~/.pgenv`. 53 | 54 | ``` sh 55 | $ git clone https://github.com/theory/pgenv.git ~/.pgenv 56 | ``` 57 | 58 | 2. Add `~/.pgenv/bin` and `~/.pgenv/pgsql/bin` to your `$PATH` for access to 59 | the `pgenv` command-line utility and all the programs provided by 60 | PostgreSQL: 61 | 62 | ``` sh 63 | $ echo 'export PATH="$HOME/.pgenv/bin:$HOME/.pgenv/pgsql/bin:$PATH"' >> ~/.bash_profile 64 | ``` 65 | 66 | **Ubuntu note**: Modify your `~/.profile` instead of `~/.bash_profile`. 67 | 68 | **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`. 69 | 70 | 3. Restart your shell as a login shell so the path changes take effect. You 71 | can now begin using pgenv. 72 | 73 | ~~~ sh 74 | $ exec $SHELL -l 75 | ~~~ 76 | 77 | 4. Build a version of PostgreSQL: 78 | 79 | ~~~ sh 80 | $ pgenv build 10.4 81 | ~~~ 82 | 83 | ### Configuration 84 | 85 | By default, all versions of PostgreSQL will be built in the root of the 86 | project directory (generally in `~/.pgenv`.). If you'd like them to live 87 | elsewhere, set the `$PGENV_ROOT` environment variable to the appropriate 88 | directory. 89 | 90 | It is possible to configure which programs, flags and languages to build 91 | using a configuration file before the program launches the build. 92 | For a more detailed configuration, see the [`pgenv config`](#pgenv-config) 93 | command below. 94 | 95 | ### Upgrading 96 | 97 | You can upgrade your installation to the cutting-edge version at any time 98 | with a simple `git pull`. 99 | 100 | ~~~ sh 101 | $ cd ~/.pgenv 102 | $ git pull 103 | ~~~ 104 | 105 | ### Dependencies 106 | ------------ 107 | 108 | * env - Sets environment for execution 109 | * bash - Command shell interpreter 110 | * curl - Used to download files 111 | * sed, grep, cat, tar, sort, tr, uname - General Unix command line utilities 112 | * patch - For patching versions that need patching 113 | * make - Builds PostgreSQL 114 | 115 | Optional dependencies: 116 | 117 | * Perl 5 - To build PL/Perl 118 | * Python - To build PL/Python 119 | 120 | Command Reference 121 | ----------------- 122 | 123 | Like `git`, the `pgenv` command delegates to subcommands based on its 124 | first argument. The subcommands are: 125 | 126 | ### pgenv use 127 | 128 | Sets the version of PostgreSQL to be used in all shells by symlinking its 129 | directory to `~/$PGENV_ROOT/pgsql` and starting it. Initializes the data 130 | directory if none exists. If another version is currently active, it will be 131 | stopped before switching. If the specified version is already in use, the 132 | `use` command won't stop it, but will initialize its data directory and starts 133 | it if it's not already running. 134 | 135 | $ pgenv use 10.4 136 | waiting for server to shut down.... done 137 | server stopped 138 | waiting for server to start.... done 139 | server started 140 | PostgreSQL 10.4 started 141 | 142 | ### pgenv versions 143 | 144 | Lists all PostgreSQL versions known to `pgenv`, and shows an asterisk next to 145 | the currently active version (if any). The first column reports versions 146 | available for use by `pgenv` and the second lists the subdirectory of 147 | `$PGENV_ROOT` in which the each version is installed: 148 | 149 | $ pgenv versions 150 | 10.4 pgsql-10.4 151 | 11beta3 pgsql-11beta3 152 | 9.5.13 pgsql-9.5.13 153 | * 9.6.9 pgsql-9.6.9 154 | 155 | In this example, versions `9.5.13`, `9.6.9`, `10.4`, and `11beta3` are 156 | available for use, and the `*` indicates that `9.6.10` is the currently active 157 | version. Each version is installed in a `pgsql-` subdirectory of 158 | `$PGENV_ROOT`. 159 | 160 | ### pgenv current 161 | 162 | Displays the currently active PostgreSQL version. 163 | 164 | $ pgenv current 165 | 10.4 166 | 167 | Please note that `version` is a command synonym for version: 168 | 169 | $ pgenv version 170 | 10.4 171 | 172 | ### pgenv clear 173 | 174 | Clears the currently active version of PostgreSQL. If the current version is 175 | running, `clear` will stop it before clearing it. 176 | 177 | $ pgenv clear 178 | waiting for server to shut down.... done 179 | server stopped 180 | PostgreSQL stopped 181 | PostgreSQL cleared 182 | 183 | ### pgenv build 184 | 185 | Downloads and builds the specified version of PostgreSQL and its contrib 186 | modules, as far back as 8.0. 187 | It is possible to instrument the build process to patch the source tree, see 188 | the section on patching later on. 189 | If the version is already built, it will not be rebuilt; use 190 | `clear` to remove an existing version before building it again. 191 | 192 | $ pgenv build 10.3 193 | # [Curl, configure, and make output elided] 194 | PostgreSQL 10.3 built 195 | 196 | The build phase can be customized via a configuration file, in the case 197 | the system does not find a configuration file when the `build` is executed, 198 | a warning is shown to the user to remind she can edit a configuration file 199 | and start over the build process: 200 | 201 | ```sh 202 | $ pgenv build 10.3 203 | ... 204 | WARNING: no configuration file found for version 10.3 205 | HINT: if you wish to customize the build process please 206 | stop the execution within 5 seconds (CTRL-c) and run 207 | pgenv config write 10.3 && pgenv config edit 10.3 208 | adjust 'configure' and 'make' options and flags and run again 209 | pgenv build 10.3 210 | ``` 211 | 212 | Within the configuration file it is possible to instrument 213 | the build phase from the configuration to the actual build. For instance, 214 | in order to build with PL/Perl, it is possible to configure 215 | the variable `PGENV_CONFIGURE_OPTS` adding `--with-perl`. Please note that 216 | it is possible to pass argument variables within the command line to 217 | instrument the build phase. As an example, the following is a possible 218 | work-flow to configure and build a customized 10.5 instance: 219 | 220 | 221 | $ pgenv config write 10.5 222 | $ pgenv config edit 10.5 223 | # adjust PGENV_CONFIGURE_OPTS 224 | $ pgenv build 10.5 225 | 226 | In the case you need to specify a particular variable, such as the Perl interpreter, 227 | pass it on the command line at the time of build: 228 | 229 | $ PERL=/usr/local/my-fancy-perl pgenv build 10.5 230 | 231 | #### Patching 232 | 233 | `pgenv` can patch the source tree before the build process starts. 234 | In particular, the `patch/` folder can contain a set of index files 235 | and patch to apply. The process searches for an index file corresponding 236 | to the PostgreSQL version to build, and if found applies all the patches 237 | contained into the index. 238 | 239 | Index files are named after the PostgreSQL version and the Operating System; 240 | in particular the name of an index file is composed as `patch..` 241 | where `version` is the PostgreSQL version number (or a part of it) and 242 | `os` is the Operating System. As an example, `patch.8.1.4.Linux` represents 243 | the index used when building PostgreSQL 8.1.4 on a Linux machine. 244 | To provide more flexibility, the system searches for an index that is named 245 | after the exact PostgreSQL version and Operating System or a mix of 246 | possible combinations of those. 247 | As an example, in the case of the PostgreSQL version 248 | 8.1.4 the index files is searched among one of the following: 249 | 250 | $PGENV_ROOT/patch/index/patch.8.1.4.Linux 251 | $PGENV_ROOT/patch/index/patch.8.1.4 252 | $PGENV_ROOT/patch/index/patch.8.1.Linux 253 | $PGENV_ROOT/patch/index/patch.8.1 254 | $PGENV_ROOT/patch/index/patch.8.Linux 255 | $PGENV_ROOT/patch/index/patch.8 256 | 257 | 258 | This allows you to specify an index for pretty much any combination or grouping desired. 259 | The first index file that matches wins and it is the only one used for the build process. 260 | If no index file is found at all, no patching is applied on the source tree. 261 | 262 | The index file must contain a list of patches to apply, that is file names (either absolute 263 | or relative to the `patch/` subfolder). Each individual file is applied thru `patch(1)`. 264 | 265 | It is possible to specify a particular index file, that means avoid the automatic index selection, 266 | by either setting the `PGENV_PATCH_INDEX` variable on the command line or in the configuration 267 | file. As an example 268 | 269 | $ PGENV_PATCH_INDEX=/src/my-patch-list.txt pgenv build 10.5 270 | 271 | 272 | 273 | ### pgenv remove 274 | 275 | Removes the specified version of PostgreSQL unless it is the currently-active 276 | version. Use the `clear` command to clear the active version before removing it. 277 | 278 | $ pgenv remove 10.3 279 | PostgreSQL 10.3 removed 280 | 281 | The command removes the version, data directory, source code and configuration. 282 | 283 | ### pgenv start 284 | 285 | Starts the currently active version of PostgreSQL if it's not already running. 286 | Initializes the data directory if none exists. 287 | 288 | $ pgenv start 289 | PostgreSQL started 290 | 291 | It is possible to specify flags to pass to `pg_ctl(1)` when performing the 292 | `START` action, setting the `PGENV_START_OPTS` in the [configuration](#pgenv-config). 293 | Such options must not include the data directory, nor the log file. 294 | 295 | ### pgenv stop 296 | 297 | Stops the currently active version of PostgreSQL. 298 | 299 | $ pgenv stop 300 | PostgreSQL 10.5 stopped 301 | 302 | It is possible to specify flags to pass to `pg_ctl(1)` when performing the 303 | `stop` action, setting the `PGENV_STOP_OPTS` in the [configuration](#pgenv-config). 304 | 305 | ### pgenv restart 306 | 307 | Restarts the currently active version of PostgreSQL, or starts it if it's not 308 | already running. 309 | 310 | $ pgenv restart 311 | PostgreSQL 10.1 restarted 312 | Logging to pgsql/data/server.log 313 | 314 | It is possible to specify flags to pass to `pg_ctl(1)` when performing the 315 | `restart` action, setting the `PGENV_RESTART_OPTS` in the [configuration](#pgenv-config). 316 | 317 | 318 | ### pgenv available 319 | 320 | Shows all the versions of PostgreSQL available to download and build. Handy to 321 | find a version you to pass to the `build` command. Note that the `available` 322 | command produces copious output. 323 | 324 | $ pgenv available 325 | ... 326 | Available PostgreSQL Versions 327 | ======================================================== 328 | 329 | PostgreSQL 9.6 330 | ------------------------------------------------ 331 | 9.6.0 9.6.1 9.6.2 9.6.3 9.6.4 9.6.5 332 | 9.6.6 9.6.7 9.6.8 9.6.9 9.6.10 333 | 334 | PostgreSQL 10 335 | ------------------------------------------------ 336 | 10.0 10.1 10.2 10.3 10.4 10.5 337 | 338 | PostgreSQL 11 339 | ------------------------------------------------ 340 | 11beta1 11beta2 11beta3 341 | 342 | The versions are organized and sorted by major release number. Any listed 343 | version may be passed to the `build` command. 344 | 345 | To limit the list to versions for specific major releases, pass them to 346 | `available`. For example, to list only the `9.6` and `10` available versions: 347 | 348 | $ pgenv available 10 9.6 349 | Available PostgreSQL Versions 350 | ======================================================== 351 | 352 | PostgreSQL 9.6 353 | ------------------------------------------------ 354 | 9.6.0 9.6.1 9.6.2 9.6.3 9.6.4 9.6.5 355 | 9.6.6 9.6.7 9.6.8 9.6.9 9.6.10 356 | 357 | PostgreSQL 10 358 | ------------------------------------------------ 359 | 10.0 10.1 10.2 10.3 10.4 10.5 360 | 361 | ### pgenv check 362 | 363 | Checks the list of commands required to download and build PostgreSQL. Prints 364 | a result for each, with either the path to the command or an error reporting 365 | that the command was not found. 366 | 367 | ### pgenv help 368 | 369 | Outputs a brief usage statement and summary of available commands, like 370 | the following: 371 | 372 | $ pgenv help 373 | Usage: pgenv [] 374 | The pgenv commands are: 375 | use Set and start the current PostgreSQL version 376 | clear Stop and unset the current PostgreSQL version 377 | start Start the current PostgreSQL server 378 | stop Stop the current PostgreSQL server 379 | restart Restart the current PostgreSQL server 380 | build Build a specific version of PostgreSQL 381 | remove Remove a specific version of PostgreSQL 382 | version Show the current PostgreSQL version 383 | current Same as 'version' 384 | versions List all PostgreSQL versions available to pgenv 385 | help Show this usage statement and command summary 386 | available Show which versions can be downloaded 387 | check Check all program dependencies 388 | config View, edit, delete the program configuration 389 | 390 | For full documentation, see: https://github.com/theory/pgenv#readme 391 | 392 | ### pgenv config 393 | 394 | View, set, and delete configuration variables, both globally or for specific 395 | versions of PostgreSQL. Stores the configuration in Bash files, one for each 396 | version, as well as a default configuration. If pgenv cannot find a 397 | configuration variable in a version-specific configuration file, it will look 398 | in the default configuration. If it doesn't find it there, it tires to guess 399 | the appropriate values, or falls back on its own defaults. 400 | 401 | The `config` command accepts the following subcommands: 402 | 403 | - `show` prints the current or specified version configuration 404 | - `write` store the current or specified version configuration 405 | - `edit` opens the current or specified version configuration in an editor (using `$EDITOR`) 406 | - `delete` removes the specified configuration 407 | 408 | Each sub-command accepts a PostgreSQL version number (e.g., `10.5`) or a 409 | special keyword: 410 | 411 | - `current` or `version` tells pgenv to use the currently active version of 412 | PostgreSQL 413 | - `default` tells pgenv to use the default configuration. 414 | 415 | If no version is explicitly passed to any of the `config` subcommands, the 416 | program will work against the currently activce version of PostgreSQL. 417 | 418 | In order to start with a default configuration, use the `write` subcommand: 419 | 420 | $ pgenv config write default 421 | pgenv configuration file ~/.pgenv/.pgenv.conf written 422 | 423 | A subsequent `show` displays the defaults: 424 | 425 | ``` sh 426 | $ pgenv config show default 427 | # Default configuration 428 | # pgenv configuration for PostgreSQL 429 | # File: /home/luca/git/misc/PostgreSQL/pgenv/.pgenv.conf 430 | # --------------------------------------------------- 431 | # pgenv configuration created on mer 12 set 2018, 08.35.52, CEST 432 | 433 | # Enables debug output 434 | # PGENV_DEBUG='' 435 | 436 | ###### Build settings ##### 437 | # Make command to use for build 438 | # PGENV_MAKE='' 439 | 440 | # Make flags 441 | PGENV_MAKE_OPTS='-j3' 442 | 443 | # Configure flags 444 | # PGENV_CONFIGURE_OPTS='' 445 | 446 | 447 | # ... 448 | 449 | ##### Runtime options ##### 450 | # Path to the cluster log file 451 | PGENV_LOG='/home/luca/git/misc/PostgreSQL/pgenv/pgsql/data/server.log' 452 | 453 | # Cluster administrator user 454 | PGENV_PG_USER='postgres' 455 | 456 | # Initdb flags 457 | PGENV_INITDB_OPTS='-U postgres --locale en_US.UTF-8 --encoding UNICODE' 458 | 459 | # ... 460 | ``` 461 | 462 | You can edit the file and adjust parameters to your needs. 463 | 464 | In order to create a configuration file for a specific version, pass the 465 | version to the `write` subcommand: 466 | 467 | $ pgenv config write 10.5 468 | pgenv configuration file [~/.pgenv/.pgenv.10.5.conf] written 469 | 470 | Each time pgenv writes a configuration file, it first creates a backup with 471 | the suffix `.backup`. 472 | 473 | Use the `edit` subcommand to edit a configuration file in your favourite 474 | editor: 475 | 476 | $ pgenv config edit 10.5 477 | 478 | 479 | Use the `delete` subcommand To delete a configuration: 480 | 481 | $ pgenv config delete 10.5 482 | Configuration file ~/.pgenv/.pgenv.10.5.conf (and backup) deleted 483 | 484 | Note that you cannot delete the default configuration unless all other 485 | versions have been removed (e.g., by `pgenv remove`). This prevents accidental 486 | loss of configuration: 487 | 488 | $ pgenv config delete 489 | Cannot delete default configuration while version configurations exist 490 | To remove it anyway, delete ~/.pgenv/.pgenv.conf. 491 | 492 | The `delete` subcommand deletes both the configuration file and its backup 493 | copy. The `pgenv remove` command also deletes any configuration for the 494 | removed version. 495 | 496 | # Bug Reporting 497 | 498 | Please use [GitHub issues]. 499 | 500 | See Also 501 | -------- 502 | 503 | * [plenv] is a binary manager for [Perl], and was the inspiration for pgenv. 504 | * plenv, in turn, was inspired by and based on [rbenv], a binary manager for 505 | Ruby. 506 | * [Pgenv] works similarly, but requires [PostgreSQL] manually compiled from 507 | its Git repo. 508 | 509 | License 510 | ------- 511 | 512 | Distributed under [The MIT License]; see [`LICENSE.md`] for terms. 513 | 514 | [PostgreSQL]: https://postgresql.org/ 515 | [plenv]: https://github.com/tokuhirom/plenv/ 516 | [Perl]: https://perl.org/ 517 | [rbenv]: https://github.com/rbenv/rbenv 518 | [Pgenv]: https://github.com/mnencia/pgenv 519 | [GitHub issues]: https://github.com/theory/pgenv/issues/ 520 | [The MIT License]: https://opensource.org/licenses/MIT 521 | [`LICENSE.md`]: https://github.com/theory/pgenv/blob/master/LICENSE.md 522 | -------------------------------------------------------------------------------- /bin/pgenv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # https://stackoverflow.com/a/19622569/79202 4 | trap 'exit' ERR 5 | set -E 6 | 7 | # Set PGENV_ROOT only if not already set. 8 | if [ -z "$PGENV_ROOT" ]; then 9 | PGENV_ROOT=$(dirname $(dirname $0)) 10 | else 11 | echo "Using PGENV_ROOT $PGENV_ROOT" >&2 12 | fi 13 | 14 | cd $PGENV_ROOT 15 | # Always use an absolute path or configure could complain. 16 | PGENV_ROOT=$(pwd) 17 | 18 | PGSQL=$PGENV_ROOT/pgsql 19 | PG_DATA=$PGSQL/data 20 | PGENV_DOWNLOAD_ROOT='https://ftp.postgresql.org/pub/source/' 21 | 22 | # Now -w because 9.0 and earlier always time out even when successful. 23 | PG_CTL="$PGSQL/bin/pg_ctl" 24 | INITDB="$PGSQL/bin/initdb" 25 | 26 | ############################################# 27 | # Configuration variable and default settings 28 | 29 | PGENV_LOG=$PG_DATA/server.log 30 | PGENV_INITDB_OPTS='-U postgres --locale en_US.UTF-8 --encoding UNICODE' 31 | PGENV_MAKE_OPTS="-j3" 32 | PGENV_CONFIGURE_OPTS="" 33 | PGENV_START_OPTS="" 34 | PGENV_STOP_OPTS="" 35 | ############################################# 36 | 37 | # Prints a debug message if PGENV_DEBUG 38 | # variable enabled 39 | pgenv_debug(){ 40 | if [ ! -z "$PGENV_DEBUG" ]; then 41 | echo "[DEBUG] $1" >&2 42 | fi 43 | } 44 | 45 | pgenv_versions() { 46 | if [ -e "pgsql" ]; then 47 | local curr=$(readlink pgsql) 48 | fi 49 | local installed=0 50 | local flags="" 51 | for dir in $( ls -d pgsql-* 2>/dev/null); do 52 | if [ "$dir" = "$curr" ]; then 53 | flags=" *" 54 | else 55 | flags=" " 56 | fi 57 | 58 | local version=$( echo $dir | $PGENV_SED 's/^pgsql-//' ) 59 | printf "%s %-6s %s\n" "$flags" "$version" "$dir" 60 | installed=$(( installed + 1 )) 61 | done 62 | 63 | if [ $installed -eq 0 ]; then 64 | echo "No PostgreSQL version is installed!" 65 | fi 66 | } 67 | 68 | pgenv_help() { 69 | cat < [] 71 | 72 | The pgenv commands are: 73 | use Set and start the current PostgreSQL version 74 | clear Stop and unset the current PostgreSQL version 75 | start Start the current PostgreSQL server 76 | stop Stop the current PostgreSQL server 77 | restart Restart the current PostgreSQL server 78 | build Build a specific version of PostgreSQL 79 | remove Remove a specific version of PostgreSQL 80 | version Show the current PostgreSQL version 81 | current Same as 'version' 82 | versions List all PostgreSQL versions available to pgenv 83 | help Show this usage statement and command summary 84 | available Show which versions can be downloaded 85 | check Check all program dependencies 86 | config View, edit, delete the program configuration 87 | 88 | For full documentation, see: https://github.com/theory/pgenv#readme 89 | EOF 90 | } 91 | 92 | # Searches for all dependencies and prints a report. If the argument is null, 93 | # only missing depencencies will be reported. Otherwise, it prints the paths for 94 | # all commands. 95 | pgenv_check_dependencies(){ 96 | local verbose=$1 97 | # Don't exit on error. 98 | trap "" ERR 99 | 100 | local present="" 101 | local missing="" 102 | local warning="" 103 | 104 | pgenv_detail_command(){ 105 | local command_name=$1 106 | local command=$2 107 | 108 | local nl=$'\n' 109 | local tab=$'\t' 110 | if [ -z "$command" ]; then 111 | missing+="[KO] $command_name:${tab}NOT found!$nl" 112 | else 113 | present+="[OK] $command_name:$tab$command$nl" 114 | fi 115 | } 116 | 117 | 118 | if [ -z "$PGENV_MAKE" ]; then 119 | PGENV_MAKE=$(which make) 120 | if [ -z "$PGENV_MAKE" ]; then 121 | PGENV_MAKE=$(which gmake) 122 | fi 123 | fi 124 | pgenv_detail_command "make" $PGENV_MAKE 125 | 126 | 127 | if [ -z "$PGENV_CURL" ]; then 128 | PGENV_CURL=$(which curl) 129 | fi 130 | pgenv_detail_command "curl" $PGENV_CURL 131 | 132 | if [ -z "$PGENV_PATCH" ]; then 133 | PGENV_PATCH=$(which patch) 134 | fi 135 | pgenv_detail_command "patch" $PGENV_PATCH 136 | 137 | if [ -z "$PGENV_TAR" ]; then 138 | PGENV_TAR=$(which tar) 139 | fi 140 | pgenv_detail_command "tar" $PGENV_TAR 141 | 142 | if [ -z "$PGENV_SED" ]; then 143 | PGENV_SED=$(which sed) 144 | fi 145 | pgenv_detail_command "sed" $PGENV_SED 146 | 147 | 148 | # check for sort and tr, but not place into 149 | # variables (do we need to push to that extent?) 150 | pgenv_detail_command "sort" $(which sort) 151 | pgenv_detail_command "tr" $(which tr) 152 | 153 | # Go back to exiting on error. 154 | trap 'exit' ERR 155 | if [ ! -z "$verbose" ]; then 156 | # Report found dependencies only in verbose mode. 157 | echo -n "$present" 158 | fi 159 | if [ ! -z "$warning" ]; then 160 | # Always show warnings. 161 | echo -n "$warning" 162 | fi 163 | if [ ! -z "$missing" ]; then 164 | # Always show missing dependencies and exit with an error. 165 | echo "$missing" 166 | exit 1 167 | fi 168 | } 169 | 170 | # This function checks if its first argument is a valid PostgreSQL version 171 | # number, like "10.5" or "9.5.4". In case no version number is specified, or the 172 | # version number is invalid (e.g., "10", "0.9") the function aborts the script. 173 | # If no version has been specified, and a non-empty string is passed as second 174 | # argument, the function prints out a list of installed versions. 175 | # 176 | # Invoking with `pgenv_input_version_or_exit "$v" "verbose"` will produce a list 177 | # from which the user can choose, while `pgenv_input_version_or_exit "$v"`` will 178 | # not. Mind the quotes! 179 | pgenv_input_version_or_exit() { 180 | local version=$1 181 | local verbose=$2 182 | local hint=$3 183 | 184 | if [ -z "$version" ]; then 185 | if [ ! -z "$hint" ]; then 186 | # count the versions 187 | local installed_versions=0 188 | for installed in $( ls -d pgsql-* 2>/dev/null ) 189 | do 190 | installed_versions=$(( installed_versions + 1 )) 191 | done 192 | else 193 | # make a fake value to use the following the if statement 194 | installed_versions=-1 195 | fi 196 | 197 | # if no version is installed, suggest the user to build one 198 | if [ $installed_versions -eq 0 ]; then 199 | echo "No PostgreSQL version is installed!" 200 | echo "Are you looking for command \`$hint\` instead?" 201 | exit 1 202 | else 203 | # at least one version is available, 204 | # ask more details to the user 205 | echo "Which version of PostgreSQL do you want?" 206 | if [ ! -z "$verbose" ]; then 207 | pgenv_versions 208 | fi 209 | exit 1 210 | fi 211 | fi 212 | 213 | if [[ $version =~ ^[1-9][0-9]?\.[0-9]+(\.[0-9]+)?$ ]]; then 214 | return # versions 9.5.4 or 10.1 and alike 215 | elif [[ $version =~ ^[1-9][1-9](beta|rc)[1-9]?$ ]]; then 216 | return # versions 11beta1 and alike 217 | else 218 | echo "Value \"$version\" does not appear to be a PostgreSQL valid version number" 219 | exit 1 220 | fi 221 | } 222 | 223 | # This function accepts a version number (that should have been already checked 224 | # to be valid) and searches for an installation with such a version. If no 225 | # installation with such version number has been found, the script aborts after 226 | # showing installed versions 227 | pgenv_installed_version_or_exit(){ 228 | local version=$1 229 | if [ ! -e "pgsql-${version}" ]; then 230 | echo "PostgreSQL $version not installed; installed versions:" 231 | pgenv_versions 232 | exit 1 233 | fi 234 | } 235 | 236 | # Checks if there is a currently activer version and, if not, reports that fact 237 | # and aborts the script. 238 | pgenv_current_postgresql_or_exit(){ 239 | if [ ! -e "pgsql" ]; then 240 | echo "No version of PostgreSQL currently in use" 241 | echo "Run \`pgenv use \$version\` to link and start a specific version" 242 | echo "Run \`pgenv versions\` to list all installed versions" 243 | exit 1 244 | fi 245 | } 246 | 247 | # Prints the currently active version number. To capture the value instead of 248 | # printing it, make a call like `v=&( pgenv_current_version_number )` 249 | pgenv_current_version_number(){ 250 | # find sed even without the configuration/dependencies 251 | if [ -z "$PGENV_SED" ]; then 252 | PGENV_SED=$(which sed) 253 | fi 254 | local v=$( readlink pgsql | $PGENV_SED 's/^pgsql-//' ) 255 | echo $v 256 | } 257 | 258 | # Provides the configuration file name 259 | # for the specified version. 260 | # 261 | # If no version is specified, the default configuration 262 | # file is provided. 263 | pgenv_configuration_file_name(){ 264 | local v=$1 265 | local PGENV_DEFAULT_CONFIG_FILE="${PGENV_ROOT}/.pgenv.conf" 266 | 267 | if [ ! -z "$v" ]; then 268 | echo "${PGENV_ROOT}/.pgenv.$v.conf" 269 | else 270 | echo "${PGENV_DEFAULT_CONFIG_FILE}" 271 | fi 272 | } 273 | 274 | # Dumps the specified configuration file (if exists) or aborts. 275 | # 276 | # The function accept two option arguments: 277 | # - the version number (if not specified the default configuration will be considered) 278 | # - a title to use for printing the configruation file 279 | # 280 | # If the file cannot be found the function exits. 281 | pgenv_configuration_dump_or_exit(){ 282 | local v=$1 283 | local title=$2 284 | 285 | local CONF=$( pgenv_configuration_file_name $v ) 286 | 287 | if [ -r $CONF ]; then 288 | 289 | echo "# $title" 290 | echo "# pgenv configuration for PostgreSQL $v" 291 | echo "# File: $CONF" 292 | echo "# ---------------------------------------------------" 293 | cat $CONF 294 | echo 295 | else 296 | echo "No configuration found for version <$title> [$CONF]" >&2 297 | exit 1 298 | fi 299 | } 300 | 301 | # Function to load the configuration from a file. 302 | # A configuration file is a shell file that contains variables that 303 | # will be 'sourced' into the current script runtime. 304 | # 305 | # The function accepts an optional argument which is the version number 306 | # to search for. A configuration file with such version number 307 | # will be used as configuration, and in the case it is missing, the default 308 | # configuration file will be used. 309 | # 310 | # The function sets the PGENV_CONFIGURATION_FILE variable to the name of the 311 | # file loaded or to an empty string. This helps understanding later on 312 | # if the configuration has been loaded. 313 | pgenv_configuration_load(){ 314 | local v=$1 315 | 316 | local PGENV_DEFAULT_CONFIG_FILE=$( pgenv_configuration_file_name ) 317 | local PGENV_CONFIG_FILE=$( pgenv_configuration_file_name $v ) 318 | PGENV_CONFIGURATION_FILE='' 319 | 320 | for conf in $( echo "$PGENV_CONFIG_FILE" "$PGENV_DEFAULT_CONFIG_FILE" ) 321 | do 322 | pgenv_debug "Looking for configuration in $conf" 323 | 324 | if [ -r "$conf" ]; then 325 | pgenv_debug "Load configuration from [$conf]" 326 | source "$conf" 327 | PGENV_CONFIGURATION_FILE="$conf" 328 | return 329 | fi 330 | done 331 | 332 | pgenv_debug "No configuration loaded" 333 | } 334 | 335 | # Utility function to remove the configuration file. 336 | # It does remove the default file only if there are no more installed instances 337 | # on this system. 338 | pgenv_configuration_delete(){ 339 | local v=$1 340 | local PGENV_DEFAULT_CONFIG_FILE=$( pgenv_configuration_file_name ) 341 | local PGENV_CONFIG_FILE=$( pgenv_configuration_file_name $v ) 342 | 343 | 344 | # if the file is the default one, delete only if there are 345 | # no installed instances 346 | if [ "$PGENV_CONFIG_FILE" = "$PGENV_DEFAULT_CONFIG_FILE" ]; then 347 | local installed_versions=0 348 | for installed in $( ls -d pgsql-* 2>/dev/null ) 349 | do 350 | installed_versions=$(( installed_versions + 1 )) 351 | done 352 | 353 | if [ $installed_versions -gt 0 ]; then 354 | echo "Cannot delete default configuration while version configurations exist" 355 | echo "To remove it anyway, delete $PGENV_CONFIG_FILE" 356 | exit 1 357 | fi 358 | # if the file is not here, nothing to do! 359 | elif [ ! -f "$PGENV_CONFIG_FILE" ]; then 360 | echo "No configuration to delete" 361 | exit 1 362 | fi 363 | 364 | # remove the file 365 | pgenv_debug "Deleting configuration file [$PGENV_CONFIG_FILE]" 366 | rm -f "$PGENV_CONFIG_FILE" # remove config file 367 | rm -f "${PGENV_CONFIG_FILE}.backup" # remove also backup file 368 | echo "Configuration file $PGENV_CONFIG_FILE (and backup) deleted" 369 | } 370 | 371 | 372 | # Utility function to write a single variable in the configuration file. 373 | # 374 | # Accepts: 375 | # - the configuration file name to which write to 376 | # - the name of the variable 377 | # - the value of the variable 378 | # - an optional comment. 379 | # 380 | # 381 | # Invoking it as 382 | # pgenv_configuration_write_variable 'pgenv.conf' 'foo' 'bar' 'A foo option' 383 | # 384 | # will result in the file in the following: 385 | # 386 | # # A foo option 387 | # foo=bar 388 | # 389 | # If the variable value is not set, the variable name is placed with a comment sign. 390 | pgenv_configuration_write_variable(){ 391 | local file=$1 392 | local name=$2 393 | local value=$3 394 | local comment=$4 395 | 396 | if [ ! -z "comment" ]; then 397 | echo "# $comment" >> "$file" 398 | fi 399 | 400 | # if no value supplied, put a comment 401 | if [ -z "$value" ]; then 402 | echo -n "# " >> "$file" 403 | fi 404 | echo "${name}='${value}'" >> "$file" 405 | echo >> "$file" 406 | } 407 | 408 | # Writes the whole current configuration to the current version file 409 | # or the version file specified. It does a backup copy in the case 410 | # the file already exists. 411 | pgenv_configuration_write() { 412 | local v=$1 413 | CONF=$( pgenv_configuration_file_name $v ) 414 | 415 | # sanity check 416 | if [ -z "$CONF" ]; then 417 | echo "Cannot determine which configuration file to use!" 418 | exit 1 419 | fi 420 | 421 | # make a backup copy 422 | if [ -f "$CONF" ]; then 423 | CONF_BACKUP="${CONF}.backup" 424 | pgenv_debug "Making backup copy of [$CONF] into [$CONF_BACKUP]" 425 | mv "$CONF" "$CONF_BACKUP" 426 | fi 427 | 428 | # ok, write the configuration 429 | echo "# pgenv configuration created on $(date)" > "$CONF" 430 | echo "" >> "$CONF" 431 | pgenv_configuration_write_variable "$CONF" "PGENV_DEBUG" "" 'Enables debug output' 432 | 433 | echo "###### Build settings #####" >> "$CONF" 434 | pgenv_configuration_write_variable "$CONF" "PGENV_MAKE" "$PGENV_MAKE" 'Make command to use for build' 435 | pgenv_configuration_write_variable "$CONF" "PGENV_MAKE_OPTS" "$PGENV_MAKE_OPTS" 'Make flags' 436 | pgenv_configuration_write_variable "$CONF" "PGENV_CONFIGURE_OPTS" "$PGENV_CONFIGURE_OPTS" 'Configure flags, including PL languages but without --prefix' 437 | 438 | pgenv_configuration_write_variable "$CONF" "PGENV_PATCH_INDEX" "$PGENV_PATCH_INDEX" 'A file that lists ordered patches to apply before building starts' 439 | 440 | pgenv_configuration_write_variable "$CONF" "PGENV_CURL" "$PGENV_CURL" 'Curl command to download source code' 441 | pgenv_configuration_write_variable "$CONF" "PGENV_PATCH" "$PGENV_PATCH" 'Patch command for specific versions' 442 | pgenv_configuration_write_variable "$CONF" "PGENV_SED" "$PGENV_SED" 'Sed used to manipulate strings' 443 | 444 | echo "##### Runtime options #####" >> "$CONF" 445 | pgenv_configuration_write_variable "$CONF" "PGENV_LOG" "$PGENV_LOG" 'Path to the cluster log file (mandatory)' 446 | pgenv_configuration_write_variable "$CONF" "PGENV_INITDB_OPTS" "$PGENV_INITDB_OPTS" 'Initdb flags' 447 | pgenv_configuration_write_variable "$CONF" "PGENV_STOP_OPTS" "$PGENV_STOP_OPTS" 'Stop configuration flags' 448 | pgenv_configuration_write_variable "$CONF" "PGENV_START_OPTS" "$PGENV_START_OPTS" 'Start configuration flags' 449 | pgenv_configuration_write_variable "$CONF" "PGENV_RESTART_OPTS" "$PGENV_RESTART_OPTS" 'Restart configuration flags' 450 | 451 | 452 | echo "pgenv configuration written to file $CONF" 453 | } 454 | 455 | 456 | # Wrapper function to start the current instance. 457 | # If the instance is already running, nothing happens. 458 | # If the instance does not have already a PG_DATA 459 | # directory, it will be initdb-ed. 460 | pgenv_start_instance(){ 461 | trap "" ERR 462 | 463 | # if the instance is already running, do nothing 464 | if $PG_CTL status -D "$PG_DATA" &> /dev/null; then 465 | echo "PostgreSQL $v is already running" 466 | return 467 | fi 468 | 469 | # Init the database if needed. 470 | pgenv_initdb 471 | 472 | pgenv_debug "pg_ctl starting instance with flags [$PGENV_START_OPTS] log [$PGENV_LOG]" 473 | $PG_CTL start -D "$PG_DATA" -l "$PGENV_LOG" $PGENV_START_OPTS 474 | if [ $? -eq 0 ]; then 475 | echo "PostgreSQL $v started" 476 | echo "Logging to $PGENV_LOG" 477 | else 478 | echo "PostgreSQL $v NOT started, examine logs in $PGENV_LOG" 479 | fi 480 | trap 'exit' ERR 481 | } 482 | 483 | # Initializes and instance if no data directory is found. 484 | # Requires PG_DATA to be set. 485 | # It is safe to call multiple times. 486 | pgenv_initdb(){ 487 | if [ ! -d $PG_DATA ]; then 488 | pgenv_debug "initdb running with flags [$PGENV_INITDB_OPTS]" 489 | $INITDB -D "$PG_DATA" $PGENV_INITDB_OPTS 490 | else 491 | pgenv_debug "Directory $PG_DATA exists, not initdb-ing!" 492 | fi 493 | } 494 | 495 | # Wrapper function to stop or restart the current instance. 496 | # Accepts an optional argument 'command' that specifies 497 | # if 'stop' or 'restart' action need to be performed. 498 | pgenv_stop_or_restart_instance(){ 499 | local command=$1 500 | if $PG_CTL status -D "$PG_DATA" &> /dev/null; then 501 | # ok, server running, apply the command 502 | case $command in 503 | stop) 504 | pgenv_debug "pg_ctl stopping with flags [$PGENV_STOP_OPTS]" 505 | $PG_CTL stop -D "$PG_DATA" $PGENV_STOP_OPTS 506 | echo "PostgreSQL $v stopped" 507 | ;; 508 | restart) 509 | pgenv_debug "pg_ctl restarting with flags [$PGENV_RESTART_OPTS]" 510 | $PG_CTL restart -D "$PG_DATA" -l "$PGENV_LOG" $PGENV_RESTART_OPTS 511 | echo "PostgreSQL $v restarted" 512 | echo "Logging to $PGENV_LOG" 513 | ;; 514 | esac 515 | else 516 | # server not running 517 | case $command in 518 | stop) 519 | echo "PostgreSQL $v not running" 520 | ;; 521 | restart) 522 | pgenv_start_instance 523 | ;; 524 | esac 525 | fi 526 | } 527 | 528 | 529 | # A function to provide the list, in the right order, of 530 | # patch index files to try for patching the source tree. 531 | # The idea is that the priority goes to an index that matches 532 | # the exact version and the OS-type, then the exact PostgreSQL version, 533 | # and iterates reducing the version to major/minor and finally to 534 | # major only. For example, for the version 8.1.4: 535 | # 536 | # 537 | # patch/index/patch.8.1.4.Linux 538 | # patch/index/patch.8.1.4 539 | # patch/index/patch.8.1.Linux 540 | # patch/index/patch.8.1 541 | # patch/index/patch.8.Linux 542 | # patch/index/patch.8 543 | # 544 | # The first file found must win. 545 | pgenv_patch_get_index_file_names(){ 546 | local version=$1 547 | 548 | local brand=$( echo $version | $PGENV_SED 's/\([[:digit:]]\{1,2\}\).*/\1/' ) 549 | local year=$( echo $version | $PGENV_SED 's/[[:digit:]]\{1,2\}\.\([[:digit:]]\{1,2\}\).*/\1/' ) 550 | 551 | # show all the files in the correct order 552 | cat < /dev/null; then 645 | $PG_CTL stop -D "$PG_DATA" 646 | fi 647 | fi 648 | 649 | # Link the new instance. 650 | ln -nsf pgsql-$2 pgsql 651 | fi 652 | 653 | # Init if needed. 654 | pgenv_initdb 655 | 656 | # start the instance 657 | pgenv_start_instance 658 | exit 659 | ;; 660 | 661 | start) 662 | # check a version is currently in use 663 | pgenv_current_postgresql_or_exit 664 | v=$( pgenv_current_version_number ) 665 | pgenv_debug "Current version $v" 666 | pgenv_configuration_load $v 667 | 668 | # Start er up! 669 | pgenv_start_instance 670 | exit 671 | ;; 672 | 673 | stop|restart) 674 | # check a version is currently in use 675 | pgenv_current_postgresql_or_exit 676 | v=$( pgenv_current_version_number ) 677 | pgenv_debug "Current version $v" 678 | pgenv_configuration_load $v 679 | 680 | # either stop or restart 681 | command="$1" 682 | 683 | # stop the current instance (or restart it) 684 | pgenv_stop_or_restart_instance $command 685 | exit 686 | ;; 687 | 688 | build) 689 | v=$2 690 | # sanity checks before building 691 | pgenv_input_version_or_exit "$v" 692 | pgenv_configuration_load $v 693 | pgenv_check_dependencies 694 | 695 | 696 | # Skip it if we already have it. 697 | if [ -e "pgsql-$v" ]; then 698 | echo "PostgreSQL $v already built" 699 | exit 700 | fi 701 | 702 | # Switch to the src directory. 703 | if [ ! -e "src" ]; then 704 | mkdir src 705 | fi 706 | cd src 707 | 708 | # Download the source if wee don't already have it. 709 | # WARNING: older PostgreSQL used .tar.gz instead of .tar.bz2, 710 | # so if the version is behind 8 use the first format, otherwise 711 | # try to get the most compressed archive 712 | if [[ $v =~ ^[1-7]\. ]]; then 713 | PG_TARBALL="postgresql-$v.tar.gz" 714 | TAR_OPTS="zxf" 715 | else 716 | PG_TARBALL="postgresql-$v.tar.bz2" 717 | TAR_OPTS="jxf" 718 | fi 719 | 720 | if [ ! -f $PG_TARBALL ]; then 721 | $PGENV_CURL -fLO ${PGENV_DOWNLOAD_ROOT}/v$v/${PG_TARBALL} 722 | fi 723 | 724 | 725 | # warn if no configuration was loaded 726 | if [ -z "$PGENV_CONFIGURATION_FILE" ]; then 727 | echo "WARNING: no configuration file found for version $v" 728 | echo "HINT: if you wish to customize the build process please" 729 | echo "stop the execution within 5 seconds (CTRL-c) and run " 730 | echo " pgenv config write $v && pgenv config edit $v" 731 | echo "adjust 'configure' and 'make' options and flags and run again" 732 | echo " pgenv build $v" 733 | echo 734 | sleep 5 735 | fi 736 | 737 | 738 | # Unpack the source. 739 | rm -rf "postgresql-$v" 740 | $PGENV_TAR $TAR_OPTS $PG_TARBALL 741 | cd postgresql-$v 742 | 743 | # patch the source tree if required 744 | pgenv_debug "Patching version $v" 745 | pgenv_patch_source_tree "$v" 'verbose' 746 | 747 | 748 | pgenv_debug "configure command line [--prefix=$PGENV_ROOT/pgsql-$v] + [$PGENV_CONFIGURE_OPTS]" 749 | # need to keep a single string to pass to configure or 750 | # will get an 'invalid package' 751 | ./configure --prefix=$PGENV_ROOT/pgsql-$v $PGENV_CONFIGURE_OPTS 752 | 753 | # make and make install 754 | if [[ $v =~ ^[1-8]\. ]]; then 755 | # 8.x (and prior versions?) doesn't have `make world`. 756 | $PGENV_MAKE $PGENV_MAKE_OPTS 757 | $PGENV_MAKE install 758 | cd contrib 759 | $PGENV_MAKE $PGENV_MAKE_OPTS 760 | $PGENV_MAKE install 761 | else 762 | # Yay, make world! 763 | $PGENV_MAKE world $PGENV_MAKE_OPTS 764 | $PGENV_MAKE install-world 765 | fi 766 | 767 | 768 | # write the configuration 769 | pgenv_configuration_write "$v" 770 | 771 | echo "PostgreSQL $v built" 772 | exit 773 | ;; 774 | 775 | clear) 776 | v=$( pgenv_current_postgresql_or_exit ) 777 | pgenv_configuration_load $v 778 | 779 | # stop the instance 780 | pgenv_stop_or_restart_instance 'stop' 781 | 782 | # We know a version is in use, since pgenv_current_postgresql_or_exit 783 | # otherwise would have killed the script. 784 | rm -f pgsql 785 | echo "PostgreSQL $v cleared" 786 | exit 787 | ;; 788 | 789 | remove) 790 | v=$2 791 | pgenv_input_version_or_exit "$v" 'show-installed-versions' 'build' 792 | 793 | if [ "`readlink pgsql`" = "pgsql-$v" ]; then 794 | echo "PostgreSQL $v currently in use" 795 | echo "Run \`pgenv clear\` to clear it" 796 | echo "or \`pgenv use\` to switch to another version" 797 | exit 1 798 | fi 799 | 800 | rm -fr "pgsql-$v" 801 | rm -fr src/postgresql-$v.tar.* # could be .tar.bz2 or .tar.gz 802 | rm -fr src/postgresql-$v 803 | pgenv_configuration_delete $v # remove this particular configuration 804 | pgenv_configuration_delete # remove default configuration if no instances are left 805 | echo "PostgreSQL $v removed" 806 | exit 807 | ;; 808 | 809 | version|current) 810 | pgenv_current_postgresql_or_exit 811 | pgenv_current_version_number 812 | exit 813 | ;; 814 | 815 | versions) 816 | pgenv_configuration_load 817 | pgenv_check_dependencies 818 | pgenv_versions 819 | exit 820 | ;; 821 | 822 | help) 823 | pgenv_help 824 | exit 825 | ;; 826 | 827 | available) 828 | # load executables 829 | pgenv_check_dependencies 830 | 831 | shift # remove the command from the argument list 832 | echo -e " Available PostgreSQL Versions" 833 | echo -e "========================================================\n" 834 | 835 | # there should be a simpler single regexp... 836 | # First of all download the page with the links to each version (href=va.b.c/) 837 | # and trim out each version, then extract the major version 838 | # and append each version to an hash indexed by the major version number 839 | for version in $( curl -s $PGENV_DOWNLOAD_ROOT \ 840 | | grep -o '" 874 | pgenv_debug "Hash content: ${!versions_hash[@]}" 875 | exit 1 876 | fi 877 | 878 | # read back the versions and display the output 879 | # displying each version with a separated header 880 | for major in $( echo ${!versions_hash[@]} | sort -n ) 881 | do 882 | # normalize version numbers 883 | # (note, use sed instead of bc to avoid introducing another dependency) 884 | if [ $major -ge 70 -a $major -le 96 ]; then 885 | current_version=$( echo $major | $PGENV_SED 's/\([[:digit:]]\)\([[:digit:]]\)/\1\.\2/' ) 886 | else 887 | current_version=$(( major / 10 )) 888 | fi 889 | 890 | # drop away specific versions if the user required only 891 | # a few. All arguments, if any, are major version numbers, 892 | # so check on each of them to see if it makes match with the 893 | # current version, and if not, avoid printing this version. 894 | must_print=1 # always print a version group in default 895 | if [ $# -ge 1 ]; then 896 | must_print=0 897 | for required_major in $* 898 | do 899 | if [ $current_version = $required_major ]; then 900 | must_print=1 901 | break 902 | fi 903 | done 904 | 905 | if [ $must_print -ne 1 ]; then 906 | pgenv_debug "Skip major version $current_version (required $*)" 907 | continue 908 | fi 909 | fi 910 | 911 | echo " PostgreSQL $current_version" 912 | echo " ------------------------------------------------" 913 | printed=0 914 | for numeric in $( echo ${versions_hash[$major]} \ 915 | | tr '-' '\n' \ 916 | | sort -V ) 917 | do 918 | # new line after 5 numbers 919 | if [ $printed -gt 5 ]; then 920 | printed=0 921 | echo 922 | fi 923 | 924 | # move to right to begin the line 925 | if [ $printed -eq 0 ]; then 926 | echo -n " " 927 | fi 928 | 929 | # the output string will be 'MM.m.pp' or 'MM.mm' 930 | # therefore no more than 6 chars, left aligned 931 | printf " %-6s " $numeric 932 | printed=$(( printed + 1 )) 933 | done 934 | echo -e "\n" 935 | done 936 | exit 937 | ;; 938 | 939 | check) 940 | # load default configuration 941 | pgenv_configuration_load 942 | # check for all required dependencies 943 | pgenv_check_dependencies "verbose" 944 | exit 945 | ;; 946 | 947 | config|configuration) 948 | action=$2 949 | v=$3 950 | 951 | # which version does the user wants? 952 | case "$v" in 953 | version|current) 954 | v=$( pgenv_current_version_number ) 955 | title='PostgreSQL currently in use' 956 | ;; 957 | default) 958 | v='' 959 | title='Default configuration' 960 | ;; 961 | *) 962 | # get the currently in use if none specified 963 | if [ -z "$v" ]; then 964 | v=$( pgenv_current_version_number ) 965 | fi 966 | 967 | title="PostgreSQL $v" 968 | ;; 969 | esac 970 | 971 | 972 | case $action in 973 | show) 974 | pgenv_configuration_dump_or_exit "$v" "$title" ;; 975 | write) 976 | # in an explicit write load first the variables from the runtime 977 | # environment, so PL/Perl, make, and stuff can be already set 978 | pgenv_check_dependencies 979 | pgenv_configuration_write "$v" ;; 980 | edit) 981 | configuration_file=$( pgenv_configuration_file_name $v ) 982 | if [ ! -z "$EDITOR" ]; then 983 | $EDITOR $configuration_file 984 | else 985 | echo "No EDITOR variable set, manually start your editor to edit $configuration_file" 986 | exit 1 987 | fi 988 | ;; 989 | delete) 990 | pgenv_configuration_delete "$v" ;; 991 | *) 992 | if [ -z "$action" ]; then 993 | echo "You need to specify a \`config\` action to perform" 994 | else 995 | echo "Configuration action \`$action\` not supported" 996 | fi 997 | exit 1 998 | ;; 999 | esac 1000 | exit 1001 | ;; 1002 | 1003 | *) 1004 | if [ $# -gt 0 ]; then 1005 | echo "Unknown command \`$1\`" 1006 | fi 1007 | 1008 | pgenv_help 1009 | exit 1 1010 | ;; 1011 | esac 1012 | -------------------------------------------------------------------------------- /patch/8.0/8.0.plperl.patch: -------------------------------------------------------------------------------- 1 | --- a/src/pl/plperl/plperl.c 2 | +++ b/src/pl/plperl/plperl.c 3 | @@ -694,7 +694,7 @@ 4 | if (!isGV_with_GP(sv) || !GvCV(sv)) 5 | continue; 6 | SvREFCNT_dec(GvCV(sv)); /* free the CV */ 7 | - GvCV(sv) = NULL; /* prevent call via GV */ 8 | + GvCV_set(sv, NULL); /* prevent call via GV */ 9 | } 10 | 11 | hv_clear(stash); 12 | -------------------------------------------------------------------------------- /patch/index/patch.8.0: -------------------------------------------------------------------------------- 1 | 8.0/8.0.plperl.patch 2 | -------------------------------------------------------------------------------- /patch/index/patch.8.1: -------------------------------------------------------------------------------- 1 | 8.0/8.0.plperl.patch 2 | --------------------------------------------------------------------------------