initdb.sh 34.9 KB
Newer Older
1
#!@SHELL@
M
 
Marc G. Fournier 已提交
2 3
#-------------------------------------------------------------------------
#
P
Peter Eisentraut 已提交
4
# initdb creates (initializes) a PostgreSQL database cluster (site,
5
# instance, installation, whatever).  A database cluster is a
P
Peter Eisentraut 已提交
6
# collection of PostgreSQL databases all managed by the same postmaster.
M
 
Marc G. Fournier 已提交
7
#
8 9
# To create the database cluster, we create the directory that contains
# all its data, create the files that hold the global tables, create
10 11
# a few other control files for it, and create two databases: the
# template0 and template1 databases.
M
 
Marc G. Fournier 已提交
12
#
13 14 15 16
# The template databases are ordinary PostgreSQL databases.  template0
# is never supposed to change after initdb, whereas template1 can be
# changed to add site-local standard data.  Either one can be copied
# to produce a new database.
M
 
Marc G. Fournier 已提交
17
#
18 19 20 21 22 23 24
# To create template1, we run the postgres (backend) program in bootstrap
# mode and feed it data from the postgres.bki library file.  After this
# initial bootstrap phase, some additional stuff is created by normal
# SQL commands fed to a standalone backend.  Those commands are just
# embedded into this script (yeah, it's ugly).
#
# template0 is made just by copying the completed template1.
M
 
Marc G. Fournier 已提交
25 26
#
#
B
Bruce Momjian 已提交
27
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
28
# Portions Copyright (c) 1994, Regents of the University of California
M
 
Marc G. Fournier 已提交
29
#
30
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.175 2002/09/24 23:14:25 tgl Exp $
B
Bruce Momjian 已提交
31 32 33
#
#-------------------------------------------------------------------------

34 35 36 37 38

##########################################################################
#
# INITIALIZATION

39
exit_nicely(){
B
Bruce Momjian 已提交
40
    stty echo > /dev/null 2>&1
41 42
    echo 1>&2
    echo "$CMDNAME failed." 1>&2
43
    if [ "$noclean" != yes ]; then
44
        if [ "$made_new_pgdata" = yes ]; then
45 46
            echo "Removing $PGDATA." 1>&2
            rm -rf "$PGDATA" || echo "Failed." 1>&2
47
        fi
B
Bruce Momjian 已提交
48
    else
49
        echo "Data directory $PGDATA will not be removed at user's request." 1>&2
B
Bruce Momjian 已提交
50 51 52 53
    fi
    exit 1
}

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
pg_getlocale(){
    arg=$1
    unset ret

    for var in "PGLC_$arg" PGLOCALE LC_ALL "LC_$arg" LANG; do
        varset=`eval echo '${'"$var"'+set}'`
        varval=`eval echo '$'"$var"`
        if test "$varset" = set; then
            ret=$varval
            break
        fi
    done

    if test "${ret+set}" != set; then
        ret=C
    fi

    echo "$ret"
}

B
Bruce Momjian 已提交
74 75 76

CMDNAME=`basename $0`

77
# Placed here during build
78 79
VERSION='@VERSION@'
bindir='@bindir@'
80 81
# Note that "datadir" is not the directory we're initializing, it's
# merely how Autoconf names PREFIX/share.
82
datadir='@datadir@'
83

P
Peter Eisentraut 已提交
84 85 86 87 88 89 90 91 92 93 94 95

# Check for echo -n vs echo \c
if echo '\c' | grep -s c >/dev/null 2>&1
then
    ECHO_N="echo -n"
    ECHO_C=""
else
    ECHO_N="echo"
    ECHO_C='\c'
fi


B
Bruce Momjian 已提交
96 97 98
#
# Find out where we're located
#
99 100
if echo "$0" | grep '/' > /dev/null 2>&1 
then
B
Bruce Momjian 已提交
101
        # explicit dir name given
P
Peter Eisentraut 已提交
102
        self_path=`echo $0 | sed 's,/[^/]*$,,'`       # (dirname command is not portable)
B
Bruce Momjian 已提交
103 104
else
        # look for it in PATH ('which' command is not portable)
B
Bruce Momjian 已提交
105 106
        for dir in `echo "$PATH" | sed 's/:/ /g'`
	do
B
Bruce Momjian 已提交
107 108
                # empty entry in path means current dir
                [ -z "$dir" ] && dir='.'
109
                if [ -f "$dir/$CMDNAME" ]
B
Bruce Momjian 已提交
110
		then
P
Peter Eisentraut 已提交
111
                        self_path="$dir"
B
Bruce Momjian 已提交
112 113 114 115 116
                        break
                fi
        done
fi

P
Peter Eisentraut 已提交
117 118 119 120 121 122 123 124 125

# Check for right version of backend.  First we check for an
# executable in the same directory is this initdb script (presuming
# the above code worked).  Then we fall back to the hard-wired bindir.
# We do it in this order because during upgrades users might move
# their trees to backup places, so $bindir might be inaccurate.

if [ x"$self_path" != x"" ] \
  && [ -x "$self_path/postgres" ] \
126
  && [ x"`$self_path/postgres -V 2>/dev/null`" = x"postgres (PostgreSQL) $VERSION" ]
P
Peter Eisentraut 已提交
127 128 129
then
    PGPATH=$self_path
elif [ -x "$bindir/postgres" ]; then
130
    if [ x"`$bindir/postgres -V 2>/dev/null`" = x"postgres (PostgreSQL) $VERSION" ]
P
Peter Eisentraut 已提交
131 132 133
    then
        PGPATH=$bindir
    else
134 135 136 137 138 139 140 141 142 143 144 145 146
        # Maybe there was an error message?
        errormsg=`$bindir/postgres -V 2>&1 >/dev/null`
      (
        echo "The program "
        echo "    '$bindir/postgres'"
        echo "needed by $CMDNAME does not belong to PostgreSQL version $VERSION, or"
        echo "there may be a configuration problem."
        if test x"$errormsg" != x""; then
            echo
            echo "This was the error message issued by that program:"
            echo "$errormsg"
        fi
      ) 1>&2
P
Peter Eisentraut 已提交
147 148 149
        exit 1
    fi
else
150 151
    echo "The program 'postgres' is needed by $CMDNAME but was not found in" 1>&2
    echo "the directory '$bindir'.  Check your installation." 1>&2
P
Peter Eisentraut 已提交
152
    exit 1
153 154
fi

P
Peter Eisentraut 已提交
155 156 157 158

# Now we can assume that 'pg_id' belongs to the same version as the
# verified 'postgres' in the same directory.
if [ ! -x "$PGPATH/pg_id" ]; then
159 160
    echo "The program 'pg_id' is needed by $CMDNAME but was not found in" 1>&2
    echo "the directory '$PGPATH'.  Check your installation." 1>&2
P
Peter Eisentraut 已提交
161 162
    exit 1
fi
B
Bruce Momjian 已提交
163

164 165 166

EffectiveUser=`$PGPATH/pg_id -n -u`
if [ -z "$EffectiveUser" ]; then
167
    echo "$CMDNAME: could not determine current user name" 1>&2
168 169 170 171 172
    exit 1
fi

if [ `$PGPATH/pg_id -u` -eq 0 ]
then
173 174
    echo "You cannot run $CMDNAME as root. Please log in (using, e.g., 'su')" 1>&2
    echo "as the (unprivileged) user that will own the server process." 1>&2
175 176 177
    exit 1
fi

178

179 180
short_version=`echo $VERSION | sed -e 's!^\([0-9][0-9]*\.[0-9][0-9]*\).*!\1!'`
if [ x"$short_version" = x"" ] ; then
181
  echo "$CMDNAME: bug: version number has wrong format" 1>&2
182 183
  exit 1
fi
184

185 186 187 188 189

##########################################################################
#
# COMMAND LINE OPTIONS

B
Bruce Momjian 已提交
190
# 0 is the default (non-)encoding
191
ENCODINGID=0
B
Bruce Momjian 已提交
192 193

# Set defaults:
194 195 196
debug=
noclean=
show_setting=
B
Bruce Momjian 已提交
197 198 199 200 201

# Note: There is a single compelling reason that the name of the database
#       superuser be the same as the Unix user owning the server process:
#       The single user postgres backend will only connect as the database
#       user with the same name as the Unix user running it. That's
202
#       a security measure.
203
POSTGRES_SUPERUSERNAME="$EffectiveUser"
B
Bruce Momjian 已提交
204

205
while [ "$#" -gt 0 ]
B
Bruce Momjian 已提交
206 207 208 209 210 211
do
    case "$1" in
        --help|-\?)
                usage=t
                break
                ;;
212
        --version|-V)
213 214 215
                echo "initdb (PostgreSQL) $VERSION"
                exit 0
                ;;
B
Bruce Momjian 已提交
216
        --debug|-d)
217
                debug=yes
B
Bruce Momjian 已提交
218 219
                echo "Running with debug mode on."
                ;;
220
        --show|-s)
221
        	show_setting=yes
222
        	;;        
B
Bruce Momjian 已提交
223
        --noclean|-n)
224
                noclean=yes
B
Bruce Momjian 已提交
225 226
                echo "Running with noclean mode on. Mistakes will not be cleaned up."
                ;;
227 228 229
# The name of the database superuser. Can be freely changed.
        --username|-U)
                POSTGRES_SUPERUSERNAME="$2"
B
Bruce Momjian 已提交
230
                shift;;
231 232
        --username=*)
                POSTGRES_SUPERUSERNAME=`echo $1 | sed 's/^--username=//'`
B
Bruce Momjian 已提交
233
                ;;
234 235
        -U*)
                POSTGRES_SUPERUSERNAME=`echo $1 | sed 's/^-U//'`
B
Bruce Momjian 已提交
236 237
                ;;
# The default password of the database superuser.
P
Peter Eisentraut 已提交
238 239 240
# Make initdb prompt for the default password of the database superuser.
        --pwprompt|-W)
                PwPrompt=1
B
Bruce Momjian 已提交
241 242 243 244 245 246 247 248 249 250 251 252
                ;;
# Directory where to install the data. No default, unless the environment
# variable PGDATA is set.
        --pgdata|-D)
                PGDATA="$2"
                shift;;
        --pgdata=*)
                PGDATA=`echo $1 | sed 's/^--pgdata=//'`
                ;;
        -D*)
                PGDATA=`echo $1 | sed 's/^-D//'`
                ;;
253
# The directory where the .bki input files are stored. Normally
254 255 256
# they are in PREFIX/share and this option should be unnecessary.
        -L)
                datadir="$2"
B
Bruce Momjian 已提交
257 258
                shift;;
        -L*)
259
                datadir=`echo $1 | sed 's/^-L//'`
B
Bruce Momjian 已提交
260 261 262
                ;;
# The encoding of the template1 database. Defaults to what you chose
# at configure time. (see above)
263
        --encoding|-E)
264
                ENCODING="$2"
B
Bruce Momjian 已提交
265
                shift;;
P
Peter Eisentraut 已提交
266
        --encoding=*)
267
                ENCODING=`echo $1 | sed 's/^--encoding=//'`
B
Bruce Momjian 已提交
268
                ;;
269
        -E*)
270
                ENCODING=`echo $1 | sed 's/^-E//'`
B
Bruce Momjian 已提交
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
# Locale flags
        --locale)
                PGLOCALE="$2"
                shift;;
        --locale=*)
                PGLOCALE=`echo $1 | sed 's/^[^=]*=//'`
                ;;
        --no-locale)
                PGLOCALE=C
                ;;

        --lc-collate)
                PGLC_COLLATE=$2
                shift;;
        --lc-collate=*)
                PGLC_COLLATE=`echo $1 | sed 's/^[^=]*=//'`
                ;;
        --lc-ctype)
                PGLC_CTYPE=$2
                shift;;
        --lc-ctype=*)
                PGLC_CTYPE=`echo $1 | sed 's/^[^=]*=//'`
                ;;
        --lc-messages)
                PGLC_MESSAGES=$2
                shift;;
        --lc-messages=*)
                PGLC_MESSAGES=`echo $1 | sed 's/^[^=]*=//'`
                ;;
        --lc-monetary)
                PGLC_MONETARY=$2
                shift;;
        --lc-monetary=*)
                PGLC_MONETARY=`echo $1 | sed 's/^[^=]*=//'`
                ;;
        --lc-numeric)
                PGLC_NUMERIC=$2
                shift;;
        --lc-numeric=*)
                PGLC_NUMERIC=`echo $1 | sed 's/^[^=]*=//'`
                ;;
        --lc-time)
                PGLC_TIME=$2
                shift;;
        --lc-time=*)
                PGLC_TIME=`echo $1 | sed 's/^[^=]*=//'`
                ;;

P
Peter Eisentraut 已提交
320 321
	-*)
		echo "$CMDNAME: invalid option: $1"
322
		echo "Try '$CMDNAME --help' for more information."
P
Peter Eisentraut 已提交
323 324
		exit 1
		;;
325 326

# Non-option argument specifies data directory
B
Bruce Momjian 已提交
327
        *)
P
Peter Eisentraut 已提交
328
                PGDATA=$1
B
Bruce Momjian 已提交
329 330 331 332 333
                ;;
    esac
    shift
done

P
Peter Eisentraut 已提交
334
if [ "$usage" ]; then
335
    echo "$CMDNAME initializes a PostgreSQL database cluster."
336 337 338 339 340
    echo
    echo "Usage:"
    echo "  $CMDNAME [options] datadir"
    echo
    echo "Options:"
341
    echo " [-D, --pgdata] DATADIR       Location for this database cluster"
342
    echo "  -W, --pwprompt              Prompt for a password for the new superuser"
343
    echo "  -E, --encoding ENCODING     Set default encoding for new databases"
344 345 346 347 348 349 350
    echo "  --locale LOCALE             Initialize database cluster with given locale"
    echo "  --lc-collate, --lc-ctype, --lc-messages LOCALE"
    echo "  --lc-monetary, --lc-numeric, --lc-time LOCALE"
    echo "                              Initialize database cluster with given locale"
    echo "                              in the respective category"
    echo "                              (default taken from environment)"
    echo "  --no-locale                 Equivalent to --locale=C"
351
    echo "  -U, --username NAME         Database superuser name"
352
    echo "Less commonly used options: "
353
    echo "  -L DIRECTORY                Where to find the input files"
354 355 356 357 358
    echo "  -d, --debug                 Generate lots of debugging output"
    echo "  -n, --noclean               Do not clean up after errors"
    echo
    echo "Report bugs to <pgsql-bugs@postgresql.org>."
    exit 0
B
Bruce Momjian 已提交
359 360 361
fi

#-------------------------------------------------------------------------
362
# Resolve the encoding name
B
Bruce Momjian 已提交
363 364
#-------------------------------------------------------------------------

365
if [ "$ENCODING" ]
366
then
367
	ENCODINGID=`$PGPATH/pg_encoding -b $ENCODING`
368
	if [ "$?" -ne 0 ]
B
Bruce Momjian 已提交
369
	then
370
              (
P
Peter Eisentraut 已提交
371
                echo "$CMDNAME: pg_encoding failed"
372
                echo "Make sure the program was installed correctly."
373
              ) 1>&2
B
Bruce Momjian 已提交
374 375
                exit 1
        fi
376
	if [ -z "$ENCODINGID" ]
377
	then
378
		echo "$CMDNAME: $ENCODING is not a valid backend encoding name" 1>&2
379
		exit 1
B
Bruce Momjian 已提交
380 381 382 383 384 385 386 387
	fi
fi


#-------------------------------------------------------------------------
# Make sure he told us where to build the database system
#-------------------------------------------------------------------------

388 389
if [ -z "$PGDATA" ]
then
390
  (
B
Bruce Momjian 已提交
391
    echo "$CMDNAME: You must identify where the the data for this database"
392
    echo "system will reside.  Do this with either a -D invocation"
B
Bruce Momjian 已提交
393
    echo "option or a PGDATA environment variable."
394
  ) 1>&2
B
Bruce Momjian 已提交
395 396 397 398 399 400 401 402
    exit 1
fi


#-------------------------------------------------------------------------
# Find the input files
#-------------------------------------------------------------------------

403 404
POSTGRES_BKI="$datadir"/postgres.bki
POSTGRES_DESCR="$datadir"/postgres.description
B
Bruce Momjian 已提交
405

406
PG_HBA_SAMPLE="$datadir"/pg_hba.conf.sample
407
PG_IDENT_SAMPLE="$datadir"/pg_ident.conf.sample
408
POSTGRESQL_CONF_SAMPLE="$datadir"/postgresql.conf.sample
B
Bruce Momjian 已提交
409

410
if [ "$show_setting" = yes ] || [ "$debug" = yes ]
411
then
412
  (
413
    echo
414
    echo "initdb variables:"
415
    for var in PGDATA datadir PGPATH ENCODING ENCODINGID \
416
        POSTGRES_SUPERUSERNAME POSTGRES_BKI \
417
        POSTGRES_DESCR POSTGRESQL_CONF_SAMPLE \
418
	PG_HBA_SAMPLE PG_IDENT_SAMPLE ; do
419 420
        eval "echo '  '$var=\$$var"
    done
421
  ) 1>&2
422 423 424 425
fi

if [ "$show_setting" = yes ] ; then
    exit 0
426 427
fi

428 429
for PREREQ_FILE in "$POSTGRES_BKI" "$POSTGRES_DESCR" \
    "$PG_HBA_SAMPLE" "$PG_IDENT_SAMPLE" "$POSTGRESQL_CONF_SAMPLE"
B
Bruce Momjian 已提交
430
do
431
    if [ ! -f "$PREREQ_FILE" ] ; then
432
      (
B
Bruce Momjian 已提交
433 434
        echo "$CMDNAME does not find the file '$PREREQ_FILE'."
        echo "This means you have a corrupted installation or identified the"
435
        echo "wrong directory with the -L invocation option."
436
      ) 1>&2
B
Bruce Momjian 已提交
437 438 439 440
        exit 1
    fi
done

441 442
for file in "$POSTGRES_BKI"
do
P
Peter Eisentraut 已提交
443
     if [ x"`sed 1q $file`" != x"# PostgreSQL $short_version" ]; then
444
       (
P
Peter Eisentraut 已提交
445 446 447
         echo "The input file '$file' needed by $CMDNAME does not"
         echo "belong to PostgreSQL $VERSION.  Check your installation or specify the"
         echo "correct path using the -L option."
448
       ) 1>&2
P
Peter Eisentraut 已提交
449 450 451 452
         exit 1
     fi
done

B
Bruce Momjian 已提交
453

B
Bruce Momjian 已提交
454
trap 'echo "Caught signal." ; exit_nicely' 1 2 3 15
B
Bruce Momjian 已提交
455

456
# Let's go
457 458
echo "The files belonging to this database system will be owned by user \"$EffectiveUser\"."
echo "This user must also own the server process."
459
echo
B
Bruce Momjian 已提交
460

461 462
TAB='	'

463 464 465 466 467
if test x`pg_getlocale CTYPE` = x`pg_getlocale COLLATE` \
   && test x`pg_getlocale CTYPE` = x`pg_getlocale TIME` \
   && test x`pg_getlocale CTYPE` = x`pg_getlocale NUMERIC` \
   && test x`pg_getlocale CTYPE` = x`pg_getlocale MONETARY` \
   && test x`pg_getlocale CTYPE` = x`pg_getlocale MESSAGES`
468 469 470 471 472 473 474 475 476
then
    echo "The database cluster will be initialized with locale `pg_getlocale CTYPE`."
else
    echo "The database cluster will be initialized with locales:"
    echo "    COLLATE:  `pg_getlocale COLLATE`${TAB}CTYPE:   `pg_getlocale CTYPE`${TAB}MESSAGES: `pg_getlocale MESSAGES`"
    echo "    MONETARY: `pg_getlocale MONETARY`${TAB}NUMERIC: `pg_getlocale NUMERIC`${TAB}TIME:     `pg_getlocale TIME`"
fi

# (Be sure to maintain the correspondence with locale_is_like_safe() in selfuncs.c.)
477
if test x`pg_getlocale COLLATE` != xC && test x`pg_getlocale COLLATE` != xPOSIX; then
478 479 480 481 482 483 484
    echo "This locale setting will prevent the use of indexes for pattern matching"
    echo "operations.  If that is a concern, rerun $CMDNAME with the collation order"
    echo "set to \"C\".  For more information see the Administrator's Guide."
fi
echo


485 486 487
##########################################################################
#
# CREATE DATABASE DIRECTORY
M
 
Marc G. Fournier 已提交
488 489 490 491

# umask must disallow access to group, other for files and dirs
umask 077

492 493 494
# find out if directory is empty
pgdata_contents=`ls -A "$PGDATA" 2>/dev/null`
if [ x"$pgdata_contents" != x ]
495
then
496 497 498 499
    (
      echo "$CMDNAME: The directory $PGDATA exists but is not empty."
      echo "If you want to create a new database system, either remove or empty"
      echo "the directory $PGDATA or run initdb with"
500
      echo "an argument other than $PGDATA."
501 502 503
    ) 1>&2
    exit 1
else
504 505 506 507 508 509 510 511 512
    if [ ! -d "$PGDATA" ]; then
        $ECHO_N "creating directory $PGDATA... "$ECHO_C
        mkdir -p "$PGDATA" >/dev/null 2>&1 || mkdir "$PGDATA" || exit_nicely
        made_new_pgdata=yes
    else
        $ECHO_N "Fixing permissions on existing directory $PGDATA... "$ECHO_C
	chmod go-rwx "$PGDATA" || exit_nicely
    fi
    echo "ok"
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
    if [ ! -d "$PGDATA"/base ]
	then
        $ECHO_N "creating directory $PGDATA/base... "$ECHO_C
        mkdir "$PGDATA"/base || exit_nicely
	echo "ok"
    fi
    if [ ! -d "$PGDATA"/global ]
    then
        $ECHO_N "creating directory $PGDATA/global... "$ECHO_C
        mkdir "$PGDATA"/global || exit_nicely
	echo "ok"
    fi
    if [ ! -d "$PGDATA"/pg_xlog ]
    then
        $ECHO_N "creating directory $PGDATA/pg_xlog... "$ECHO_C
        mkdir "$PGDATA"/pg_xlog || exit_nicely
	echo "ok"
    fi
    if [ ! -d "$PGDATA"/pg_clog ]
    then
        $ECHO_N "creating directory $PGDATA/pg_clog... "$ECHO_C
        mkdir "$PGDATA"/pg_clog || exit_nicely
	echo "ok"
    fi
M
 
Marc G. Fournier 已提交
538 539
fi

540 541 542

##########################################################################
#
543
# RUN BKI SCRIPT IN BOOTSTRAP MODE TO CREATE TEMPLATE1
M
 
Marc G. Fournier 已提交
544

545
# common backend options
546
PGSQL_OPT="-F -D$PGDATA"
M
 
Marc G. Fournier 已提交
547

548
if [ "$debug" = yes ]
549
then
550
    BACKEND_TALK_ARG="-d 5"
551 552
else
    PGSQL_OPT="$PGSQL_OPT -o /dev/null"
M
 
Marc G. Fournier 已提交
553 554 555
fi


556 557 558 559
$ECHO_N "creating template1 database in $PGDATA/base/1... "$ECHO_C

rm -rf "$PGDATA"/base/1 || exit_nicely
mkdir "$PGDATA"/base/1 || exit_nicely
M
 
Marc G. Fournier 已提交
560

561 562 563
# Top level PG_VERSION is checked by bootstrapper, so make it first
echo "$short_version" > "$PGDATA/PG_VERSION" || exit_nicely

564 565
cat "$POSTGRES_BKI" \
| sed -e "s/POSTGRES/$POSTGRES_SUPERUSERNAME/g" \
566
      -e "s/ENCODING/$ENCODINGID/g" \
567 568 569 570 571 572 573 574 575
| 
(
  LC_COLLATE=`pg_getlocale COLLATE`
  LC_CTYPE=`pg_getlocale CTYPE`
  export LC_COLLATE
  export LC_CTYPE
  unset LC_ALL
  "$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BACKEND_TALK_ARG template1
) \
576
|| exit_nicely
M
 
Marc G. Fournier 已提交
577

578 579
# Make the per-database PGVERSION for template1 only after init'ing it
echo "$short_version" > "$PGDATA/base/1/PG_VERSION" || exit_nicely
M
 
Marc G. Fournier 已提交
580

581 582
echo "ok"

583 584
##########################################################################
#
585
# CREATE CONFIG FILES
586

587 588
$ECHO_N "creating configuration files... "$ECHO_C

589 590
cp "$PG_HBA_SAMPLE" "$PGDATA"/pg_hba.conf              || exit_nicely
cp "$PG_IDENT_SAMPLE" "$PGDATA"/pg_ident.conf          || exit_nicely
591 592 593 594 595 596 597 598 599 600 601 602 603
(
  cat "$POSTGRESQL_CONF_SAMPLE"
  echo
  echo
  echo "#"
  echo "#	Locale settings"
  echo "#"
  echo "# (initialized by initdb -- may be changed)"
  for cat in MESSAGES MONETARY NUMERIC TIME; do
    echo "LC_$cat = '`pg_getlocale $cat`'"
  done
) > "$PGDATA"/postgresql.conf || exit_nicely

604 605
chmod 0600 "$PGDATA"/pg_hba.conf "$PGDATA"/pg_ident.conf \
	"$PGDATA"/postgresql.conf
M
 
Marc G. Fournier 已提交
606

607 608
echo "ok"

609 610 611
##########################################################################
#
# CREATE VIEWS and other things
612 613 614 615 616
#
# NOTE: because here we are driving a standalone backend (not psql), we must
# follow the standalone backend's convention that commands end at a newline.
# To break an SQL command across lines in this script, backslash-escape all
# internal newlines in the command.
617

618
PGSQL_OPT="$PGSQL_OPT -O -c search_path=pg_catalog"
M
 
Marc G. Fournier 已提交
619

620
$ECHO_N "initializing pg_shadow... "$ECHO_C
M
 
Marc G. Fournier 已提交
621

622 623
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
-- Create a trigger so that direct updates to pg_shadow will be written
B
Bruce Momjian 已提交
624
-- to the flat password/group files pg_pwd and pg_group
625
CREATE TRIGGER pg_sync_pg_pwd AFTER INSERT OR UPDATE OR DELETE ON pg_shadow \
B
Bruce Momjian 已提交
626 627 628
FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd_and_pg_group();
CREATE TRIGGER pg_sync_pg_group AFTER INSERT OR UPDATE OR DELETE ON pg_group \
FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd_and_pg_group();
629 630 631 632 633 634 635
-- needs to be done before alter user, because alter user checks that
-- pg_shadow is secure ...
REVOKE ALL on pg_shadow FROM public;
EOF
if [ "$?" -ne 0 ]; then
    exit_nicely
fi
636
echo "ok"
637

P
Peter Eisentraut 已提交
638 639 640
# set up password
if [ "$PwPrompt" ]; then
    $ECHO_N "Enter new superuser password: "$ECHO_C
B
Bruce Momjian 已提交
641
    stty -echo > /dev/null 2>&1
P
Peter Eisentraut 已提交
642
    read FirstPw
B
Bruce Momjian 已提交
643
    stty echo > /dev/null 2>&1
P
Peter Eisentraut 已提交
644 645
    echo
    $ECHO_N "Enter it again: "$ECHO_C
B
Bruce Momjian 已提交
646
    stty -echo > /dev/null 2>&1
P
Peter Eisentraut 已提交
647
    read SecondPw
B
Bruce Momjian 已提交
648
    stty echo > /dev/null 2>&1
P
Peter Eisentraut 已提交
649 650
    echo
    if [ "$FirstPw" != "$SecondPw" ]; then
651
        echo "Passwords didn't match." 1>&2
P
Peter Eisentraut 已提交
652 653
        exit_nicely
    fi
654
    $ECHO_N "setting password... "$ECHO_C
655 656 657 658 659 660
    "$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
	ALTER USER "$POSTGRES_SUPERUSERNAME" WITH PASSWORD '$FirstPw';
EOF
    if [ "$?" -ne 0 ]; then
	exit_nicely
    fi
661
    if [ ! -f "$PGDATA"/global/pg_pwd ]; then
662
        echo
663
        echo "The password file wasn't generated. Please report this problem." 1>&2
P
Peter Eisentraut 已提交
664 665
        exit_nicely
    fi
B
Bruce Momjian 已提交
666 667 668 669 670
    if [ ! -f "$PGDATA"/global/pg_group ]; then
        echo
        echo "The group file wasn't generated. Please report this problem." 1>&2
        exit_nicely
    fi
671
    echo "ok"
P
Peter Eisentraut 已提交
672 673
fi

674
$ECHO_N "enabling unlimited row size for system tables... "$ECHO_C
675

676 677
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
ALTER TABLE pg_attrdef CREATE TOAST TABLE;
678
ALTER TABLE pg_constraint CREATE TOAST TABLE;
679
ALTER TABLE pg_database CREATE TOAST TABLE;
680
ALTER TABLE pg_description CREATE TOAST TABLE;
681
ALTER TABLE pg_group CREATE TOAST TABLE;
682 683
ALTER TABLE pg_proc CREATE TOAST TABLE;
ALTER TABLE pg_rewrite CREATE TOAST TABLE;
684
ALTER TABLE pg_shadow CREATE TOAST TABLE;
685 686 687 688 689
ALTER TABLE pg_statistic CREATE TOAST TABLE;
EOF
if [ "$?" -ne 0 ]; then
    exit_nicely
fi
690
echo "ok"
691 692


693 694 695 696 697 698 699 700 701 702 703 704 705 706
$ECHO_N "initializing pg_depend... "$ECHO_C

"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
-- Make PIN entries in pg_depend for all objects made so far in the tables
-- that the dependency code handles.  This is overkill (the system doesn't
-- really depend on having every last weird datatype, for instance)
-- but generating only the minimum required set of dependencies seems hard.
-- Note that we deliberately do not pin the system views.
-- First delete any already-made entries; PINs override all else, and must
-- be the only entries for their objects.
DELETE FROM pg_depend;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_class;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_proc;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_type;
707
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_cast;
708 709 710 711
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_constraint;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_attrdef;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_language;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_operator;
712
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_opclass;
713 714
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_rewrite;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_trigger;
715 716 717
-- restriction here to avoid pinning the public namespace
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_namespace \
    WHERE nspname LIKE 'pg%';
718 719 720 721 722 723 724
EOF
if [ "$?" -ne 0 ]; then
    exit_nicely
fi
echo "ok"


725
$ECHO_N "creating system views... "$ECHO_C
726

727 728 729 730 731 732 733 734 735 736
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF

CREATE VIEW pg_user AS \
    SELECT \
        usename, \
        usesysid, \
        usecreatedb, \
        usesuper, \
        usecatupd, \
        '********'::text as passwd, \
737 738
        valuntil, \
        useconfig \
739 740 741 742
    FROM pg_shadow;

CREATE VIEW pg_rules AS \
    SELECT \
743
        N.nspname AS schemaname, \
744 745
        C.relname AS tablename, \
        R.rulename AS rulename, \
746 747 748
        pg_get_ruledef(R.oid) AS definition \
    FROM (pg_rewrite R JOIN pg_class C ON (C.oid = R.ev_class)) \
        LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
749
    WHERE R.rulename != '_RETURN';
750 751 752

CREATE VIEW pg_views AS \
    SELECT \
753
        N.nspname AS schemaname, \
754 755
        C.relname AS viewname, \
        pg_get_userbyid(C.relowner) AS viewowner, \
756 757
        pg_get_viewdef(C.oid) AS definition \
    FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
758 759 760 761
    WHERE C.relkind = 'v';

CREATE VIEW pg_tables AS \
    SELECT \
762
        N.nspname AS schemaname, \
763 764 765 766 767
        C.relname AS tablename, \
        pg_get_userbyid(C.relowner) AS tableowner, \
        C.relhasindex AS hasindexes, \
        C.relhasrules AS hasrules, \
        (C.reltriggers > 0) AS hastriggers \
768
    FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
769 770 771 772
    WHERE C.relkind IN ('r', 's');

CREATE VIEW pg_indexes AS \
    SELECT \
773
        N.nspname AS schemaname, \
774 775
        C.relname AS tablename, \
        I.relname AS indexname, \
776 777 778 779 780
        pg_get_indexdef(I.oid) AS indexdef \
    FROM pg_index X JOIN pg_class C ON (C.oid = X.indrelid) \
         JOIN pg_class I ON (I.oid = X.indexrelid) \
         LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
    WHERE C.relkind = 'r' AND I.relkind = 'i';
781 782 783

CREATE VIEW pg_stats AS \
    SELECT \
784
        nspname AS schemaname, \
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
        relname AS tablename, \
        attname AS attname, \
        stanullfrac AS null_frac, \
        stawidth AS avg_width, \
        stadistinct AS n_distinct, \
        CASE 1 \
            WHEN stakind1 THEN stavalues1 \
            WHEN stakind2 THEN stavalues2 \
            WHEN stakind3 THEN stavalues3 \
            WHEN stakind4 THEN stavalues4 \
        END AS most_common_vals, \
        CASE 1 \
            WHEN stakind1 THEN stanumbers1 \
            WHEN stakind2 THEN stanumbers2 \
            WHEN stakind3 THEN stanumbers3 \
            WHEN stakind4 THEN stanumbers4 \
        END AS most_common_freqs, \
        CASE 2 \
            WHEN stakind1 THEN stavalues1 \
            WHEN stakind2 THEN stavalues2 \
            WHEN stakind3 THEN stavalues3 \
            WHEN stakind4 THEN stavalues4 \
        END AS histogram_bounds, \
        CASE 3 \
            WHEN stakind1 THEN stanumbers1[1] \
            WHEN stakind2 THEN stanumbers2[1] \
            WHEN stakind3 THEN stanumbers3[1] \
            WHEN stakind4 THEN stanumbers4[1] \
        END AS correlation \
814 815 816 817
    FROM pg_statistic s JOIN pg_class c ON (c.oid = s.starelid) \
         JOIN pg_attribute a ON (c.oid = attrelid AND attnum = s.staattnum) \
         LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace) \
    WHERE has_table_privilege(c.oid, 'select');
818 819 820 821 822 823

REVOKE ALL on pg_statistic FROM public;

CREATE VIEW pg_stat_all_tables AS \
    SELECT \
            C.oid AS relid, \
824
            N.nspname AS schemaname, \
825 826 827 828 829 830 831 832
            C.relname AS relname, \
            pg_stat_get_numscans(C.oid) AS seq_scan, \
            pg_stat_get_tuples_returned(C.oid) AS seq_tup_read, \
            sum(pg_stat_get_numscans(I.indexrelid)) AS idx_scan, \
            sum(pg_stat_get_tuples_fetched(I.indexrelid)) AS idx_tup_fetch, \
            pg_stat_get_tuples_inserted(C.oid) AS n_tup_ins, \
            pg_stat_get_tuples_updated(C.oid) AS n_tup_upd, \
            pg_stat_get_tuples_deleted(C.oid) AS n_tup_del \
833
    FROM pg_class C LEFT JOIN \
834
         pg_index I ON C.oid = I.indrelid \
835
         LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
836
    WHERE C.relkind = 'r' \
837
    GROUP BY C.oid, N.nspname, C.relname;
838 839 840

CREATE VIEW pg_stat_sys_tables AS \
    SELECT * FROM pg_stat_all_tables \
841
    WHERE schemaname IN ('pg_catalog', 'pg_toast');
842 843 844

CREATE VIEW pg_stat_user_tables AS \
    SELECT * FROM pg_stat_all_tables \
845
    WHERE schemaname NOT IN ('pg_catalog', 'pg_toast');
846 847 848 849

CREATE VIEW pg_statio_all_tables AS \
    SELECT \
            C.oid AS relid, \
850
            N.nspname AS schemaname, \
851 852 853 854 855 856 857 858 859 860 861 862 863
            C.relname AS relname, \
            pg_stat_get_blocks_fetched(C.oid) - \
                    pg_stat_get_blocks_hit(C.oid) AS heap_blks_read, \
            pg_stat_get_blocks_hit(C.oid) AS heap_blks_hit, \
            sum(pg_stat_get_blocks_fetched(I.indexrelid) - \
                    pg_stat_get_blocks_hit(I.indexrelid)) AS idx_blks_read, \
            sum(pg_stat_get_blocks_hit(I.indexrelid)) AS idx_blks_hit, \
            pg_stat_get_blocks_fetched(T.oid) - \
                    pg_stat_get_blocks_hit(T.oid) AS toast_blks_read, \
            pg_stat_get_blocks_hit(T.oid) AS toast_blks_hit, \
            pg_stat_get_blocks_fetched(X.oid) - \
                    pg_stat_get_blocks_hit(X.oid) AS tidx_blks_read, \
            pg_stat_get_blocks_hit(X.oid) AS tidx_blks_hit \
864 865 866
    FROM pg_class C LEFT JOIN \
            pg_index I ON C.oid = I.indrelid LEFT JOIN \
            pg_class T ON C.reltoastrelid = T.oid LEFT JOIN \
867
            pg_class X ON T.reltoastidxid = X.oid \
868
            LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
869
    WHERE C.relkind = 'r' \
870
    GROUP BY C.oid, N.nspname, C.relname, T.oid, X.oid;
871 872 873

CREATE VIEW pg_statio_sys_tables AS \
    SELECT * FROM pg_statio_all_tables \
874
    WHERE schemaname IN ('pg_catalog', 'pg_toast');
875 876 877

CREATE VIEW pg_statio_user_tables AS \
    SELECT * FROM pg_statio_all_tables \
878
    WHERE schemaname NOT IN ('pg_catalog', 'pg_toast');
879 880 881 882 883

CREATE VIEW pg_stat_all_indexes AS \
    SELECT \
            C.oid AS relid, \
            I.oid AS indexrelid, \
884
            N.nspname AS schemaname, \
885 886 887 888 889
            C.relname AS relname, \
            I.relname AS indexrelname, \
            pg_stat_get_numscans(I.oid) AS idx_scan, \
            pg_stat_get_tuples_returned(I.oid) AS idx_tup_read, \
            pg_stat_get_tuples_fetched(I.oid) AS idx_tup_fetch \
890 891 892 893 894
    FROM pg_class C JOIN \
            pg_index X ON C.oid = X.indrelid JOIN \
            pg_class I ON I.oid = X.indexrelid \
            LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
    WHERE C.relkind = 'r';
895 896 897

CREATE VIEW pg_stat_sys_indexes AS \
    SELECT * FROM pg_stat_all_indexes \
898
    WHERE schemaname IN ('pg_catalog', 'pg_toast');
899 900 901

CREATE VIEW pg_stat_user_indexes AS \
    SELECT * FROM pg_stat_all_indexes \
902
    WHERE schemaname NOT IN ('pg_catalog', 'pg_toast');
903 904 905 906 907

CREATE VIEW pg_statio_all_indexes AS \
    SELECT \
            C.oid AS relid, \
            I.oid AS indexrelid, \
908
            N.nspname AS schemaname, \
909 910 911 912 913
            C.relname AS relname, \
            I.relname AS indexrelname, \
            pg_stat_get_blocks_fetched(I.oid) - \
                    pg_stat_get_blocks_hit(I.oid) AS idx_blks_read, \
            pg_stat_get_blocks_hit(I.oid) AS idx_blks_hit \
914 915 916 917 918
    FROM pg_class C JOIN \
            pg_index X ON C.oid = X.indrelid JOIN \
            pg_class I ON I.oid = X.indexrelid \
            LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
    WHERE C.relkind = 'r';
919 920 921

CREATE VIEW pg_statio_sys_indexes AS \
    SELECT * FROM pg_statio_all_indexes \
922
    WHERE schemaname IN ('pg_catalog', 'pg_toast');
923 924 925

CREATE VIEW pg_statio_user_indexes AS \
    SELECT * FROM pg_statio_all_indexes \
926
    WHERE schemaname NOT IN ('pg_catalog', 'pg_toast');
927 928 929 930

CREATE VIEW pg_statio_all_sequences AS \
    SELECT \
            C.oid AS relid, \
931
            N.nspname AS schemaname, \
932 933 934 935 936
            C.relname AS relname, \
            pg_stat_get_blocks_fetched(C.oid) - \
                    pg_stat_get_blocks_hit(C.oid) AS blks_read, \
            pg_stat_get_blocks_hit(C.oid) AS blks_hit \
    FROM pg_class C \
937
            LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
938 939 940 941
    WHERE C.relkind = 'S';

CREATE VIEW pg_statio_sys_sequences AS \
    SELECT * FROM pg_statio_all_sequences \
942
    WHERE schemaname IN ('pg_catalog', 'pg_toast');
943 944 945

CREATE VIEW pg_statio_user_sequences AS \
    SELECT * FROM pg_statio_all_sequences \
946
    WHERE schemaname NOT IN ('pg_catalog', 'pg_toast');
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973

CREATE VIEW pg_stat_activity AS \
    SELECT \
            D.oid AS datid, \
            D.datname AS datname, \
            pg_stat_get_backend_pid(S.backendid) AS procpid, \
            pg_stat_get_backend_userid(S.backendid) AS usesysid, \
            U.usename AS usename, \
            pg_stat_get_backend_activity(S.backendid) AS current_query \
    FROM pg_database D, \
            (SELECT pg_stat_get_backend_idset() AS backendid) AS S, \
            pg_shadow U \
    WHERE pg_stat_get_backend_dbid(S.backendid) = D.oid AND \
            pg_stat_get_backend_userid(S.backendid) = U.usesysid;

CREATE VIEW pg_stat_database AS \
    SELECT \
            D.oid AS datid, \
            D.datname AS datname, \
            pg_stat_get_db_numbackends(D.oid) AS numbackends, \
            pg_stat_get_db_xact_commit(D.oid) AS xact_commit, \
            pg_stat_get_db_xact_rollback(D.oid) AS xact_rollback, \
            pg_stat_get_db_blocks_fetched(D.oid) - \
                    pg_stat_get_db_blocks_hit(D.oid) AS blks_read, \
            pg_stat_get_db_blocks_hit(D.oid) AS blks_hit \
    FROM pg_database D;

974
CREATE VIEW pg_locks AS \
975 976 977
    SELECT * \
    FROM pg_lock_status() AS L(relation oid, database oid, \
	transaction xid, pid int4, mode text, granted boolean);
978

979
CREATE VIEW pg_settings AS \
980
    SELECT * \
981 982 983 984 985 986 987 988 989 990 991
    FROM pg_show_all_settings() AS A(name text, setting text);

CREATE RULE pg_settings_u AS \
    ON UPDATE TO pg_settings \
    WHERE new.name = old.name DO \
    SELECT set_config(old.name, new.setting, 'f');

CREATE RULE pg_settings_n AS \
    ON UPDATE TO pg_settings \
    DO INSTEAD NOTHING;

992 993 994 995
EOF
if [ "$?" -ne 0 ]; then
    exit_nicely
fi
996
echo "ok"
997

998
$ECHO_N "loading pg_description... "$ECHO_C
999
(
1000 1001 1002 1003 1004 1005 1006 1007
  cat <<EOF
    CREATE TEMP TABLE tmp_pg_description ( \
	objoid oid, \
	classname name, \
	objsubid int4, \
	description text) WITHOUT OIDS;
    COPY tmp_pg_description FROM STDIN;
EOF
1008
  cat "$POSTGRES_DESCR"
1009 1010 1011 1012 1013 1014
  cat <<EOF
\.
    INSERT INTO pg_description SELECT \
	t.objoid, c.oid, t.objsubid, t.description \
    FROM tmp_pg_description t, pg_class c WHERE c.relname = t.classname;
EOF
1015
) \
1016
	| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
1017
echo "ok"
1018

1019 1020
# Create pg_conversion and support functions
$ECHO_N "creating conversions... "$ECHO_C
1021
grep -v '^DROP CONVERSION' $datadir/conversion_create.sql | "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
1022 1023
echo "ok"

1024 1025 1026 1027 1028 1029 1030 1031 1032
# Set most system catalogs and built-in functions as world-accessible.
# Some objects may require different permissions by default, so we
# make sure we don't overwrite privilege sets that have already been
# set (NOT NULL).
$ECHO_N "setting privileges on built-in objects... "$ECHO_C
(
  cat <<EOF
    UPDATE pg_class SET relacl = '{"=r"}' \
        WHERE relkind IN ('r', 'v', 'S') AND relacl IS NULL;
1033
    UPDATE pg_proc SET proacl = '{"=X"}' \
1034
        WHERE proacl IS NULL;
1035
    UPDATE pg_language SET lanacl = '{"=U"}' \
1036
        WHERE lanpltrusted;
1037 1038
    UPDATE pg_language SET lanacl = '{"="}' \
        WHERE NOT lanpltrusted;
1039 1040 1041 1042 1043
EOF
) \
	| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
echo "ok"

1044
$ECHO_N "vacuuming database template1... "$ECHO_C
1045 1046

"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
1047
ANALYZE;
1048
VACUUM FULL FREEZE;
1049 1050 1051 1052
EOF
if [ "$?" -ne 0 ]; then
    exit_nicely
fi
1053
echo "ok"
1054

1055
$ECHO_N "copying template1 to template0... "$ECHO_C
1056 1057 1058

"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
CREATE DATABASE template0;
1059

1060
UPDATE pg_database SET \
1061 1062
	datistemplate = 't', \
	datallowconn = 'f' \
1063
    WHERE datname = 'template0';
1064 1065 1066 1067

-- We use the OID of template0 to determine lastsysoid

UPDATE pg_database SET datlastsysoid = \
1068
    (SELECT oid::int4 - 1 FROM pg_database WHERE datname = 'template0');
1069

1070 1071 1072 1073 1074 1075 1076 1077
-- Explicitly revoke public create-schema and create-temp-table privileges
-- in template1 and template0; else the latter would be on by default

REVOKE CREATE,TEMPORARY ON DATABASE template1 FROM public;
REVOKE CREATE,TEMPORARY ON DATABASE template0 FROM public;

-- Finally vacuum to clean up dead rows in pg_database

1078 1079 1080 1081 1082
VACUUM FULL pg_database;
EOF
if [ "$?" -ne 0 ]; then
    exit_nicely
fi
1083
echo "ok"
1084

1085 1086 1087 1088 1089

##########################################################################
#
# FINISHED

1090
echo
1091
echo "Success. You can now start the database server using:"
1092
echo ""
1093
echo "    $PGPATH/postmaster -D $PGDATA"
1094
echo "or"
1095 1096
# (Advertise -l option here, otherwise we have a background
#  process writing to the terminal.)
1097
echo "    $PGPATH/pg_ctl -D $PGDATA -l logfile start"
1098 1099 1100
echo

exit 0