pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedRemove superuser() checks from pgstattuple
14+ messages / 5 participants
[nested] [flat]
* Remove superuser() checks from pgstattuple
@ 2016-08-23 21:22 Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
0 siblings, 1 reply; 14+ messages in thread
From: Stephen Frost @ 2016-08-23 21:22 UTC (permalink / raw)
To: pgsql-hackers
Greetings,
Attached is an rebased and updated patch to remove the explicit
superuser() checks from the contrib extension pgstattuple, in favor of
using the GRANT system to control access, and give the admin flexibility
to GRANT access to this function without having to write wrapper
functions, similar to what was been done with the backend functions.
This, naturally, REVOKE's EXECUTE from public on installation for these
functions.
Prior discussion was on this thread:
20160408214511.GQ10850@tamriel.snowman.net
but it seemed prudent to open a new thread, to avoid anyone missing that
this isn't about default roles (which was the subject of that thread).
Thanks!
Stephen
Attachments:
pgstattuple-remove-superuser-checks_v3.patch (text/x-diff, 23.3K) download
From b4f04c81c88c126c470a7afc74ea9e4f860be412 Mon Sep 17 00:00:00 2001
From: Stephen Frost <sfrost@snowman.net>
Date: Tue, 23 Aug 2016 17:13:09 -0400
Subject: [PATCH] Remove superuser checks in pgstattuple
Now that we track initial privileges on extension objects and changes to
those permissions, we can drop the superuser() checks from the various
functions which are part of the pgstattuple extension.
Since a pg_upgrade will preserve the version of the extension which
existed prior to the upgrade, we can't simply modify the existing
functions but instead need to create new functions which remove the
checks and update the SQL-level functions to use the new functions
(and to REVOKE EXECUTE rights on those functions from PUBLIC).
Approach suggested by Noah.
---
contrib/pgstattuple/Makefile | 7 +-
contrib/pgstattuple/pgstatapprox.c | 35 ++++++--
contrib/pgstattuple/pgstatindex.c | 108 +++++++++++++++++++++++--
contrib/pgstattuple/pgstattuple--1.4--1.5.sql | 111 ++++++++++++++++++++++++++
contrib/pgstattuple/pgstattuple--1.4.sql | 95 ----------------------
contrib/pgstattuple/pgstattuple--1.5.sql | 111 ++++++++++++++++++++++++++
contrib/pgstattuple/pgstattuple.c | 36 +++++++++
contrib/pgstattuple/pgstattuple.control | 2 +-
8 files changed, 395 insertions(+), 110 deletions(-)
create mode 100644 contrib/pgstattuple/pgstattuple--1.4--1.5.sql
delete mode 100644 contrib/pgstattuple/pgstattuple--1.4.sql
create mode 100644 contrib/pgstattuple/pgstattuple--1.5.sql
diff --git a/contrib/pgstattuple/Makefile b/contrib/pgstattuple/Makefile
index e732680..dc5ddba 100644
--- a/contrib/pgstattuple/Makefile
+++ b/contrib/pgstattuple/Makefile
@@ -4,9 +4,10 @@ MODULE_big = pgstattuple
OBJS = pgstattuple.o pgstatindex.o pgstatapprox.o $(WIN32RES)
EXTENSION = pgstattuple
-DATA = pgstattuple--1.4.sql pgstattuple--1.3--1.4.sql \
- pgstattuple--1.2--1.3.sql pgstattuple--1.1--1.2.sql \
- pgstattuple--1.0--1.1.sql pgstattuple--unpackaged--1.0.sql
+DATA = pgstattuple--1.5.sql pgstattuple--1.4--1.5.sql \
+ pgstattuple--1.3--1.4.sql pgstattuple--1.2--1.3.sql \
+ pgstattuple--1.1--1.2.sql pgstattuple--1.0--1.1.sql \
+ pgstattuple--unpackaged--1.0.sql
PGFILEDESC = "pgstattuple - tuple-level statistics"
REGRESS = pgstattuple
diff --git a/contrib/pgstattuple/pgstatapprox.c b/contrib/pgstattuple/pgstatapprox.c
index a49ff54..11bae14 100644
--- a/contrib/pgstattuple/pgstatapprox.c
+++ b/contrib/pgstattuple/pgstatapprox.c
@@ -29,6 +29,9 @@
#include "commands/vacuum.h"
PG_FUNCTION_INFO_V1(pgstattuple_approx);
+PG_FUNCTION_INFO_V1(pgstattuple_approx_v1_5);
+
+Datum pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo);
typedef struct output_type
{
@@ -209,6 +212,33 @@ Datum
pgstattuple_approx(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
+
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ (errmsg("must be superuser to use pgstattuple functions"))));
+
+ PG_RETURN_DATUM(pgstattuple_approx_internal(relid, fcinfo));
+}
+
+/*
+ * As of pgstattuple version 1.5, we no longer need to check if the user
+ * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
+ * Users can then grant access to it based on their policies.
+ *
+ * Otherwise identical to pgstattuple_approx (above).
+ */
+Datum
+pgstattuple_approx_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+
+ PG_RETURN_DATUM(pgstattuple_approx_internal(relid, fcinfo));
+}
+
+Datum
+pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
+{
Relation rel;
output_type stat = {0};
TupleDesc tupdesc;
@@ -217,11 +247,6 @@ pgstattuple_approx(PG_FUNCTION_ARGS)
HeapTuple ret;
int i = 0;
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- (errmsg("must be superuser to use pgstattuple functions"))));
-
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index 6084589..753e52d 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -54,6 +54,14 @@ PG_FUNCTION_INFO_V1(pg_relpages);
PG_FUNCTION_INFO_V1(pg_relpagesbyid);
PG_FUNCTION_INFO_V1(pgstatginindex);
+PG_FUNCTION_INFO_V1(pgstatindex_v1_5);
+PG_FUNCTION_INFO_V1(pgstatindexbyid_v1_5);
+PG_FUNCTION_INFO_V1(pg_relpages_v1_5);
+PG_FUNCTION_INFO_V1(pg_relpagesbyid_v1_5);
+PG_FUNCTION_INFO_V1(pgstatginindex_v1_5);
+
+Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo);
+
#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
#define IS_GIN(r) ((r)->rd_rel->relam == GIN_AM_OID)
@@ -119,6 +127,26 @@ pgstatindex(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
}
+/*
+ * As of pgstattuple version 1.5, we no longer need to check if the user
+ * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
+ * Users can then grant access to it based on their policies.
+ *
+ * Otherwise identical to pgstatindex (above).
+ */
+Datum
+pgstatindex_v1_5(PG_FUNCTION_ARGS)
+{
+ text *relname = PG_GETARG_TEXT_P(0);
+ Relation rel;
+ RangeVar *relrv;
+
+ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
+ rel = relation_openrv(relrv, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
+}
+
Datum
pgstatindexbyid(PG_FUNCTION_ARGS)
{
@@ -135,6 +163,18 @@ pgstatindexbyid(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
}
+/* Remove superuser checks in v1.5, see above */
+Datum
+pgstatindexbyid_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+ Relation rel;
+
+ rel = relation_open(relid, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
+}
+
static Datum
pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
{
@@ -319,6 +359,27 @@ pg_relpages(PG_FUNCTION_ARGS)
PG_RETURN_INT64(relpages);
}
+/* Remove superuser checks in v1.5, see above */
+Datum
+pg_relpages_v1_5(PG_FUNCTION_ARGS)
+{
+ text *relname = PG_GETARG_TEXT_P(0);
+ int64 relpages;
+ Relation rel;
+ RangeVar *relrv;
+
+ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
+ rel = relation_openrv(relrv, AccessShareLock);
+
+ /* note: this will work OK on non-local temp tables */
+
+ relpages = RelationGetNumberOfBlocks(rel);
+
+ relation_close(rel, AccessShareLock);
+
+ PG_RETURN_INT64(relpages);
+}
+
Datum
pg_relpagesbyid(PG_FUNCTION_ARGS)
{
@@ -342,6 +403,25 @@ pg_relpagesbyid(PG_FUNCTION_ARGS)
PG_RETURN_INT64(relpages);
}
+/* Remove superuser checks in v1.5, see above */
+Datum
+pg_relpagesbyid_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+ int64 relpages;
+ Relation rel;
+
+ rel = relation_open(relid, AccessShareLock);
+
+ /* note: this will work OK on non-local temp tables */
+
+ relpages = RelationGetNumberOfBlocks(rel);
+
+ relation_close(rel, AccessShareLock);
+
+ PG_RETURN_INT64(relpages);
+}
+
/* ------------------------------------------------------
* pgstatginindex()
*
@@ -352,6 +432,27 @@ Datum
pgstatginindex(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
+
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ (errmsg("must be superuser to use pgstattuple functions"))));
+
+ PG_RETURN_DATUM(pgstatginindex_internal(relid, fcinfo));
+}
+
+/* Remove superuser checks in v1.5, see above */
+Datum
+pgstatginindex_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+
+ PG_RETURN_DATUM(pgstatginindex_internal(relid, fcinfo));
+}
+
+Datum
+pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
+{
Relation rel;
Buffer buffer;
Page page;
@@ -363,11 +464,6 @@ pgstatginindex(PG_FUNCTION_ARGS)
bool nulls[3] = {false, false, false};
Datum result;
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- (errmsg("must be superuser to use pgstattuple functions"))));
-
rel = relation_open(relid, AccessShareLock);
if (!IS_INDEX(rel) || !IS_GIN(rel))
@@ -415,5 +511,5 @@ pgstatginindex(PG_FUNCTION_ARGS)
tuple = heap_form_tuple(tupleDesc, values, nulls);
result = HeapTupleGetDatum(tuple);
- PG_RETURN_DATUM(result);
+ return (result);
}
diff --git a/contrib/pgstattuple/pgstattuple--1.4--1.5.sql b/contrib/pgstattuple/pgstattuple--1.4--1.5.sql
new file mode 100644
index 0000000..65d7f19
--- /dev/null
+++ b/contrib/pgstattuple/pgstattuple--1.4--1.5.sql
@@ -0,0 +1,111 @@
+/* contrib/pgstattuple/pgstattuple--1.4--1.5.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION pgstattuple UPDATE TO '1.5'" to load this file. \quit
+
+CREATE OR REPLACE FUNCTION pgstattuple(IN relname text,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT tuple_count BIGINT, -- number of live tuples
+ OUT tuple_len BIGINT, -- total tuples length in bytes
+ OUT tuple_percent FLOAT8, -- live tuples in %
+ OUT dead_tuple_count BIGINT, -- number of dead tuples
+ OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in %
+ OUT free_space BIGINT, -- free space in bytes
+ OUT free_percent FLOAT8) -- free space in %
+AS 'MODULE_PATHNAME', 'pgstattuple_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple(text) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pgstatindex(IN relname text,
+ OUT version INT,
+ OUT tree_level INT,
+ OUT index_size BIGINT,
+ OUT root_block_no BIGINT,
+ OUT internal_pages BIGINT,
+ OUT leaf_pages BIGINT,
+ OUT empty_pages BIGINT,
+ OUT deleted_pages BIGINT,
+ OUT avg_leaf_density FLOAT8,
+ OUT leaf_fragmentation FLOAT8)
+AS 'MODULE_PATHNAME', 'pgstatindex_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatindex(text) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pg_relpages(IN relname text)
+RETURNS BIGINT
+AS 'MODULE_PATHNAME', 'pg_relpages_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pg_relpages(text) FROM PUBLIC;
+
+/* New stuff in 1.1 begins here */
+
+CREATE OR REPLACE FUNCTION pgstatginindex(IN relname regclass,
+ OUT version INT4,
+ OUT pending_pages INT4,
+ OUT pending_tuples BIGINT)
+AS 'MODULE_PATHNAME', 'pgstatginindex_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatginindex(regclass) FROM PUBLIC;
+
+/* New stuff in 1.2 begins here */
+
+CREATE OR REPLACE FUNCTION pgstattuple(IN reloid regclass,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT tuple_count BIGINT, -- number of live tuples
+ OUT tuple_len BIGINT, -- total tuples length in bytes
+ OUT tuple_percent FLOAT8, -- live tuples in %
+ OUT dead_tuple_count BIGINT, -- number of dead tuples
+ OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in %
+ OUT free_space BIGINT, -- free space in bytes
+ OUT free_percent FLOAT8) -- free space in %
+AS 'MODULE_PATHNAME', 'pgstattuplebyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple(regclass) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pgstatindex(IN relname regclass,
+ OUT version INT,
+ OUT tree_level INT,
+ OUT index_size BIGINT,
+ OUT root_block_no BIGINT,
+ OUT internal_pages BIGINT,
+ OUT leaf_pages BIGINT,
+ OUT empty_pages BIGINT,
+ OUT deleted_pages BIGINT,
+ OUT avg_leaf_density FLOAT8,
+ OUT leaf_fragmentation FLOAT8)
+AS 'MODULE_PATHNAME', 'pgstatindexbyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatindex(regclass) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pg_relpages(IN relname regclass)
+RETURNS BIGINT
+AS 'MODULE_PATHNAME', 'pg_relpagesbyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pg_relpages(regclass) FROM PUBLIC;
+
+/* New stuff in 1.3 begins here */
+
+CREATE OR REPLACE FUNCTION pgstattuple_approx(IN reloid regclass,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT scanned_percent FLOAT8, -- what percentage of the table's pages was scanned
+ OUT approx_tuple_count BIGINT, -- estimated number of live tuples
+ OUT approx_tuple_len BIGINT, -- estimated total length in bytes of live tuples
+ OUT approx_tuple_percent FLOAT8, -- live tuples in % (based on estimate)
+ OUT dead_tuple_count BIGINT, -- exact number of dead tuples
+ OUT dead_tuple_len BIGINT, -- exact total length in bytes of dead tuples
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in % (based on estimate)
+ OUT approx_free_space BIGINT, -- estimated free space in bytes
+ OUT approx_free_percent FLOAT8) -- free space in % (based on estimate)
+AS 'MODULE_PATHNAME', 'pgstattuple_approx_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple_approx(regclass) FROM PUBLIC;
diff --git a/contrib/pgstattuple/pgstattuple--1.4.sql b/contrib/pgstattuple/pgstattuple--1.4.sql
deleted file mode 100644
index 47377eb..0000000
--- a/contrib/pgstattuple/pgstattuple--1.4.sql
+++ /dev/null
@@ -1,95 +0,0 @@
-/* contrib/pgstattuple/pgstattuple--1.4.sql */
-
--- complain if script is sourced in psql, rather than via CREATE EXTENSION
-\echo Use "CREATE EXTENSION pgstattuple" to load this file. \quit
-
-CREATE FUNCTION pgstattuple(IN relname text,
- OUT table_len BIGINT, -- physical table length in bytes
- OUT tuple_count BIGINT, -- number of live tuples
- OUT tuple_len BIGINT, -- total tuples length in bytes
- OUT tuple_percent FLOAT8, -- live tuples in %
- OUT dead_tuple_count BIGINT, -- number of dead tuples
- OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
- OUT dead_tuple_percent FLOAT8, -- dead tuples in %
- OUT free_space BIGINT, -- free space in bytes
- OUT free_percent FLOAT8) -- free space in %
-AS 'MODULE_PATHNAME', 'pgstattuple'
-LANGUAGE C STRICT PARALLEL SAFE;
-
-CREATE FUNCTION pgstatindex(IN relname text,
- OUT version INT,
- OUT tree_level INT,
- OUT index_size BIGINT,
- OUT root_block_no BIGINT,
- OUT internal_pages BIGINT,
- OUT leaf_pages BIGINT,
- OUT empty_pages BIGINT,
- OUT deleted_pages BIGINT,
- OUT avg_leaf_density FLOAT8,
- OUT leaf_fragmentation FLOAT8)
-AS 'MODULE_PATHNAME', 'pgstatindex'
-LANGUAGE C STRICT PARALLEL SAFE;
-
-CREATE FUNCTION pg_relpages(IN relname text)
-RETURNS BIGINT
-AS 'MODULE_PATHNAME', 'pg_relpages'
-LANGUAGE C STRICT PARALLEL SAFE;
-
-/* New stuff in 1.1 begins here */
-
-CREATE FUNCTION pgstatginindex(IN relname regclass,
- OUT version INT4,
- OUT pending_pages INT4,
- OUT pending_tuples BIGINT)
-AS 'MODULE_PATHNAME', 'pgstatginindex'
-LANGUAGE C STRICT PARALLEL SAFE;
-
-/* New stuff in 1.2 begins here */
-
-CREATE FUNCTION pgstattuple(IN reloid regclass,
- OUT table_len BIGINT, -- physical table length in bytes
- OUT tuple_count BIGINT, -- number of live tuples
- OUT tuple_len BIGINT, -- total tuples length in bytes
- OUT tuple_percent FLOAT8, -- live tuples in %
- OUT dead_tuple_count BIGINT, -- number of dead tuples
- OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
- OUT dead_tuple_percent FLOAT8, -- dead tuples in %
- OUT free_space BIGINT, -- free space in bytes
- OUT free_percent FLOAT8) -- free space in %
-AS 'MODULE_PATHNAME', 'pgstattuplebyid'
-LANGUAGE C STRICT PARALLEL SAFE;
-
-CREATE FUNCTION pgstatindex(IN relname regclass,
- OUT version INT,
- OUT tree_level INT,
- OUT index_size BIGINT,
- OUT root_block_no BIGINT,
- OUT internal_pages BIGINT,
- OUT leaf_pages BIGINT,
- OUT empty_pages BIGINT,
- OUT deleted_pages BIGINT,
- OUT avg_leaf_density FLOAT8,
- OUT leaf_fragmentation FLOAT8)
-AS 'MODULE_PATHNAME', 'pgstatindexbyid'
-LANGUAGE C STRICT PARALLEL SAFE;
-
-CREATE FUNCTION pg_relpages(IN relname regclass)
-RETURNS BIGINT
-AS 'MODULE_PATHNAME', 'pg_relpagesbyid'
-LANGUAGE C STRICT PARALLEL SAFE;
-
-/* New stuff in 1.3 begins here */
-
-CREATE FUNCTION pgstattuple_approx(IN reloid regclass,
- OUT table_len BIGINT, -- physical table length in bytes
- OUT scanned_percent FLOAT8, -- what percentage of the table's pages was scanned
- OUT approx_tuple_count BIGINT, -- estimated number of live tuples
- OUT approx_tuple_len BIGINT, -- estimated total length in bytes of live tuples
- OUT approx_tuple_percent FLOAT8, -- live tuples in % (based on estimate)
- OUT dead_tuple_count BIGINT, -- exact number of dead tuples
- OUT dead_tuple_len BIGINT, -- exact total length in bytes of dead tuples
- OUT dead_tuple_percent FLOAT8, -- dead tuples in % (based on estimate)
- OUT approx_free_space BIGINT, -- estimated free space in bytes
- OUT approx_free_percent FLOAT8) -- free space in % (based on estimate)
-AS 'MODULE_PATHNAME', 'pgstattuple_approx'
-LANGUAGE C STRICT PARALLEL SAFE;
diff --git a/contrib/pgstattuple/pgstattuple--1.5.sql b/contrib/pgstattuple/pgstattuple--1.5.sql
new file mode 100644
index 0000000..04d23ef
--- /dev/null
+++ b/contrib/pgstattuple/pgstattuple--1.5.sql
@@ -0,0 +1,111 @@
+/* contrib/pgstattuple/pgstattuple--1.5.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION pgstattuple" to load this file. \quit
+
+CREATE FUNCTION pgstattuple(IN relname text,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT tuple_count BIGINT, -- number of live tuples
+ OUT tuple_len BIGINT, -- total tuples length in bytes
+ OUT tuple_percent FLOAT8, -- live tuples in %
+ OUT dead_tuple_count BIGINT, -- number of dead tuples
+ OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in %
+ OUT free_space BIGINT, -- free space in bytes
+ OUT free_percent FLOAT8) -- free space in %
+AS 'MODULE_PATHNAME', 'pgstattuple_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple(text) FROM PUBLIC;
+
+CREATE FUNCTION pgstatindex(IN relname text,
+ OUT version INT,
+ OUT tree_level INT,
+ OUT index_size BIGINT,
+ OUT root_block_no BIGINT,
+ OUT internal_pages BIGINT,
+ OUT leaf_pages BIGINT,
+ OUT empty_pages BIGINT,
+ OUT deleted_pages BIGINT,
+ OUT avg_leaf_density FLOAT8,
+ OUT leaf_fragmentation FLOAT8)
+AS 'MODULE_PATHNAME', 'pgstatindex_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatindex(text) FROM PUBLIC;
+
+CREATE FUNCTION pg_relpages(IN relname text)
+RETURNS BIGINT
+AS 'MODULE_PATHNAME', 'pg_relpages_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pg_relpages(text) FROM PUBLIC;
+
+/* New stuff in 1.1 begins here */
+
+CREATE FUNCTION pgstatginindex(IN relname regclass,
+ OUT version INT4,
+ OUT pending_pages INT4,
+ OUT pending_tuples BIGINT)
+AS 'MODULE_PATHNAME', 'pgstatginindex_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatginindex(regclass) FROM PUBLIC;
+
+/* New stuff in 1.2 begins here */
+
+CREATE FUNCTION pgstattuple(IN reloid regclass,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT tuple_count BIGINT, -- number of live tuples
+ OUT tuple_len BIGINT, -- total tuples length in bytes
+ OUT tuple_percent FLOAT8, -- live tuples in %
+ OUT dead_tuple_count BIGINT, -- number of dead tuples
+ OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in %
+ OUT free_space BIGINT, -- free space in bytes
+ OUT free_percent FLOAT8) -- free space in %
+AS 'MODULE_PATHNAME', 'pgstattuplebyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple(regclass) FROM PUBLIC;
+
+CREATE FUNCTION pgstatindex(IN relname regclass,
+ OUT version INT,
+ OUT tree_level INT,
+ OUT index_size BIGINT,
+ OUT root_block_no BIGINT,
+ OUT internal_pages BIGINT,
+ OUT leaf_pages BIGINT,
+ OUT empty_pages BIGINT,
+ OUT deleted_pages BIGINT,
+ OUT avg_leaf_density FLOAT8,
+ OUT leaf_fragmentation FLOAT8)
+AS 'MODULE_PATHNAME', 'pgstatindexbyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatindex(regclass) FROM PUBLIC;
+
+CREATE FUNCTION pg_relpages(IN relname regclass)
+RETURNS BIGINT
+AS 'MODULE_PATHNAME', 'pg_relpagesbyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pg_relpages(regclass) FROM PUBLIC;
+
+/* New stuff in 1.3 begins here */
+
+CREATE FUNCTION pgstattuple_approx(IN reloid regclass,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT scanned_percent FLOAT8, -- what percentage of the table's pages was scanned
+ OUT approx_tuple_count BIGINT, -- estimated number of live tuples
+ OUT approx_tuple_len BIGINT, -- estimated total length in bytes of live tuples
+ OUT approx_tuple_percent FLOAT8, -- live tuples in % (based on estimate)
+ OUT dead_tuple_count BIGINT, -- exact number of dead tuples
+ OUT dead_tuple_len BIGINT, -- exact total length in bytes of dead tuples
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in % (based on estimate)
+ OUT approx_free_space BIGINT, -- estimated free space in bytes
+ OUT approx_free_percent FLOAT8) -- free space in % (based on estimate)
+AS 'MODULE_PATHNAME', 'pgstattuple_approx_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple_approx(regclass) FROM PUBLIC;
diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c
index c1122b4..1d25567 100644
--- a/contrib/pgstattuple/pgstattuple.c
+++ b/contrib/pgstattuple/pgstattuple.c
@@ -40,7 +40,9 @@
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(pgstattuple);
+PG_FUNCTION_INFO_V1(pgstattuple_v1_5);
PG_FUNCTION_INFO_V1(pgstattuplebyid);
+PG_FUNCTION_INFO_V1(pgstattuplebyid_v1_5);
/*
* struct pgstattuple_type
@@ -174,6 +176,27 @@ pgstattuple(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
}
+/*
+ * As of pgstattuple version 1.5, we no longer need to check if the user
+ * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
+ * Users can then grant access to it based on their policies.
+ *
+ * Otherwise identical to pgstattuple (above).
+ */
+Datum
+pgstattuple_v1_5(PG_FUNCTION_ARGS)
+{
+ text *relname = PG_GETARG_TEXT_P(0);
+ RangeVar *relrv;
+ Relation rel;
+
+ /* open relation */
+ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
+ rel = relation_openrv(relrv, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
+}
+
Datum
pgstattuplebyid(PG_FUNCTION_ARGS)
{
@@ -191,6 +214,19 @@ pgstattuplebyid(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
}
+/* Remove superuser() check for 1.5 version, see above */
+Datum
+pgstattuplebyid_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+ Relation rel;
+
+ /* open relation */
+ rel = relation_open(relid, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
+}
+
/*
* pgstat_relation
*/
diff --git a/contrib/pgstattuple/pgstattuple.control b/contrib/pgstattuple/pgstattuple.control
index fa328fd..6af4075 100644
--- a/contrib/pgstattuple/pgstattuple.control
+++ b/contrib/pgstattuple/pgstattuple.control
@@ -1,5 +1,5 @@
# pgstattuple extension
comment = 'show tuple-level statistics'
-default_version = '1.4'
+default_version = '1.5'
module_pathname = '$libdir/pgstattuple'
relocatable = true
--
2.7.4
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
@ 2016-09-01 17:12 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
0 siblings, 1 reply; 14+ messages in thread
From: Peter Eisentraut @ 2016-09-01 17:12 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; pgsql-hackers
On 8/23/16 5:22 PM, Stephen Frost wrote:
> Now that we track initial privileges on extension objects and changes to
> those permissions, we can drop the superuser() checks from the various
> functions which are part of the pgstattuple extension.
>
> Since a pg_upgrade will preserve the version of the extension which
> existed prior to the upgrade, we can't simply modify the existing
> functions but instead need to create new functions which remove the
> checks and update the SQL-level functions to use the new functions
I think this is a good change to pursue, and we'll likely want to do
more similar changes in contrib. But I'm worried that what is logically
a 10-line change will end up a 20 KiB patch every time.
Have we explored other options for addressing the upgrade problems?
Maybe the function could check that non-default privileges have been
granted?
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2016-09-04 15:41 ` Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 14+ messages in thread
From: Stephen Frost @ 2016-09-04 15:41 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: pgsql-hackers
* Peter Eisentraut (peter.eisentraut@2ndquadrant.com) wrote:
> On 8/23/16 5:22 PM, Stephen Frost wrote:
> > Now that we track initial privileges on extension objects and changes to
> > those permissions, we can drop the superuser() checks from the various
> > functions which are part of the pgstattuple extension.
> >
> > Since a pg_upgrade will preserve the version of the extension which
> > existed prior to the upgrade, we can't simply modify the existing
> > functions but instead need to create new functions which remove the
> > checks and update the SQL-level functions to use the new functions
>
> I think this is a good change to pursue, and we'll likely want to do
> more similar changes in contrib. But I'm worried that what is logically
> a 10-line change will end up a 20 KiB patch every time.
This is primairly due to how we handle new versions of an extension.
Any change to an extension is going to involve a new upgrade script and
the removal of the prior version install script and addition of the new
version install scripts.
> Have we explored other options for addressing the upgrade problems?
We did discuss the upgrade issue and Noah proposed the current approach,
which appears to be the best option.
> Maybe the function could check that non-default privileges have been
> granted?
Simply changing the function to behave differently depending on what
privileges have or havn't been granted doesn't seem like a very good
idea.
Consider an existing installation where the admin tried to grant access
to one of these functions:
GRANT EXECUTE ON pgstattuple_func() TO bob;
This would result in a GRANT to bob explicitly, and the GRANT to public
would still be there also.
Then an upgrade of PG, without upgrading the extension, would lead to
any user being able to execute the function. An upgrade of the
extension would revoke the GRANT to PUBLIC and, further, would
hopefuflly cause the admin to consider checking the documentation about
the upgrade (which needs to be added; I'll do that).
We also created a new version to add the PARALLEL SAFE markings to the
functions. In general, I believe it's better to use a new version when
we're making these kinds of changes.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
@ 2016-09-04 15:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-04 23:36 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-05 00:59 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
0 siblings, 2 replies; 14+ messages in thread
From: Tom Lane @ 2016-09-04 15:55 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers
[ warning, thread hijack ahead ]
Stephen Frost <sfrost@snowman.net> writes:
> * Peter Eisentraut (peter.eisentraut@2ndquadrant.com) wrote:
>> I think this is a good change to pursue, and we'll likely want to do
>> more similar changes in contrib. But I'm worried that what is logically
>> a 10-line change will end up a 20 KiB patch every time.
> We also created a new version to add the PARALLEL SAFE markings to the
> functions. In general, I believe it's better to use a new version when
> we're making these kinds of changes.
It is becoming clear that the current extension update mechanism is kind
of brute-force for this sort of change. I have no ideas offhand about a
better way to do it, but like Peter, I was dismayed by the amount of pure
overhead involved in the PARALLEL SAFE updates.
It's not only development overhead, either: users have to remember to
run around and issue ALTER EXTENSION UPDATE for every extension they
have, in every database they have it installed in. Anyone want to
lay a side bet on how many users will actually do that? Given that
the release notes don't currently suggest doing so, I'd be willing
to put money on "none at all" :-(
I wonder whether pg_upgrade ought to be changed to attempt upgrading
every extension after it's completed the basic migration. Or at
least offer a script containing all the needed commands.
Anyway, it's not this particular patch's job to do better, but we
oughta think about better ways to do it.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-04 23:36 ` Stephen Frost <sfrost@snowman.net>
2016-09-08 16:28 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
1 sibling, 1 reply; 14+ messages in thread
From: Stephen Frost @ 2016-09-04 23:36 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers
Tom,
* Tom Lane (tgl@sss.pgh.pa.us) wrote:
> [ warning, thread hijack ahead ]
quite.
> Stephen Frost <sfrost@snowman.net> writes:
> > * Peter Eisentraut (peter.eisentraut@2ndquadrant.com) wrote:
> >> I think this is a good change to pursue, and we'll likely want to do
> >> more similar changes in contrib. But I'm worried that what is logically
> >> a 10-line change will end up a 20 KiB patch every time.
>
> > We also created a new version to add the PARALLEL SAFE markings to the
> > functions. In general, I believe it's better to use a new version when
> > we're making these kinds of changes.
>
> It is becoming clear that the current extension update mechanism is kind
> of brute-force for this sort of change. I have no ideas offhand about a
> better way to do it, but like Peter, I was dismayed by the amount of pure
> overhead involved in the PARALLEL SAFE updates.
To make the patches smaller, it seems that we'd need a way to avoid the
removal and re-addition of the entire install script and a way to avoid
having to add a new upgrade script.
Perhaps if the versioned install script was actually a non-versioned
install script in the source tree, and the Makefile simply installed it
into the correct place, then we could eliminate that part. (All very
hand-wavy, I've not looked at what it'd take to do.)
I don't have any great answers for the upgrade script off-hand. We
could come up with a way for one file to handle multiple upgrade
options, but that doesn't really make the patch any smaller.
> It's not only development overhead, either: users have to remember to
> run around and issue ALTER EXTENSION UPDATE for every extension they
> have, in every database they have it installed in. Anyone want to
> lay a side bet on how many users will actually do that? Given that
> the release notes don't currently suggest doing so, I'd be willing
> to put money on "none at all" :-(
I agree, that's also an issue.
> I wonder whether pg_upgrade ought to be changed to attempt upgrading
> every extension after it's completed the basic migration. Or at
> least offer a script containing all the needed commands.
I like the idea of having an option and documentation to go along with
it. Hopefully that will help administrators at least realize that it's
something they'll want to look at doing.
> Anyway, it's not this particular patch's job to do better, but we
> oughta think about better ways to do it.
Agreed.
Thanks!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-04 23:36 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
@ 2016-09-08 16:28 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-26 19:43 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
0 siblings, 1 reply; 14+ messages in thread
From: Peter Eisentraut @ 2016-09-08 16:28 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers
On 9/4/16 7:36 PM, Stephen Frost wrote:
> Perhaps if the versioned install script was actually a non-versioned
> install script in the source tree, and the Makefile simply installed it
> into the correct place, then we could eliminate that part. (All very
> hand-wavy, I've not looked at what it'd take to do.)
A number of external extensions actually do it that way, but it also has
its problems. For example, if you don't preserve the old base install
scripts, you can't actually test whether your upgrade scripts work in
the sense that they upgrade you to the same place.
This is now being obsoleted by the later idea of allowing base installs
from a chain of upgrade scripts. But if your upgrade scripts contain
ALTER TABLE commands, you will probably still want to write base install
scripts that do a fresh CREATE TABLE instead.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-04 23:36 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-08 16:28 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
@ 2016-09-26 19:43 ` Stephen Frost <sfrost@snowman.net>
2016-09-27 06:27 ` Re: Remove superuser() checks from pgstattuple Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Stephen Frost @ 2016-09-26 19:43 UTC (permalink / raw)
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers
Peter, all,
* Peter Eisentraut (peter.eisentraut@2ndquadrant.com) wrote:
> This is now being obsoleted by the later idea of allowing base installs
> from a chain of upgrade scripts. But if your upgrade scripts contain
> ALTER TABLE commands, you will probably still want to write base install
> scripts that do a fresh CREATE TABLE instead.
I've updated the patch to remove the new base version script and to rely
on the changes made by Tom to install the 1.4 version and then upgrade
to 1.5.
Based on my testing, it appears to all work correctly.
Updated (much smaller) patch attached.
Thanks!
Stephen
Attachments:
pgstattuple-remove-superuser-checks_v4.patch (text/x-diff, 14.5K) download
From 508a4db0111607d8d59eef4a8e172f8a7aa8fdfa Mon Sep 17 00:00:00 2001
From: Stephen Frost <sfrost@snowman.net>
Date: Tue, 23 Aug 2016 17:13:09 -0400
Subject: [PATCH] Remove superuser checks in pgstattuple
Now that we track initial privileges on extension objects and changes to
those permissions, we can drop the superuser() checks from the various
functions which are part of the pgstattuple extension.
Since a pg_upgrade will preserve the version of the extension which
existed prior to the upgrade, we can't simply modify the existing
functions but instead need to create new functions which remove the
checks and update the SQL-level functions to use the new functions
(and to REVOKE EXECUTE rights on those functions from PUBLIC).
Approach suggested by Noah.
---
contrib/pgstattuple/Makefile | 7 +-
contrib/pgstattuple/pgstatapprox.c | 35 ++++++--
contrib/pgstattuple/pgstatindex.c | 108 +++++++++++++++++++++++--
contrib/pgstattuple/pgstattuple--1.4--1.5.sql | 111 ++++++++++++++++++++++++++
contrib/pgstattuple/pgstattuple.c | 36 +++++++++
contrib/pgstattuple/pgstattuple.control | 2 +-
6 files changed, 284 insertions(+), 15 deletions(-)
create mode 100644 contrib/pgstattuple/pgstattuple--1.4--1.5.sql
diff --git a/contrib/pgstattuple/Makefile b/contrib/pgstattuple/Makefile
index e732680..294077d 100644
--- a/contrib/pgstattuple/Makefile
+++ b/contrib/pgstattuple/Makefile
@@ -4,9 +4,10 @@ MODULE_big = pgstattuple
OBJS = pgstattuple.o pgstatindex.o pgstatapprox.o $(WIN32RES)
EXTENSION = pgstattuple
-DATA = pgstattuple--1.4.sql pgstattuple--1.3--1.4.sql \
- pgstattuple--1.2--1.3.sql pgstattuple--1.1--1.2.sql \
- pgstattuple--1.0--1.1.sql pgstattuple--unpackaged--1.0.sql
+DATA = pgstattuple--1.4.sql pgstattuple--1.4--1.5.sql \
+ pgstattuple--1.3--1.4.sql pgstattuple--1.2--1.3.sql \
+ pgstattuple--1.1--1.2.sql pgstattuple--1.0--1.1.sql \
+ pgstattuple--unpackaged--1.0.sql
PGFILEDESC = "pgstattuple - tuple-level statistics"
REGRESS = pgstattuple
diff --git a/contrib/pgstattuple/pgstatapprox.c b/contrib/pgstattuple/pgstatapprox.c
index a49ff54..11bae14 100644
--- a/contrib/pgstattuple/pgstatapprox.c
+++ b/contrib/pgstattuple/pgstatapprox.c
@@ -29,6 +29,9 @@
#include "commands/vacuum.h"
PG_FUNCTION_INFO_V1(pgstattuple_approx);
+PG_FUNCTION_INFO_V1(pgstattuple_approx_v1_5);
+
+Datum pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo);
typedef struct output_type
{
@@ -209,6 +212,33 @@ Datum
pgstattuple_approx(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
+
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ (errmsg("must be superuser to use pgstattuple functions"))));
+
+ PG_RETURN_DATUM(pgstattuple_approx_internal(relid, fcinfo));
+}
+
+/*
+ * As of pgstattuple version 1.5, we no longer need to check if the user
+ * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
+ * Users can then grant access to it based on their policies.
+ *
+ * Otherwise identical to pgstattuple_approx (above).
+ */
+Datum
+pgstattuple_approx_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+
+ PG_RETURN_DATUM(pgstattuple_approx_internal(relid, fcinfo));
+}
+
+Datum
+pgstattuple_approx_internal(Oid relid, FunctionCallInfo fcinfo)
+{
Relation rel;
output_type stat = {0};
TupleDesc tupdesc;
@@ -217,11 +247,6 @@ pgstattuple_approx(PG_FUNCTION_ARGS)
HeapTuple ret;
int i = 0;
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- (errmsg("must be superuser to use pgstattuple functions"))));
-
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index 6084589..753e52d 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -54,6 +54,14 @@ PG_FUNCTION_INFO_V1(pg_relpages);
PG_FUNCTION_INFO_V1(pg_relpagesbyid);
PG_FUNCTION_INFO_V1(pgstatginindex);
+PG_FUNCTION_INFO_V1(pgstatindex_v1_5);
+PG_FUNCTION_INFO_V1(pgstatindexbyid_v1_5);
+PG_FUNCTION_INFO_V1(pg_relpages_v1_5);
+PG_FUNCTION_INFO_V1(pg_relpagesbyid_v1_5);
+PG_FUNCTION_INFO_V1(pgstatginindex_v1_5);
+
+Datum pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo);
+
#define IS_INDEX(r) ((r)->rd_rel->relkind == RELKIND_INDEX)
#define IS_BTREE(r) ((r)->rd_rel->relam == BTREE_AM_OID)
#define IS_GIN(r) ((r)->rd_rel->relam == GIN_AM_OID)
@@ -119,6 +127,26 @@ pgstatindex(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
}
+/*
+ * As of pgstattuple version 1.5, we no longer need to check if the user
+ * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
+ * Users can then grant access to it based on their policies.
+ *
+ * Otherwise identical to pgstatindex (above).
+ */
+Datum
+pgstatindex_v1_5(PG_FUNCTION_ARGS)
+{
+ text *relname = PG_GETARG_TEXT_P(0);
+ Relation rel;
+ RangeVar *relrv;
+
+ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
+ rel = relation_openrv(relrv, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
+}
+
Datum
pgstatindexbyid(PG_FUNCTION_ARGS)
{
@@ -135,6 +163,18 @@ pgstatindexbyid(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
}
+/* Remove superuser checks in v1.5, see above */
+Datum
+pgstatindexbyid_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+ Relation rel;
+
+ rel = relation_open(relid, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstatindex_impl(rel, fcinfo));
+}
+
static Datum
pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
{
@@ -319,6 +359,27 @@ pg_relpages(PG_FUNCTION_ARGS)
PG_RETURN_INT64(relpages);
}
+/* Remove superuser checks in v1.5, see above */
+Datum
+pg_relpages_v1_5(PG_FUNCTION_ARGS)
+{
+ text *relname = PG_GETARG_TEXT_P(0);
+ int64 relpages;
+ Relation rel;
+ RangeVar *relrv;
+
+ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
+ rel = relation_openrv(relrv, AccessShareLock);
+
+ /* note: this will work OK on non-local temp tables */
+
+ relpages = RelationGetNumberOfBlocks(rel);
+
+ relation_close(rel, AccessShareLock);
+
+ PG_RETURN_INT64(relpages);
+}
+
Datum
pg_relpagesbyid(PG_FUNCTION_ARGS)
{
@@ -342,6 +403,25 @@ pg_relpagesbyid(PG_FUNCTION_ARGS)
PG_RETURN_INT64(relpages);
}
+/* Remove superuser checks in v1.5, see above */
+Datum
+pg_relpagesbyid_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+ int64 relpages;
+ Relation rel;
+
+ rel = relation_open(relid, AccessShareLock);
+
+ /* note: this will work OK on non-local temp tables */
+
+ relpages = RelationGetNumberOfBlocks(rel);
+
+ relation_close(rel, AccessShareLock);
+
+ PG_RETURN_INT64(relpages);
+}
+
/* ------------------------------------------------------
* pgstatginindex()
*
@@ -352,6 +432,27 @@ Datum
pgstatginindex(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
+
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ (errmsg("must be superuser to use pgstattuple functions"))));
+
+ PG_RETURN_DATUM(pgstatginindex_internal(relid, fcinfo));
+}
+
+/* Remove superuser checks in v1.5, see above */
+Datum
+pgstatginindex_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+
+ PG_RETURN_DATUM(pgstatginindex_internal(relid, fcinfo));
+}
+
+Datum
+pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
+{
Relation rel;
Buffer buffer;
Page page;
@@ -363,11 +464,6 @@ pgstatginindex(PG_FUNCTION_ARGS)
bool nulls[3] = {false, false, false};
Datum result;
- if (!superuser())
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- (errmsg("must be superuser to use pgstattuple functions"))));
-
rel = relation_open(relid, AccessShareLock);
if (!IS_INDEX(rel) || !IS_GIN(rel))
@@ -415,5 +511,5 @@ pgstatginindex(PG_FUNCTION_ARGS)
tuple = heap_form_tuple(tupleDesc, values, nulls);
result = HeapTupleGetDatum(tuple);
- PG_RETURN_DATUM(result);
+ return (result);
}
diff --git a/contrib/pgstattuple/pgstattuple--1.4--1.5.sql b/contrib/pgstattuple/pgstattuple--1.4--1.5.sql
new file mode 100644
index 0000000..65d7f19
--- /dev/null
+++ b/contrib/pgstattuple/pgstattuple--1.4--1.5.sql
@@ -0,0 +1,111 @@
+/* contrib/pgstattuple/pgstattuple--1.4--1.5.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION pgstattuple UPDATE TO '1.5'" to load this file. \quit
+
+CREATE OR REPLACE FUNCTION pgstattuple(IN relname text,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT tuple_count BIGINT, -- number of live tuples
+ OUT tuple_len BIGINT, -- total tuples length in bytes
+ OUT tuple_percent FLOAT8, -- live tuples in %
+ OUT dead_tuple_count BIGINT, -- number of dead tuples
+ OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in %
+ OUT free_space BIGINT, -- free space in bytes
+ OUT free_percent FLOAT8) -- free space in %
+AS 'MODULE_PATHNAME', 'pgstattuple_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple(text) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pgstatindex(IN relname text,
+ OUT version INT,
+ OUT tree_level INT,
+ OUT index_size BIGINT,
+ OUT root_block_no BIGINT,
+ OUT internal_pages BIGINT,
+ OUT leaf_pages BIGINT,
+ OUT empty_pages BIGINT,
+ OUT deleted_pages BIGINT,
+ OUT avg_leaf_density FLOAT8,
+ OUT leaf_fragmentation FLOAT8)
+AS 'MODULE_PATHNAME', 'pgstatindex_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatindex(text) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pg_relpages(IN relname text)
+RETURNS BIGINT
+AS 'MODULE_PATHNAME', 'pg_relpages_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pg_relpages(text) FROM PUBLIC;
+
+/* New stuff in 1.1 begins here */
+
+CREATE OR REPLACE FUNCTION pgstatginindex(IN relname regclass,
+ OUT version INT4,
+ OUT pending_pages INT4,
+ OUT pending_tuples BIGINT)
+AS 'MODULE_PATHNAME', 'pgstatginindex_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatginindex(regclass) FROM PUBLIC;
+
+/* New stuff in 1.2 begins here */
+
+CREATE OR REPLACE FUNCTION pgstattuple(IN reloid regclass,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT tuple_count BIGINT, -- number of live tuples
+ OUT tuple_len BIGINT, -- total tuples length in bytes
+ OUT tuple_percent FLOAT8, -- live tuples in %
+ OUT dead_tuple_count BIGINT, -- number of dead tuples
+ OUT dead_tuple_len BIGINT, -- total dead tuples length in bytes
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in %
+ OUT free_space BIGINT, -- free space in bytes
+ OUT free_percent FLOAT8) -- free space in %
+AS 'MODULE_PATHNAME', 'pgstattuplebyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple(regclass) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pgstatindex(IN relname regclass,
+ OUT version INT,
+ OUT tree_level INT,
+ OUT index_size BIGINT,
+ OUT root_block_no BIGINT,
+ OUT internal_pages BIGINT,
+ OUT leaf_pages BIGINT,
+ OUT empty_pages BIGINT,
+ OUT deleted_pages BIGINT,
+ OUT avg_leaf_density FLOAT8,
+ OUT leaf_fragmentation FLOAT8)
+AS 'MODULE_PATHNAME', 'pgstatindexbyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstatindex(regclass) FROM PUBLIC;
+
+CREATE OR REPLACE FUNCTION pg_relpages(IN relname regclass)
+RETURNS BIGINT
+AS 'MODULE_PATHNAME', 'pg_relpagesbyid_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pg_relpages(regclass) FROM PUBLIC;
+
+/* New stuff in 1.3 begins here */
+
+CREATE OR REPLACE FUNCTION pgstattuple_approx(IN reloid regclass,
+ OUT table_len BIGINT, -- physical table length in bytes
+ OUT scanned_percent FLOAT8, -- what percentage of the table's pages was scanned
+ OUT approx_tuple_count BIGINT, -- estimated number of live tuples
+ OUT approx_tuple_len BIGINT, -- estimated total length in bytes of live tuples
+ OUT approx_tuple_percent FLOAT8, -- live tuples in % (based on estimate)
+ OUT dead_tuple_count BIGINT, -- exact number of dead tuples
+ OUT dead_tuple_len BIGINT, -- exact total length in bytes of dead tuples
+ OUT dead_tuple_percent FLOAT8, -- dead tuples in % (based on estimate)
+ OUT approx_free_space BIGINT, -- estimated free space in bytes
+ OUT approx_free_percent FLOAT8) -- free space in % (based on estimate)
+AS 'MODULE_PATHNAME', 'pgstattuple_approx_v1_5'
+LANGUAGE C STRICT PARALLEL SAFE;
+
+REVOKE EXECUTE ON FUNCTION pgstattuple_approx(regclass) FROM PUBLIC;
diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c
index c1122b4..1d25567 100644
--- a/contrib/pgstattuple/pgstattuple.c
+++ b/contrib/pgstattuple/pgstattuple.c
@@ -40,7 +40,9 @@
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(pgstattuple);
+PG_FUNCTION_INFO_V1(pgstattuple_v1_5);
PG_FUNCTION_INFO_V1(pgstattuplebyid);
+PG_FUNCTION_INFO_V1(pgstattuplebyid_v1_5);
/*
* struct pgstattuple_type
@@ -174,6 +176,27 @@ pgstattuple(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
}
+/*
+ * As of pgstattuple version 1.5, we no longer need to check if the user
+ * is a superuser because we REVOKE EXECUTE on the function from PUBLIC.
+ * Users can then grant access to it based on their policies.
+ *
+ * Otherwise identical to pgstattuple (above).
+ */
+Datum
+pgstattuple_v1_5(PG_FUNCTION_ARGS)
+{
+ text *relname = PG_GETARG_TEXT_P(0);
+ RangeVar *relrv;
+ Relation rel;
+
+ /* open relation */
+ relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
+ rel = relation_openrv(relrv, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
+}
+
Datum
pgstattuplebyid(PG_FUNCTION_ARGS)
{
@@ -191,6 +214,19 @@ pgstattuplebyid(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
}
+/* Remove superuser() check for 1.5 version, see above */
+Datum
+pgstattuplebyid_v1_5(PG_FUNCTION_ARGS)
+{
+ Oid relid = PG_GETARG_OID(0);
+ Relation rel;
+
+ /* open relation */
+ rel = relation_open(relid, AccessShareLock);
+
+ PG_RETURN_DATUM(pgstat_relation(rel, fcinfo));
+}
+
/*
* pgstat_relation
*/
diff --git a/contrib/pgstattuple/pgstattuple.control b/contrib/pgstattuple/pgstattuple.control
index fa328fd..6af4075 100644
--- a/contrib/pgstattuple/pgstattuple.control
+++ b/contrib/pgstattuple/pgstattuple.control
@@ -1,5 +1,5 @@
# pgstattuple extension
comment = 'show tuple-level statistics'
-default_version = '1.4'
+default_version = '1.5'
module_pathname = '$libdir/pgstattuple'
relocatable = true
--
2.7.4
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-04 23:36 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-08 16:28 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-26 19:43 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
@ 2016-09-27 06:27 ` Michael Paquier <michael.paquier@gmail.com>
2016-09-28 15:38 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
0 siblings, 1 reply; 14+ messages in thread
From: Michael Paquier @ 2016-09-27 06:27 UTC (permalink / raw)
To: Stephen Frost <sfrost@snowman.net>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers
On Tue, Sep 27, 2016 at 4:43 AM, Stephen Frost <sfrost@snowman.net> wrote:
> * Peter Eisentraut (peter.eisentraut@2ndquadrant.com) wrote:
>> This is now being obsoleted by the later idea of allowing base installs
>> from a chain of upgrade scripts. But if your upgrade scripts contain
>> ALTER TABLE commands, you will probably still want to write base install
>> scripts that do a fresh CREATE TABLE instead.
>
> I've updated the patch to remove the new base version script and to rely
> on the changes made by Tom to install the 1.4 version and then upgrade
> to 1.5.
>
> Based on my testing, it appears to all work correctly.
Same conclusion from here.
> Updated (much smaller) patch attached.
I had a look at it, and it is doing the work it claims to do. So I am
marking it as "Ready for Committer".
--
Michael
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-04 23:36 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-08 16:28 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-26 19:43 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-27 06:27 ` Re: Remove superuser() checks from pgstattuple Michael Paquier <michael.paquier@gmail.com>
@ 2016-09-28 15:38 ` Stephen Frost <sfrost@snowman.net>
0 siblings, 0 replies; 14+ messages in thread
From: Stephen Frost @ 2016-09-28 15:38 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers
Michael,
* Michael Paquier (michael.paquier@gmail.com) wrote:
> On Tue, Sep 27, 2016 at 4:43 AM, Stephen Frost <sfrost@snowman.net> wrote:
> > * Peter Eisentraut (peter.eisentraut@2ndquadrant.com) wrote:
> >> This is now being obsoleted by the later idea of allowing base installs
> >> from a chain of upgrade scripts. But if your upgrade scripts contain
> >> ALTER TABLE commands, you will probably still want to write base install
> >> scripts that do a fresh CREATE TABLE instead.
> >
> > I've updated the patch to remove the new base version script and to rely
> > on the changes made by Tom to install the 1.4 version and then upgrade
> > to 1.5.
> >
> > Based on my testing, it appears to all work correctly.
>
> Same conclusion from here.
Fantastic, thanks for the testing!
> > Updated (much smaller) patch attached.
>
> I had a look at it, and it is doing the work it claims to do. So I am
> marking it as "Ready for Committer".
Great. I'm going to go over the whole patch closely again and will push
it soon.
Thanks again!
Stephen
Attachments:
signature.asc (application/pgp-signature, 818B) download
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-05 00:59 ` Andres Freund <andres@anarazel.de>
2016-09-05 01:09 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 14+ messages in thread
From: Andres Freund @ 2016-09-05 00:59 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Stephen Frost <sfrost@snowman.net>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers
On 2016-09-04 11:55:06 -0400, Tom Lane wrote:
> [ warning, thread hijack ahead ]
>
> Stephen Frost <sfrost@snowman.net> writes:
> > * Peter Eisentraut (peter.eisentraut@2ndquadrant.com) wrote:
> >> I think this is a good change to pursue, and we'll likely want to do
> >> more similar changes in contrib. But I'm worried that what is logically
> >> a 10-line change will end up a 20 KiB patch every time.
>
> > We also created a new version to add the PARALLEL SAFE markings to the
> > functions. In general, I believe it's better to use a new version when
> > we're making these kinds of changes.
>
> It is becoming clear that the current extension update mechanism is kind
> of brute-force for this sort of change. I have no ideas offhand about a
> better way to do it, but like Peter, I was dismayed by the amount of pure
> overhead involved in the PARALLEL SAFE updates.
Agreed. I think one way, which a few extensions are taking, is to have a
base version and then incremental version upgrades. Currently CREATE
EXTENSION doesn't natively support that, so you have to concatenate the
upgrade scripts. I think it'd be great if we could add a 'baseversion'
property to the extension control file. When you create a new extension,
it'll start with the base version and then use the existing code to find
a path to upgrade to the target version. That also makes it a lot
easier to actually properly test extension upgrade paths, something
we've not really been good at.
> It's not only development overhead, either: users have to remember to
> run around and issue ALTER EXTENSION UPDATE for every extension they
> have, in every database they have it installed in. Anyone want to
> lay a side bet on how many users will actually do that? Given that
> the release notes don't currently suggest doing so, I'd be willing
> to put money on "none at all" :-(
Some certainly are, but I'm afraid that you're right that it's not too
many. If we don't make pg_upgrade upgrade all extensions, we should at
least have it generate a script doing so.
Greetings,
Andres Freund
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 00:59 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
@ 2016-09-05 01:09 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 01:13 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 14+ messages in thread
From: Tom Lane @ 2016-09-05 01:09 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Stephen Frost <sfrost@snowman.net>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> On 2016-09-04 11:55:06 -0400, Tom Lane wrote:
>> It is becoming clear that the current extension update mechanism is kind
>> of brute-force for this sort of change. I have no ideas offhand about a
>> better way to do it, but like Peter, I was dismayed by the amount of pure
>> overhead involved in the PARALLEL SAFE updates.
> Agreed. I think one way, which a few extensions are taking, is to have a
> base version and then incremental version upgrades. Currently CREATE
> EXTENSION doesn't natively support that, so you have to concatenate the
> upgrade scripts. I think it'd be great if we could add a 'baseversion'
> property to the extension control file. When you create a new extension,
> it'll start with the base version and then use the existing code to find
> a path to upgrade to the target version. That also makes it a lot
> easier to actually properly test extension upgrade paths, something
> we've not really been good at.
Hm, couldn't we do that automatically? At least in the case where only
one base-version script is available?
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 00:59 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
2016-09-05 01:09 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-05 01:13 ` Andres Freund <andres@anarazel.de>
2016-09-05 01:33 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 14+ messages in thread
From: Andres Freund @ 2016-09-05 01:13 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Stephen Frost <sfrost@snowman.net>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers
On 2016-09-04 21:09:41 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2016-09-04 11:55:06 -0400, Tom Lane wrote:
> >> It is becoming clear that the current extension update mechanism is kind
> >> of brute-force for this sort of change. I have no ideas offhand about a
> >> better way to do it, but like Peter, I was dismayed by the amount of pure
> >> overhead involved in the PARALLEL SAFE updates.
>
> > Agreed. I think one way, which a few extensions are taking, is to have a
> > base version and then incremental version upgrades. Currently CREATE
> > EXTENSION doesn't natively support that, so you have to concatenate the
> > upgrade scripts. I think it'd be great if we could add a 'baseversion'
> > property to the extension control file. When you create a new extension,
> > it'll start with the base version and then use the existing code to find
> > a path to upgrade to the target version. That also makes it a lot
> > easier to actually properly test extension upgrade paths, something
> > we've not really been good at.
>
> Hm, couldn't we do that automatically? At least in the case where only
> one base-version script is available?
You mean determining the baseversion? Hm, yes, that might work. But I'm
not sure how much we can rely on no earlier scripts being already
installed or such. Seems like a problem you'd possibly only encounter in
the field or dirty development environments.
Andres
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 00:59 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
2016-09-05 01:09 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 01:13 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
@ 2016-09-05 01:33 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 01:35 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 14+ messages in thread
From: Tom Lane @ 2016-09-05 01:33 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: Stephen Frost <sfrost@snowman.net>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> On 2016-09-04 21:09:41 -0400, Tom Lane wrote:
>> Hm, couldn't we do that automatically? At least in the case where only
>> one base-version script is available?
> You mean determining the baseversion? Hm, yes, that might work. But I'm
> not sure how much we can rely on no earlier scripts being already
> installed or such. Seems like a problem you'd possibly only encounter in
> the field or dirty development environments.
Actually, why would we care? Pick one, with some tiebreaker rules
(shortest update path, for starters). I think nearly all of the
infrastructure for this is already there in extension.c.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: Remove superuser() checks from pgstattuple
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Re: Remove superuser() checks from pgstattuple Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Re: Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 00:59 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
2016-09-05 01:09 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 01:13 ` Re: Remove superuser() checks from pgstattuple Andres Freund <andres@anarazel.de>
2016-09-05 01:33 ` Re: Remove superuser() checks from pgstattuple Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-09-05 01:35 ` Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 14+ messages in thread
From: Andres Freund @ 2016-09-05 01:35 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Stephen Frost <sfrost@snowman.net>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; pgsql-hackers
On September 4, 2016 6:33:30 PM PDT, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>Andres Freund <andres@anarazel.de> writes:
>> On 2016-09-04 21:09:41 -0400, Tom Lane wrote:
>>> Hm, couldn't we do that automatically? At least in the case where
>only
>>> one base-version script is available?
>
>> You mean determining the baseversion? Hm, yes, that might work. But
>I'm
>> not sure how much we can rely on no earlier scripts being already
>> installed or such. Seems like a problem you'd possibly only encounter
>in
>> the field or dirty development environments.
>
>Actually, why would we care? Pick one, with some tiebreaker rules
>(shortest update path, for starters).
Fair point.
> I think nearly all of the
>infrastructure for this is already there in extension.c.
Yes, it doesn't sound very hard...
Andres
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 14+ messages in thread
end of thread, other threads:[~2016-09-28 15:38 UTC | newest]
Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-08-23 21:22 Remove superuser() checks from pgstattuple Stephen Frost <sfrost@snowman.net>
2016-09-01 17:12 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-04 15:41 ` Stephen Frost <sfrost@snowman.net>
2016-09-04 15:55 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-04 23:36 ` Stephen Frost <sfrost@snowman.net>
2016-09-08 16:28 ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2016-09-26 19:43 ` Stephen Frost <sfrost@snowman.net>
2016-09-27 06:27 ` Michael Paquier <michael.paquier@gmail.com>
2016-09-28 15:38 ` Stephen Frost <sfrost@snowman.net>
2016-09-05 00:59 ` Andres Freund <andres@anarazel.de>
2016-09-05 01:09 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 01:13 ` Andres Freund <andres@anarazel.de>
2016-09-05 01:33 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-09-05 01:35 ` Andres Freund <andres@anarazel.de>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox