Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16ea152

Browse files
committed
Revoke public read access from pg_statistic, create new system view
pg_stats to provide controlled (and, hopefully, more readable) accessto statistics. Comments on definition of pg_stats welcome.I didn't force initdb, but the rules regress test will fail until youdo one.
1 parent5af4855 commit16ea152

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

‎src/bin/initdb/initdb.sh

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
2828
# Portions Copyright (c) 1994, Regents of the University of California
2929
#
30-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.126 2001/06/12 05:55:50 tgl Exp $
30+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.127 2001/06/14 19:47:25 tgl Exp $
3131
#
3232
#-------------------------------------------------------------------------
3333

@@ -497,7 +497,8 @@ echo "CREATE TRIGGER pg_sync_pg_pwd AFTER INSERT OR UPDATE OR DELETE ON pg_shado
497497
"FOR EACH ROW EXECUTE PROCEDURE update_pg_pwd()" \
498498
|"$PGPATH"/postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
499499

500-
# needs to be done before alter user
500+
# needs to be done before alter user, because alter user checks that
501+
# pg_shadow is secure ...
501502
echo"REVOKE ALL on pg_shadow FROM public" \
502503
|"$PGPATH"/postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
503504

@@ -601,6 +602,46 @@ echo "CREATE VIEW pg_indexes AS \
601602
AND I.oid = X.indexrelid;" \
602603
|"$PGPATH"/postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
603604

605+
echo"CREATE VIEW pg_stats AS\
606+
SELECT\
607+
relname AS tablename,\
608+
attname AS attname,\
609+
stanullfrac AS null_frac,\
610+
stawidth AS avg_width,\
611+
stadistinct AS n_distinct,\
612+
CASE 1\
613+
WHEN stakind1 THEN stavalues1\
614+
WHEN stakind2 THEN stavalues2\
615+
WHEN stakind3 THEN stavalues3\
616+
WHEN stakind4 THEN stavalues4\
617+
END AS most_common_vals,\
618+
CASE 1\
619+
WHEN stakind1 THEN stanumbers1\
620+
WHEN stakind2 THEN stanumbers2\
621+
WHEN stakind3 THEN stanumbers3\
622+
WHEN stakind4 THEN stanumbers4\
623+
END AS most_common_freqs,\
624+
CASE 2\
625+
WHEN stakind1 THEN stavalues1\
626+
WHEN stakind2 THEN stavalues2\
627+
WHEN stakind3 THEN stavalues3\
628+
WHEN stakind4 THEN stavalues4\
629+
END AS histogram_bounds,\
630+
CASE 3\
631+
WHEN stakind1 THEN stanumbers1[1]\
632+
WHEN stakind2 THEN stanumbers2[1]\
633+
WHEN stakind3 THEN stanumbers3[1]\
634+
WHEN stakind4 THEN stanumbers4[1]\
635+
END AS correlation\
636+
FROM pg_class c, pg_attribute a, pg_statistic s\
637+
WHERE c.oid = s.starelid AND c.oid = a.attrelid\
638+
AND a.attnum = s.staattnum\
639+
AND has_table_privilege(c.oid, 'select');" \
640+
|"$PGPATH"/postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
641+
642+
echo"REVOKE ALL on pg_statistic FROM public" \
643+
|"$PGPATH"/postgres$PGSQL_OPT template1> /dev/null|| exit_nicely
644+
604645
echo"Loading pg_description."
605646
echo"COPY pg_description FROM STDIN">$TEMPFILE
606647
cat"$POSTGRES_DESCR">>$TEMPFILE

‎src/test/regress/expected/rules.out

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,11 +1264,12 @@ drop table cchild;
12641264
-- Check that ruleutils are working
12651265
--
12661266
SELECT viewname, definition FROM pg_views ORDER BY viewname;
1267-
viewname | definition
1268-
--------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1267+
viewname | definition
1268+
--------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
12691269
iexit | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
12701270
pg_indexes | SELECT c.relname AS tablename, i.relname AS indexname, pg_get_indexdef(x.indexrelid) AS indexdef FROM pg_index x, pg_class c, pg_class i WHERE ((((c.relkind = 'r'::"char") AND (i.relkind = 'i'::"char")) AND (c.oid = x.indrelid)) AND (i.oid = x.indexrelid));
12711271
pg_rules | SELECT c.relname AS tablename, r.rulename, pg_get_ruledef(r.rulename) AS definition FROM pg_rewrite r, pg_class c WHERE ((r.rulename !~ '^_RET'::text) AND (c.oid = r.ev_class));
1272+
pg_stats | SELECT c.relname AS tablename, a.attname, s.stanullfrac AS null_frac, s.stawidth AS avg_width, s.stadistinct AS n_distinct, CASE WHEN (1 = s.stakind1) THEN s.stavalues1 WHEN (1 = s.stakind2) THEN s.stavalues2 WHEN (1 = s.stakind3) THEN s.stavalues3 WHEN (1 = s.stakind4) THEN s.stavalues4 ELSE NULL::"_text" END AS most_common_vals, CASE WHEN (1 = s.stakind1) THEN s.stanumbers1 WHEN (1 = s.stakind2) THEN s.stanumbers2 WHEN (1 = s.stakind3) THEN s.stanumbers3 WHEN (1 = s.stakind4) THEN s.stanumbers4 ELSE NULL::"_float4" END AS most_common_freqs, CASE WHEN (2 = s.stakind1) THEN s.stavalues1 WHEN (2 = s.stakind2) THEN s.stavalues2 WHEN (2 = s.stakind3) THEN s.stavalues3 WHEN (2 = s.stakind4) THEN s.stavalues4 ELSE NULL::"_text" END AS histogram_bounds, CASE WHEN (3 = s.stakind1) THEN s.stanumbers1[1] WHEN (3 = s.stakind2) THEN s.stanumbers2[1] WHEN (3 = s.stakind3) THEN s.stanumbers3[1] WHEN (3 = s.stakind4) THEN s.stanumbers4[1] ELSE NULL::float4 END AS correlation FROM pg_class c, pg_attribute a, pg_statistic s WHERE ((((c.oid = s.starelid) AND (c.oid = a.attrelid)) AND (a.attnum = s.staattnum)) AND has_table_privilege(c.oid, 'select'::text));
12721273
pg_tables | SELECT c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, c.relhasindex AS hasindexes, c.relhasrules AS hasrules, (c.reltriggers > 0) AS hastriggers FROM pg_class c WHERE ((c.relkind = 'r'::"char") OR (c.relkind = 's'::"char"));
12731274
pg_user | SELECT pg_shadow.usename, pg_shadow.usesysid, pg_shadow.usecreatedb, pg_shadow.usetrace, pg_shadow.usesuper, pg_shadow.usecatupd, '********'::text AS passwd, pg_shadow.valuntil FROM pg_shadow;
12741275
pg_views | SELECT c.relname AS viewname, pg_get_userbyid(c.relowner) AS viewowner, pg_get_viewdef(c.relname) AS definition FROM pg_class c WHERE (c.relkind = 'v'::"char");
@@ -1286,7 +1287,7 @@ SELECT viewname, definition FROM pg_views ORDER BY viewname;
12861287
shoelace_obsolete | SELECT shoelace.sl_name, shoelace.sl_avail, shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor = shoelace.sl_color))));
12871288
street | SELECT r.name, r.thepath, c.cname FROM ONLY road r, real_city c WHERE (c.outline ## r.thepath);
12881289
toyemp | SELECT emp.name, emp.age, emp."location", (12 * emp.salary) AS annualsal FROM emp;
1289-
(20 rows)
1290+
(21 rows)
12901291

12911292
SELECT tablename, rulename, definition FROM pg_rules
12921293
ORDER BY tablename, rulename;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp