mirror of
https://github.com/postgres/postgres.git
synced 2025-06-03 00:02:26 -04:00
Change SQL commands embedded in the initdb script from the style
echo "command" | postgres to the style postgres <<EOF command EOF This makes the script more legible (IMHO anyway) by reducing the need to escape quotes, and allows us to execute successive SQL commands in a single standalone-backend run, rather than needing to start a new standalone backend for each command. With all the CREATE VIEWs that are getting done now, this makes for a rather substantial reduction in the runtime of initdb. (Some of us do initdb often enough to care how long it runs ;-).)
This commit is contained in:
parent
9c2b1a92b5
commit
267a8f82bf
@ -27,7 +27,7 @@
|
|||||||
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
# Portions Copyright (c) 1994, Regents of the University of California
|
# Portions Copyright (c) 1994, Regents of the University of California
|
||||||
#
|
#
|
||||||
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.130 2001/07/15 22:48:18 tgl Exp $
|
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.131 2001/07/31 01:16:09 tgl Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -478,21 +478,28 @@ chmod 0600 "$PGDATA"/pg_hba.conf "$PGDATA"/pg_ident.conf \
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
#
|
#
|
||||||
# CREATE VIEWS and other things
|
# CREATE VIEWS and other things
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
echo "Initializing pg_shadow."
|
echo "Initializing pg_shadow."
|
||||||
|
|
||||||
PGSQL_OPT="-o /dev/null -O -F -D$PGDATA"
|
PGSQL_OPT="-o /dev/null -O -F -D$PGDATA"
|
||||||
|
|
||||||
# Create a trigger so that direct updates to pg_shadow will be written
|
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
|
||||||
# to the flat password file pg_pwd
|
-- Create a trigger so that direct updates to pg_shadow will be written
|
||||||
echo "CREATE TRIGGER pg_sync_pg_pwd AFTER INSERT OR UPDATE OR DELETE ON pg_shadow" \
|
-- to the flat password file pg_pwd
|
||||||
"FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd()" \
|
CREATE TRIGGER pg_sync_pg_pwd AFTER INSERT OR UPDATE OR DELETE ON pg_shadow \
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd();
|
||||||
|
-- needs to be done before alter user, because alter user checks that
|
||||||
# needs to be done before alter user, because alter user checks that
|
-- pg_shadow is secure ...
|
||||||
# pg_shadow is secure ...
|
REVOKE ALL on pg_shadow FROM public;
|
||||||
echo "REVOKE ALL on pg_shadow FROM public" \
|
EOF
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
if [ "$?" -ne 0 ]; then
|
||||||
|
exit_nicely
|
||||||
|
fi
|
||||||
|
|
||||||
# set up password
|
# set up password
|
||||||
if [ "$PwPrompt" ]; then
|
if [ "$PwPrompt" ]; then
|
||||||
@ -510,8 +517,12 @@ if [ "$PwPrompt" ]; then
|
|||||||
echo "Passwords didn't match." 1>&2
|
echo "Passwords didn't match." 1>&2
|
||||||
exit_nicely
|
exit_nicely
|
||||||
fi
|
fi
|
||||||
echo "ALTER USER \"$POSTGRES_SUPERUSERNAME\" WITH PASSWORD '$FirstPw'" \
|
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
ALTER USER "$POSTGRES_SUPERUSERNAME" WITH PASSWORD '$FirstPw';
|
||||||
|
EOF
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
exit_nicely
|
||||||
|
fi
|
||||||
if [ ! -f $PGDATA/global/pg_pwd ]; then
|
if [ ! -f $PGDATA/global/pg_pwd ]; then
|
||||||
echo "The password file wasn't generated. Please report this problem." 1>&2
|
echo "The password file wasn't generated. Please report this problem." 1>&2
|
||||||
exit_nicely
|
exit_nicely
|
||||||
@ -522,23 +533,24 @@ fi
|
|||||||
|
|
||||||
echo "Enabling unlimited row width for system tables."
|
echo "Enabling unlimited row width for system tables."
|
||||||
|
|
||||||
echo "ALTER TABLE pg_attrdef CREATE TOAST TABLE" \
|
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
ALTER TABLE pg_attrdef CREATE TOAST TABLE;
|
||||||
echo "ALTER TABLE pg_description CREATE TOAST TABLE" \
|
ALTER TABLE pg_description CREATE TOAST TABLE;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
ALTER TABLE pg_proc CREATE TOAST TABLE;
|
||||||
echo "ALTER TABLE pg_proc CREATE TOAST TABLE" \
|
ALTER TABLE pg_relcheck CREATE TOAST TABLE;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
ALTER TABLE pg_rewrite CREATE TOAST TABLE;
|
||||||
echo "ALTER TABLE pg_relcheck CREATE TOAST TABLE" \
|
ALTER TABLE pg_statistic CREATE TOAST TABLE;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
EOF
|
||||||
echo "ALTER TABLE pg_rewrite CREATE TOAST TABLE" \
|
if [ "$?" -ne 0 ]; then
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
exit_nicely
|
||||||
echo "ALTER TABLE pg_statistic CREATE TOAST TABLE" \
|
fi
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
|
|
||||||
echo "Creating system views."
|
echo "Creating system views."
|
||||||
|
|
||||||
echo "CREATE VIEW pg_user AS \
|
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
|
||||||
|
|
||||||
|
CREATE VIEW pg_user AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
usename, \
|
usename, \
|
||||||
usesysid, \
|
usesysid, \
|
||||||
@ -548,31 +560,28 @@ echo "CREATE VIEW pg_user AS \
|
|||||||
usecatupd, \
|
usecatupd, \
|
||||||
'********'::text as passwd, \
|
'********'::text as passwd, \
|
||||||
valuntil \
|
valuntil \
|
||||||
FROM pg_shadow" \
|
FROM pg_shadow;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_rules AS \
|
CREATE VIEW pg_rules AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.relname AS tablename, \
|
C.relname AS tablename, \
|
||||||
R.rulename AS rulename, \
|
R.rulename AS rulename, \
|
||||||
pg_get_ruledef(R.rulename) AS definition \
|
pg_get_ruledef(R.rulename) AS definition \
|
||||||
FROM pg_rewrite R, pg_class C \
|
FROM pg_rewrite R, pg_class C \
|
||||||
WHERE R.rulename !~ '^_RET' \
|
WHERE R.rulename !~ '^_RET' \
|
||||||
AND C.oid = R.ev_class;" \
|
AND C.oid = R.ev_class;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_views AS \
|
CREATE VIEW pg_views AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.relname AS viewname, \
|
C.relname AS viewname, \
|
||||||
pg_get_userbyid(C.relowner) AS viewowner, \
|
pg_get_userbyid(C.relowner) AS viewowner, \
|
||||||
pg_get_viewdef(C.relname) AS definition \
|
pg_get_viewdef(C.relname) AS definition \
|
||||||
FROM pg_class C \
|
FROM pg_class C \
|
||||||
WHERE C.relkind = 'v';" \
|
WHERE C.relkind = 'v';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
# XXX why does pg_tables include sequences?
|
-- XXX why does pg_tables include sequences?
|
||||||
|
|
||||||
echo "CREATE VIEW pg_tables AS \
|
CREATE VIEW pg_tables AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.relname AS tablename, \
|
C.relname AS tablename, \
|
||||||
pg_get_userbyid(C.relowner) AS tableowner, \
|
pg_get_userbyid(C.relowner) AS tableowner, \
|
||||||
@ -580,10 +589,9 @@ echo "CREATE VIEW pg_tables AS \
|
|||||||
C.relhasrules AS hasrules, \
|
C.relhasrules AS hasrules, \
|
||||||
(C.reltriggers > 0) AS hastriggers \
|
(C.reltriggers > 0) AS hastriggers \
|
||||||
FROM pg_class C \
|
FROM pg_class C \
|
||||||
WHERE C.relkind IN ('r', 's');" \
|
WHERE C.relkind IN ('r', 's');
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_indexes AS \
|
CREATE VIEW pg_indexes AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.relname AS tablename, \
|
C.relname AS tablename, \
|
||||||
I.relname AS indexname, \
|
I.relname AS indexname, \
|
||||||
@ -591,10 +599,9 @@ echo "CREATE VIEW pg_indexes AS \
|
|||||||
FROM pg_index X, pg_class C, pg_class I \
|
FROM pg_index X, pg_class C, pg_class I \
|
||||||
WHERE C.relkind = 'r' AND I.relkind = 'i' \
|
WHERE C.relkind = 'r' AND I.relkind = 'i' \
|
||||||
AND C.oid = X.indrelid \
|
AND C.oid = X.indrelid \
|
||||||
AND I.oid = X.indexrelid;" \
|
AND I.oid = X.indexrelid;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stats AS \
|
CREATE VIEW pg_stats AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
relname AS tablename, \
|
relname AS tablename, \
|
||||||
attname AS attname, \
|
attname AS attname, \
|
||||||
@ -628,13 +635,11 @@ echo "CREATE VIEW pg_stats AS \
|
|||||||
FROM pg_class c, pg_attribute a, pg_statistic s \
|
FROM pg_class c, pg_attribute a, pg_statistic s \
|
||||||
WHERE c.oid = s.starelid AND c.oid = a.attrelid \
|
WHERE c.oid = s.starelid AND c.oid = a.attrelid \
|
||||||
AND a.attnum = s.staattnum \
|
AND a.attnum = s.staattnum \
|
||||||
AND has_table_privilege(c.oid, 'select');" \
|
AND has_table_privilege(c.oid, 'select');
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "REVOKE ALL on pg_statistic FROM public" \
|
REVOKE ALL on pg_statistic FROM public;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_all_tables AS \
|
CREATE VIEW pg_stat_all_tables AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.oid AS relid, \
|
C.oid AS relid, \
|
||||||
C.relname AS relname, \
|
C.relname AS relname, \
|
||||||
@ -648,20 +653,17 @@ echo "CREATE VIEW pg_stat_all_tables AS \
|
|||||||
FROM pg_class C FULL OUTER JOIN \
|
FROM pg_class C FULL OUTER JOIN \
|
||||||
pg_index I ON C.oid = I.indrelid \
|
pg_index I ON C.oid = I.indrelid \
|
||||||
WHERE C.relkind = 'r' \
|
WHERE C.relkind = 'r' \
|
||||||
GROUP BY C.oid, C.relname;" \
|
GROUP BY C.oid, C.relname;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_sys_tables AS \
|
CREATE VIEW pg_stat_sys_tables AS \
|
||||||
SELECT * FROM pg_stat_all_tables \
|
SELECT * FROM pg_stat_all_tables \
|
||||||
WHERE relname ~ '^pg_';" \
|
WHERE relname ~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_user_tables AS \
|
CREATE VIEW pg_stat_user_tables AS \
|
||||||
SELECT * FROM pg_stat_all_tables \
|
SELECT * FROM pg_stat_all_tables \
|
||||||
WHERE relname !~ '^pg_';" \
|
WHERE relname !~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_all_tables AS \
|
CREATE VIEW pg_statio_all_tables AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.oid AS relid, \
|
C.oid AS relid, \
|
||||||
C.relname AS relname, \
|
C.relname AS relname, \
|
||||||
@ -682,20 +684,17 @@ echo "CREATE VIEW pg_statio_all_tables AS \
|
|||||||
pg_class T ON C.reltoastrelid = T.oid FULL OUTER JOIN \
|
pg_class T ON C.reltoastrelid = T.oid FULL OUTER JOIN \
|
||||||
pg_class X ON C.reltoastidxid = X.oid \
|
pg_class X ON C.reltoastidxid = X.oid \
|
||||||
WHERE C.relkind = 'r' \
|
WHERE C.relkind = 'r' \
|
||||||
GROUP BY C.oid, C.relname, T.oid, X.oid;" \
|
GROUP BY C.oid, C.relname, T.oid, X.oid;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_sys_tables AS \
|
CREATE VIEW pg_statio_sys_tables AS \
|
||||||
SELECT * FROM pg_statio_all_tables \
|
SELECT * FROM pg_statio_all_tables \
|
||||||
WHERE relname ~ '^pg_';" \
|
WHERE relname ~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_user_tables AS \
|
CREATE VIEW pg_statio_user_tables AS \
|
||||||
SELECT * FROM pg_statio_all_tables \
|
SELECT * FROM pg_statio_all_tables \
|
||||||
WHERE relname !~ '^pg_';" \
|
WHERE relname !~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_all_indexes AS \
|
CREATE VIEW pg_stat_all_indexes AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.oid AS relid, \
|
C.oid AS relid, \
|
||||||
I.oid AS indexrelid, \
|
I.oid AS indexrelid, \
|
||||||
@ -709,20 +708,17 @@ echo "CREATE VIEW pg_stat_all_indexes AS \
|
|||||||
pg_index X \
|
pg_index X \
|
||||||
WHERE C.relkind = 'r' AND \
|
WHERE C.relkind = 'r' AND \
|
||||||
X.indrelid = C.oid AND \
|
X.indrelid = C.oid AND \
|
||||||
X.indexrelid = I.oid;" \
|
X.indexrelid = I.oid;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_sys_indexes AS \
|
CREATE VIEW pg_stat_sys_indexes AS \
|
||||||
SELECT * FROM pg_stat_all_indexes \
|
SELECT * FROM pg_stat_all_indexes \
|
||||||
WHERE relname ~ '^pg_';" \
|
WHERE relname ~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_user_indexes AS \
|
CREATE VIEW pg_stat_user_indexes AS \
|
||||||
SELECT * FROM pg_stat_all_indexes \
|
SELECT * FROM pg_stat_all_indexes \
|
||||||
WHERE relname !~ '^pg_';" \
|
WHERE relname !~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_all_indexes AS \
|
CREATE VIEW pg_statio_all_indexes AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.oid AS relid, \
|
C.oid AS relid, \
|
||||||
I.oid AS indexrelid, \
|
I.oid AS indexrelid, \
|
||||||
@ -736,20 +732,17 @@ echo "CREATE VIEW pg_statio_all_indexes AS \
|
|||||||
pg_index X \
|
pg_index X \
|
||||||
WHERE C.relkind = 'r' AND \
|
WHERE C.relkind = 'r' AND \
|
||||||
X.indrelid = C.oid AND \
|
X.indrelid = C.oid AND \
|
||||||
X.indexrelid = I.oid;" \
|
X.indexrelid = I.oid;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_sys_indexes AS \
|
CREATE VIEW pg_statio_sys_indexes AS \
|
||||||
SELECT * FROM pg_statio_all_indexes \
|
SELECT * FROM pg_statio_all_indexes \
|
||||||
WHERE relname ~ '^pg_';" \
|
WHERE relname ~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_user_indexes AS \
|
CREATE VIEW pg_statio_user_indexes AS \
|
||||||
SELECT * FROM pg_statio_all_indexes \
|
SELECT * FROM pg_statio_all_indexes \
|
||||||
WHERE relname !~ '^pg_';" \
|
WHERE relname !~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_all_sequences AS \
|
CREATE VIEW pg_statio_all_sequences AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
C.oid AS relid, \
|
C.oid AS relid, \
|
||||||
C.relname AS relname, \
|
C.relname AS relname, \
|
||||||
@ -757,20 +750,17 @@ echo "CREATE VIEW pg_statio_all_sequences AS \
|
|||||||
pg_stat_get_blocks_hit(C.oid) AS blks_read, \
|
pg_stat_get_blocks_hit(C.oid) AS blks_read, \
|
||||||
pg_stat_get_blocks_hit(C.oid) AS blks_hit \
|
pg_stat_get_blocks_hit(C.oid) AS blks_hit \
|
||||||
FROM pg_class C \
|
FROM pg_class C \
|
||||||
WHERE C.relkind = 'S';" \
|
WHERE C.relkind = 'S';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_sys_sequences AS \
|
CREATE VIEW pg_statio_sys_sequences AS \
|
||||||
SELECT * FROM pg_statio_all_sequences \
|
SELECT * FROM pg_statio_all_sequences \
|
||||||
WHERE relname ~ '^pg_';" \
|
WHERE relname ~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_statio_user_sequences AS \
|
CREATE VIEW pg_statio_user_sequences AS \
|
||||||
SELECT * FROM pg_statio_all_sequences \
|
SELECT * FROM pg_statio_all_sequences \
|
||||||
WHERE relname !~ '^pg_';" \
|
WHERE relname !~ '^pg_';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_activity AS \
|
CREATE VIEW pg_stat_activity AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
D.oid AS datid, \
|
D.oid AS datid, \
|
||||||
D.datname AS datname, \
|
D.datname AS datname, \
|
||||||
@ -782,10 +772,9 @@ echo "CREATE VIEW pg_stat_activity AS \
|
|||||||
(SELECT pg_stat_get_backend_idset() AS backendid) AS S, \
|
(SELECT pg_stat_get_backend_idset() AS backendid) AS S, \
|
||||||
pg_shadow U \
|
pg_shadow U \
|
||||||
WHERE pg_stat_get_backend_dbid(S.backendid) = D.oid AND \
|
WHERE pg_stat_get_backend_dbid(S.backendid) = D.oid AND \
|
||||||
pg_stat_get_backend_userid(S.backendid) = U.usesysid;" \
|
pg_stat_get_backend_userid(S.backendid) = U.usesysid;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
|
||||||
echo "CREATE VIEW pg_stat_database AS \
|
CREATE VIEW pg_stat_database AS \
|
||||||
SELECT \
|
SELECT \
|
||||||
D.oid AS datid, \
|
D.oid AS datid, \
|
||||||
D.datname AS datname, \
|
D.datname AS datname, \
|
||||||
@ -795,8 +784,12 @@ echo "CREATE VIEW pg_stat_database AS \
|
|||||||
pg_stat_get_db_blocks_fetched(D.oid) - \
|
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_read, \
|
||||||
pg_stat_get_db_blocks_hit(D.oid) AS blks_hit \
|
pg_stat_get_db_blocks_hit(D.oid) AS blks_hit \
|
||||||
FROM pg_database D;" \
|
FROM pg_database D;
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
|
||||||
|
EOF
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
exit_nicely
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Loading pg_description."
|
echo "Loading pg_description."
|
||||||
(
|
(
|
||||||
@ -806,26 +799,39 @@ echo "Loading pg_description."
|
|||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
||||||
|
|
||||||
echo "Setting lastsysoid."
|
echo "Setting lastsysoid."
|
||||||
echo "UPDATE pg_database SET \
|
|
||||||
|
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
|
||||||
|
UPDATE pg_database SET \
|
||||||
datistemplate = 't', \
|
datistemplate = 't', \
|
||||||
datlastsysoid = (SELECT max(oid) FROM pg_description) \
|
datlastsysoid = (SELECT max(oid) FROM pg_description) \
|
||||||
WHERE datname = 'template1'" \
|
WHERE datname = 'template1';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
EOF
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
exit_nicely
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Vacuuming database."
|
echo "Vacuuming database."
|
||||||
echo "VACUUM FULL ANALYZE" \
|
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
|
||||||
|
VACUUM FULL ANALYZE;
|
||||||
|
EOF
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
exit_nicely
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Copying template1 to template0."
|
echo "Copying template1 to template0."
|
||||||
echo "CREATE DATABASE template0" \
|
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
"$PGPATH"/postgres $PGSQL_OPT template1 >/dev/null <<EOF
|
||||||
echo "UPDATE pg_database SET \
|
CREATE DATABASE template0;
|
||||||
|
UPDATE pg_database SET \
|
||||||
datistemplate = 't', \
|
datistemplate = 't', \
|
||||||
datallowconn = 'f' \
|
datallowconn = 'f' \
|
||||||
WHERE datname = 'template0'" \
|
WHERE datname = 'template0';
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
VACUUM FULL pg_database;
|
||||||
echo "VACUUM FULL pg_database" \
|
EOF
|
||||||
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
|
if [ "$?" -ne 0 ]; then
|
||||||
|
exit_nicely
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user