1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
|
#!/bin/bash
## WARNING TO MAINTAINERS - DO NOT EDIT this file in debian/. It will be
## overwritten by debian/rules. Edit the .in template instead.
set -e
# postgresql Debian package - post-installation script
#
guessdatestyle() {
# Guess the postgresql datestyle to use for a given timezone (from glibc)
if [ -L /etc/localtime ]
then
# find the timezone offset from UTC
tzno=`date '+%z'`
x=`readlink /etc/localtime | sed -e 's|/usr/share/zoneinfo/||'`
else
if [ -z "$TZ" ]
then
# make sure TZ is set and exported
TZ=`cat /etc/timezone`
fi
export TZ
# find the timezone offset from UTC
tzno=`date '+%z'`
x=`echo $TZ | cut -d/ -f1`
fi
# Find the name of the zone - strip off unwanted header directories
case $x in SystemV | posix | right )
x=`echo $x | cut -d/ -f2-4`
;;
esac
# What country does this zone belong to (if undefined, set it to __)
if [ -n "$x" ]
then
tzcountry=`grep $x /usr/share/zoneinfo/zone.tab | head -1 | cut -c1-2`
fi
if [ -z "$tzcountry" ]
then
tzcountry=__
fi
# Guess the timezone
case $tzcountry in US )
# US date format
GuessDateStyle=SQL
GuessOrder=US
;;
AR )
# Argentina
GuessDateStyle=SQL
GuessOrder=EU
;;
CA )
# Canada has no standard
GuessDateStyle=ISO
GuessOrder=US
;;
DE )
# Germany has a style to itself
GuessDateStyle=GERMAN
GuessOrder=EU
;;
__ )
# No country, so see if the zone is a region or country name
x=$TZ
while echo $x | grep -q /
do
y=`dirname $x`
case $y in SystemV | posix | right )
y=`basename $x`
;;
esac
x=$y
done
case $x in Africa | Canada | Indian | Mexico | America | Chile | GB | Iran | Mideast | Antarctica | Cuba | Israel | NZ | Singapore | Arctic | Jamaica | Asia | Japan | Navajo | Turkey | Atlantic | Kwajalein | Australia | Egypt | Libya | US | Brazil | Eire | Pacific | Hongkong | Poland | Europe | Iceland | Portugal)
# try to guess the zone from the UTC offset and
# the zone abbreviation
if [ -z "$GuessDateStyle" ]
then
GuessDateStyle=Postgres
GuessOrder=EU
if [ "$LANG" = de_DE ]
then
GuessDateStyle=GERMAN
GuessOrder=EU
elif [ $tzno -le -200 -a $tzno -gt -1200 ]
then
tzn=`date '+%Z'`
case $tzn in ADT | AST | AKDT | AKST | CDT | CST | EDT | EST | HADT | HAST | HST | MDT | MST | NDT | PDT | PST)
GuessDateStyle=SQL
GuessOrder=US
;;
esac
fi
fi
;;
* )
# Not a country or region so use ISO
GuessDateStyle=ISO
GuessOrder=EU
;;
esac
;;
* )
# The rest of the world uses normal European format
GuessDateStyle=Postgres
GuessOrder=EU
;;
esac
}
convert_old_conf() {
lastdir=`pwd`
cd /etc/postgresql
[ -d old_config ] ||
mkdir old_config
if [ -f pg_options ]
then
sed -e '/^[ ]*#/d' -e '/^[ ]*$/d' -e 's|\+[ ]*$| = 1|' -e 's|-[ ]*$| = 0|' pg_options > pg_options_out
all=`awk '/^[ ]*all[ ]*=/{print $3}' pg_options_out | tail -1`
case $all in
-1)
# do not set any tracing options
;;
0)
x=`awk '/^[ ]*parse[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add debug_print_parse $x
x=`awk '/^[ ]*plan[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add debug_print_plan $x
x=`awk '/^[ ]*rewritten[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add debug_print_rewritten $x
x=`awk '/^[ ]*query[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add debug_print_query $x
;;
1)
# trace everything
pgconf_add debug_print_parse 1
pgconf_add debug_print_plan 1
pgconf_add debug_print_rewritten 1
pgconf_add debug_print_query 1
;;
esac
# 3 pretty print options are now combined in one
x=`awk '/^[ ]*pretty_plan[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add debug_pretty_print $x
x=`awk '/^[ ]*pretty_parse[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add debug_pretty_print $x
x=`awk '/^[ ]*pretty_rewritten[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add debug_pretty_print $x
x=`awk '/^[ ]*parserstats[ ]*=/{print $3}' pg_options_out | tail -1`
# statistics printing
[ $x -gt 0 ] && pgconf_add show_parser_stats $x
x=`awk '/^[ ]*plannerstats[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add show_planner_stats $x
x=`awk '/^[ ]*executorstats[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add show_executor_stats $x
x=`awk '/^[ ]*deadlock_timeout[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add deadlock_timeout $x
x=`awk '/^[ ]*nofsync[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && echo "Turning off fsync is no longer necessary and is undesirable; I have not
transfered this option to the new configuration."
x=`awk '/^[ ]*syslog[ ]*=/{print $3}' pg_options_out | tail -1`
pgconf_add syslog $x
x=`awk '/^[ ]*hostlookup[ ]*=/{print $3}' pg_options_out | tail -1`
[ $x -gt 0 ] && pgconf_add hostname_lookup $x
rm pg_options_out
mv pg_options old_config
fi
# postmaster options overrode pg_options, so we do those last
. /etc/postgresql/postmaster.init
[ -n "$POSTGRES_DATA" ] && pmconf_add POSTGRES_DATA $POSTGRES_DATA
[ -n "$POSTGRES_LOG" ] && pmconf_add POSTGRES_LOG $POSTGRES_LOG
[ -n "$PGDATESTYLE" ] && pmconf_add PGDATESTYLE $PGDATESTYLE
[ -n "$KERNEL_FILE_MAX" ] && pmconf_add KERNEL_FILE_MAX $KERNEL_FILE_MAX
[ -n "$PGBACKENDCOUNT" ] && pgconf_add max_connections $PGBACKENDCOUNT
[ -n "$PGBUFFERS" ] && pgconf_add shared_buffers $PGBUFFERS
[ -n "$PGDEBUG" ] && pgconf_add debug_level $PGDEBUG
[ -n "$PGFSYNC" ] && echo "Turning off fsync is no longer necessary and may well be undesirable; I have
not transfered this option to the new configuration."
[ -n "$PGSORTMEM" ] && pgconf_add sort_mem $PGSORTMEM
[ -n "$PGALLOWTCPIP" ] && pgconf_add tcpip_socket $PGALLOWTCPIP
[ -n "$PGPORT" ] && pgconf_add port $PGPORT
mv postmaster.init old_config
if [ -f $postgresql.env ]
then
sed 's/postmaster.init/postmaster.conf/g' postgresql.env > $$ &&
mv $$ postgresql.env
fi
# change the postgres user's login profile
cd ~postgres
for f in .login .bash_profile .profile
do
rm -f $$
if [ -f $f ]
then
sed 's/postmaster.init/postmaster.conf/g' $f > $$ &&
mv $$ $f
fi
done
chown postgres.postgres *
chmod 644 *
cd $lastdir
}
pgconf_add() {
param=$2
[ $2 = yes ] && param=on
[ $2 = no ] && param=off
if grep -q "^[ ]*$1[ ]*=" postgresql.conf
then
sed "s|^[ ]*$1[ ]*=.*$|$1 = $param|" <postgresql.conf >$$
mv $$ postgresql.conf
else
echo "$1 = $param" >> postgresql.conf
fi
}
pmconf_add() {
# no need for fancy regexps for tab here, because this is a pristine
# file we've just loaded
sed "s|^# $1=.*$|$1=$2|" < postmaster.conf > $$
mv $$ postmaster.conf
}
set_the_locale() {
# Available locales are in /usr/lib/locale (created by locale-gen)
[ -d /usr/lib/locale ] &&
langs=`ls /usr/lib/locale`
if [ -n "$langs" ]
then
echo "You need to specify the locale under which the postmaster will run."
echo "(This mainly affects the sorting of text. Use of any locale but C"
echo "will reduce the efficiency of index access; however, it will also"
echo "force sorting by ASCII code rather than by national collating order.)"
echo
echo "You have the following locales enabled in your system:"
echo $langs
echo
again=true
langs='C|'`echo $langs | tr ' ' '|'`
while [ $again = true ]
do
echo -n "Select locale [${PGLANG:=C}]: "
read x
[ -z "$x" ] && x=$PGLANG
eval case $x in $langs \) PGLANG=$x\; again=false\;\; \* \) again=true\;\; esac
done
fi
}
# *** EXECUTION STARTS HERE ***
SHELL=/bin/sh
if [ ! "$1" = configure ]
then
# in the future this needs to be improved!
echo Nothing to do for $1
exit
fi
TMPFILE=`mktemp /tmp/pg.XXXXXX` || exit 1
chmod a+rw $TMPFILE
trap "rm -f ${TMPFILE}" 0
# 7.2-5 and 7.2-6 erroneously included /etc/logcheck/ignore.d and the
# removal of the older package will have destroyed it
if dpkg --compare-versions $2 '>=' 7.2-5 &&
dpkg --compare-versions $2 '<=' 7.2-6
then
if [ -d /etc/logcheck ]
then
if [ ! -e /etc/logcheck/ignore.d ]
then
suffix=`readlink /etc/logcheck/logcheck.ignore |
cut -d. -f3`
ln -s ignore.d.${suffix} /etc/logcheck/ignore.d
fi
fi
fi
# If any conffiles have been _deleted_, restore them from the dpkg-dist
# versions (deletion goes beyond valid user editing!)
for f in /etc/init.d/postgresql /etc/postgresql/pg_hba.conf /etc/postgresql/pg_ident.conf /etc/postgresql/postgresql.conf /etc/postgresql/postmaster.conf
do
if [ ! -f $f ]
then
[ -f $f.dpkg-dist ] && mv $f.dpkg-dist $f || touch $f
fi
done
. /etc/postgresql/postmaster.conf
if [ -f /etc/postgresql/postmaster.init ]
then
echo -n "The format of PostgreSQL's configuration files has changed
radically. /etc/postgresql/postmaster.init and /etc/postgresql/pg_options
are no longer used.
Do you want me to move your old configuration to the new files? [Y/n] "
read ans
[ -z "$ans" ] && ans=Y
case $ans in y|Y|yes|YES)
convert_old_conf
;;
*)
echo "Please do the conversion by hand and remove the old files so as not
to be asked this question again."
;;
esac
fi
# If the preinst script set the flag file (that points PGDATA to
# /var/postgres/data), read it and then delete it.
if [ -f /var/lib/postgres/dpkg-postinst-flag ]
then
. /var/lib/postgres/dpkg-postinst-flag
rm /var/lib/postgres/dpkg-postinst-flag
cp /etc/postgresql/postmaster.conf ${TMPFILE}
sed "/^# POSTGRES_DATA=/s|^.*$|POSTGRES_DATA=${POSTGRES_DATA}|" <${TMPFILE} >/etc/postgresql/postmaster.conf
> ${TMPFILE}
fi
PGDATA=${POSTGRES_DATA:=/var/lib/postgres/data}
PGBASE=/usr/lib/postgresql
PGLIB=${PGBASE}/lib
PATH=${PATH}:${PGBASE}/bin
export PGDATA PGLIB PATH
if [ -n "$POSTGRESHOME" -a -z "$POSTGRES_HOME" ]
then
echo '/etc/postgresql/postmaster.conf still contains the variable POSTGRESHOME
This should be changed to POSTGRES_HOME. Setup of postgresql cannot continue
until this has been done. May I do this now? [Y/n] '
read x
case "$x" in
Y|y|"")
cp /etc/postgresql/postmaster.conf $TMPFILE
sed -e 's/POSTGRESHOME/POSTGRES_HOME/g' <$TMPFILE > /etc/postgresql/postmaster.conf
;;
*)
echo "Please edit /etc/postgresql/postmaster.conf by hand and
change all occurrences of POSTGRESHOME to POSTGRES_HOME. Then rerun the setup
of postgresql."
exit 1
;;
esac
fi
PGHOME=${POSTGRES_HOME:=`dirname ${PGDATA}`}
if [ `dirname $PGHOME` = / ]
then
echo -n "In /etc/postgresql/postmaster.conf, POSTGRES_HOME is configured as
$PGHOME, which is unacceptable! (If POSTGRES_HOME is not defined,
it is set to the parent directory of POSTGRES_DATA.)
POSTGRES_HOME should be at least two levels below /, and POSTGRES_DATA
should be at least 3 levels below /.
"
exit 1
fi
if [ ! -d "${PGHOME}" -a ! -f "${PGHOME}" ]
then
echo Creating missing home directory ${PGHOME} for postgres
install -m 700 -o postgres -g postgres -d ${PGHOME}
fi
if [ ! -d "${PGHOME}" ]
then
echo Cannot create home directory ${PGHOME} for postgres
exit 1
fi
# Make sure that /etc/passwd's home directory exists
PSWDHOME=`getent passwd postgres | cut -f6 -d:`
if [ ! -e "${PSWDHOME}" ]
then
echo "The home directory given for postgres in /etc/passwd (${PSWDHOME})"
echo does not exist
echo "(Home directory from /etc/postgresql/postmaster.conf is ${PGHOME})"
exit 1
fi
if [ "${PSWDHOME}" != "${PGHOME}" ]
then
echo Home directory for postgres in /etc/passwd is ${PSWDHOME}
echo Home directory from /etc/postgresql/postmaster.conf is ${PGHOME}
fi
PGSHELL=`getent passwd postgres | awk -F: '{print $7}'`
if [ -z "${PGSHELL}" ]
then
PGSHELL=/bin/sh
fi
PGSHELL=`basename ${PGSHELL}`
case ${PGSHELL} in
bash)
PROFILE=.bash_profile
;;
sh | ksh)
PROFILE=.profile
;;
csh | tcsh)
PROFILE=.login
;;
*)
PROFILE=.profile
;;
esac
install -m 700 -o postgres -g postgres -d ${PGDATA}
grep -q -s postmaster.conf ${PGHOME}/${PROFILE} ||
(echo Updating ${PGHOME}/${PROFILE} ...
echo . /etc/postgresql/postmaster.conf >>${PGHOME}/${PROFILE}
if [ ${PROFILE} = .login ]
then
# C-shell syntax...
echo setenv PATH /bin:/usr/bin:${PGBASE}/bin >>${PGHOME}/${PROFILE}
echo setenv PGDATA \${POSTGRES_DATA:-/var/lib/postgres/data} >>${PGHOME}/${PROFILE}
echo setenv PGLIB ${PGLIB} >>${PGHOME}/${PROFILE}
else
echo PATH=/bin:/usr/bin:${PGBASE}/bin >>${PGHOME}/${PROFILE}
echo PGDATA=\${POSTGRES_DATA:-/var/lib/postgres/data} >>${PGHOME}/${PROFILE}
echo PGLIB=${PGLIB} >>${PGHOME}/${PROFILE}
echo export PGLIB PGDATA >>${PGHOME}/${PROFILE}
fi)
chown -R postgres.postgres ${PGDATA} ${PGHOME} /var/lib/postgres /var/run/postgresql
chmod 755 /var/run/postgresql
chmod 700 ${PGDATA}
# LANG has to be set before we run initdb
if [ "$1" = configure -a -n "$2" ] && dpkg --compare-versions $2 lt 7.1
then
# Before 7.1, LANG was defined in postmaster.init
[ -f /etc/postgresql/postmaster.init ] &&
OLDINIT=/etc/postgresql/postmaster.init ||
OLDINIT=/etc/postgresql/old_config/postmaster.init
[ -f $OLDINIT ] &&
PGLANG=`grep '^[ ]*LANG=' $OLDINIT | tail -1 | cut -d= -f2` ||
unset PGLANG
else
# From 7.1 LC_COLLATE and LC_CTYPE are stored in the database control file
if [ -r $PGDATA/global/pg_control ]
then
PGLANG=`/usr/lib/postgresql/bin/pg_controldata | grep LC_COLLATE | awk '{print $2}'`
fi
fi
if [ ! -f ${PGDATA}/PG_VERSION ]
then
# There is no existing database structure
echo "PostgreSQL databases can be created with any one of a number of
different character encodings. Please choose the default encoding, which
will be used for all newly-created databases in the absence of a specific
encoding specification. The choices are:
SQL_ASCII ASCII
EUC_JP Japanese EUC
EUC_CN Chinese EUC
EUC_KR Korean EUC
EUC_TW Taiwan EUC
UNICODE Unicode(UTF-8)
MULE_INTERNAL Mule internal
LATIN1 ISO 8859-1 English and some European languages
LATIN2 ISO 8859-2 English and some European languages
LATIN3 ISO 8859-3 English and some European languages
LATIN4 ISO 8859-4 English and some European languages
LATIN5 ISO 8859-5 English and some European languages
LATIN6 ISO 8859-10 ECMA-144 Latin Alphabet No.6
LATIN7 ISO 8859-13 Latin Alphabet No.7
LATIN8 ISO 8859-14 Latin Alphabet No.8
LATIN9 ISO 8859-15 Latin Alphabet No.9
LATIN10 ISO 8859-16 ASRO SR 14111 Latin Alphabet No.10
ISO-8859-5 ECMA-113 Latin/Cyrillic
ISO-8859-6 ECMA-114 Latin/Arabic
ISO-8859-7 ECMA-118 Latin/Greek
ISO-8859-8 ECMA-121 Latin/Hebrew
KOI8 KOI8-R
WIN Windows CP1251
ALT Windows CP866
"
ok=
while [ -z "$ok" ]
do
echo -n "Enter default encoding (SQL_ASCII): "
read Encoding
if [ -z "${Encoding}" ]
then
Encoding=SQL_ASCII
fi
case ${Encoding} in SQL_ASCII | EUC_JP | EUC_CN | EUC_KR | EUC_TW | UNICODE | MULE_INTERNAL | LATIN[1-9] | LATIN10 | ISO-8859-[5-8] | KOI8 | WIN | ALT )
ok=true
;;
*)
echo Invalid response, choose one of SQL_ASCII EUC_JP EUC_CN EUC_KR EUC_TW UNICODE MULE_INTERNAL LATIN1 - LATIN10 ISO-8859-5 - ISO-8859-8 KOI8 WIN ALT
;;
esac
done
set_the_locale
echo Now installing the PostgreSQL database files in ${PGDATA}
echo su - postgres -c "cd ${PGHOME}; . ./${PROFILE}; LANG=$PGLANG initdb --encoding ${Encoding} --pgdata ${PGDATA}"
su - postgres -c "cd ${PGHOME}; . ./${PROFILE}; LANG=$PGLANG initdb --encoding ${Encoding} --pgdata ${PGDATA}"
echo PostgreSQL database now installed.
echo Use /usr/bin/createdb to create a specific database and
echo /usr/bin/createuser to enable other users to connect to a
echo PostgreSQL database.
echo
echo In the first instance, these commands must be run by the
echo user \'postgres\'.
echo
fi
if [ "$1" = configure ]
then
# Does postgresql.conf exist? If not, we need to create it.
CONFFILE=/etc/postgresql/postgresql.conf
if [ ! -f $CONFFILE ]
then
echo "# postgresql.conf
# Configuration file for PostgreSQL 7.1 and above
#
" > $CONFFILE
guessdatestyle
cp /etc/postgresql/postmaster.conf ${TMPFILE}
echo "The date style affects how dates, times and timezone information are
presented to the user; the backend has a default setting, though the user can
override it in any session. These are the available date styles:
Style Date Datetime
-------------------------------------------------------
ISO 1999-07-17 1999-07-17 07:09:18+01
SQL 17/07/1999 17/07/1999 07:09:19.00 BST
POSTGRES 17-07-1999 Sat 17 Jul 07:09:19 1999 BST
GERMAN 17.07.1999 17.07.1999 07:09:19.00 BST
"
ok=
while [ -z "$ok" ]
do
echo -n "Choose your default date style ($GuessDateStyle): "
read ans
if [ -z "$ans" ]
then
ans=$GuessDateStyle
fi
case $ans in
ISO|SQL|POSTGRES|GERMAN)
DateStyle=$ans
ok=true
;;
*)
echo "Invalid response ($ans);
answer must be one of ISO SQL POSTGRES GERMAN"
;;
esac
done
ok=
while [ -z "$ok" ]
do
echo -n "Do you expect dates to be in European format (day before month) or
in US format (month before day)? [EU/US] ($GuessOrder): "
read ans
if [ -z "$ans" ]
then
ans=$GuessOrder
fi
case $ans in
EU)
DateOrder=European
ok=true
;;
US)
DateOrder=nonEuropean
ok=true
;;
*)
echo "Invalid response ($ans);
answer must be EU or US"
;;
esac
done
PGDATESTYLE=${DateStyle},${DateOrder}
echo PGDATESTYLE = $PGDATESTYLE >>$CONFFILE
fi
fi
# Make a symbolic link to the configuration files
for f in pg_hba.conf pg_ident.conf postgresql.conf
do
if [ ! -L ${PGDATA}/$f ]
then
rm -f ${PGDATA}/$f
ln -s /etc/postgresql/$f ${PGDATA}/$f
fi
done
# Check for instances of "peer" authentication and change them to "ident"
if grep -qs '^[ ]*local[ ]*.*[ ]*peer[ ]*' /etc/postgresql/pg_hba.conf
then
echo -n "You have \"peer\" authentication in use in /etc/postgresql/pg_hba.conf
This is no longer valid: \"peer\" must be changed to \"ident\"
Should this be changed now? [Y/n] "
read x
if [ "$x" = "Y" -o "$x" = "y" -o -z "$x" ]
then
cp /etc/postgresql/pg_hba.conf /etc/postgresql/$$
sed -e '/^local.*[ ]peer[ ]*/s:peer:ident:' </etc/postgresql/$$ >/etc/postgresql/pg_hba.conf
echo "peer changed to ident"
else
echo "You must make this change yourself before you can start postgresql"
fi
fi
#
# We may need to tidy up /etc/crontab from previous violations of policy
if grep -qs '^#-- postgresql begin *$' /etc/crontab
then
TMP=`mktemp /tmp/pg.XXXXXX` || exit 1
chmod a+rw $TMP
awk 'BEGIN {found=0}
/^#-- postgresql begin *$/ {found = 1}
/^#-- postgresql end *$/ {found = -1}
{if (!found) print}
{if (found == -1) found=0}
END {if (found) exit 1}' /etc/crontab >$TMP &&
if [ -f $TMP ]
then
mv $TMP /etc/crontab
fi
fi
# Make sure the log file exists with the correct ownership
LOGFILE=${POSTGRES_LOG:-/var/log/postgres.log}
touch $LOGFILE
chown postgres.postgres $LOGFILE
#
# These bits would be added by debhelper if we didn't need to tweak the
# last item
update-rc.d postgresql defaults >/dev/null
set +e
/etc/init.d/postgresql restart ||
if [ $? -ne 255 ]
then
exit $?
fi
set -e
# take a little nap while the postmaster sorts itself out
sleep 5
chown -R postgres.postgres /usr/lib/postgresql/dumpall
chmod -R ug+rw /usr/lib/postgresql/dumpall
if ! ps --User postgres | grep -v grep | grep -q postmaster
then
# postmaster isn't running, so we probably have an old database to update;
# lets see if we can do it automatically...
if [ -f ${PGDATA}/PG_VERSION ]
then
# It looks possible
echo -n "
The postmaster has not restarted.
postgresql has found a pre-existing database, and believes that it will be
able to update it automatically to the new version. There is some risk to
your data in this. If you have not got an up-to-date backup of
${PGDATA}, you should say no at this point.
In the course of the update, your existing ${PGDATA}
will be moved to a parallel directory and a new directory created in
its place. The saved dump of your existing database will then be loaded
into the new database. If you have a lot of data, this may take a
considerable time; if your database is sufficiently large, it may fail
for lack of disk space.
The backup of $PGDATA will be on the same filesystem;
the dump file will be in /usr/lib/postgresql/dumpall/.
Do you want me to continue with the automatic update? [y/N] "
read x
case $x in y|Y|yes|YES)
parentdir=`dirname ${PGDATA}`
echo "
The upgrade will now be done; the time taken will depend on the
size of your database(s)."
# Make sure that database passwords or other access constraints don't get
# in the way
PG_HBA_TEMP=`mktemp /etc/postgresql/pg_upgrade.XXXXXX`
chmod a+rw $PG_HBA_TEMP
export PG_HBA_TEMP
(
# this is in a sub-shell to limit the effect of the cd
cd /etc/postgresql
cp pg_hba.conf $PG_HBA_TEMP
echo "local all trust" >pg_hba.conf
)
# make sure the file is restored when the script exits
trapcmd=`trap -p 0`
[ -n "$trapcmd" ] && trapcmd="$trapcmd; "
trapcmd="${trapcmd}cp $PG_HBA_TEMP /etc/postgresql/pg_hba.conf; rm $PG_HBA_TEMP"
trap "$trapcmd" 0
i=
ok=false
while [ $ok = false ]
do
export savedir=${parentdir}/data.$2.save$i
if [ ! -e $savedir ]
then
ok=true
else
[ -z "$i" ] && i=1 || i=`expr $i + 1`
fi
done
if su - postgres -c "unset PGHOST; PATH=/usr/lib/postgresql/bin:/bin:/usr/bin postgresql-dump -icldvp $savedir -Ft /usr/lib/postgresql/dumpall/db.out"
then
if grep -qs '^[ ]*local[ ]*.*[ ]*peer[ ]*' /etc/postgresql/pg_hba.conf
then
:
else
/etc/init.d/postgresql restart
sleep 5
fi
if ps --User postgres | grep -v grep | grep -q postmaster
then
# Success!
rm /usr/lib/postgresql/dumpall/default_encoding
fi
fi
if ! ps --User postgres | grep -v grep | grep -q postmaster
then
echo "Sorry; the automatic database upgrade failed."
fi
;;
*)
echo "
Your data has not been updated and the postmaster is not running.
Read /usr/share/doc/postgresql/README.Debian.migration.gz and do a
manual update. Then restart the postmaster with
\'/etc/init.d/postgresql restart'."
;;
esac
fi
fi
# Only do the next bit if the postmaster is running...
if ps --User postgres | grep -v grep | grep -q postmaster
then
# ...and postgresql-client has been installed
if [ -x /usr/bin/psql -a -x /usr/lib/postgresql/bin/psql ]
then
echo Enabling the PL procedural language in all PostgreSQL databases...
su - postgres -c "/usr/lib/postgresql/bin/enable_lang plpgsql --all"
else
echo "Since psql is not yet available, I cannot include the PL procedural
language in your databases. Once postgresql-client has been installed, you
can run '/usr/lib/postgresql/bin/enable_lang plpgsql --all' (as user postgres)
to do this."
fi
fi
if [ "$1" = "configure" ]
then
if [ -d /usr/doc -a ! -e /usr/doc/postgresql -a -d /usr/share/doc/postgresql ]
then
ln -sf ../share/doc/postgresql /usr/doc/postgresql
fi
fi
exit 0
|