| #!/bin/bash |
| |
| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| set -e |
| |
| command -v which >/dev/null 2>&1 || { echo "I require which but it's not installed. Aborting." >&2; exit 1; } |
| |
| A=( `which -a psql` ) |
| case "${#A[@]}" in |
| 0) echo "$0: ERROR: no psql on PATH?" && exit 1; ;; |
| 1) psql=${A[0]}; ;; |
| *) psql=${A[1]}; ;; |
| esac |
| echo "psql: $psql" |
| |
| PSQLRC=<( |
| [ -e "$PSQLRC" ] && echo "\i $PSQLRC" |
| e='$e' |
| cat << EOF |
| -- save pid into file |
| \o /tmp/_pgsql_debug_pid |
| select pg_backend_pid(); |
| \! sed -r 's/ +//g;/^[0-9]+$/p;d' -i /tmp/_pgsql_debug_pid |
| \o |
| do $e$ begin raise notice 'backend PID stored in /tmp/_pgsql_debug_pid'; end $e$ ; |
| |
| -- wait for debugger |
| \if :{?debugger_wait_port} |
| do $e$ begin raise notice 'waiting for debugger; connect to 5555 after attach'; end $e$ ; |
| \setenv debugger_wait_port 5555 |
| \! nc -l -p $debugger_wait_port |
| \endif |
| EOF |
| ) exec $psql "$@" |
| # exec $psql -f <( |
| # ) "$@" |
| |
| |
| echo 0.${A[0]} |
| echo ${A[@]} |
| |
| echo ${#A[@]} |
| echo 1.${A[1]} |
| |