From 9df87255f47107c03bf2531bb018e84a69e1fa07 Mon Sep 17 00:00:00 2001
From: Mark Dilger <mark.dilger@enterprisedb.com>
Date: Wed, 20 Oct 2021 07:52:22 -0700
Subject: [PATCH v1 10/12] Adding role pg_manage_stats_settings

This new role can SET and ALTER SYSTEM SET any GUC variable which
controls stats collection.  Note that variables controlling where to
write stats to the server filesystem may not be set by this role
unless the user also has membership in role pg_write_server_files.
---
 doc/src/sgml/user-manag.sgml            |   9 +-
 src/backend/utils/misc/guc.c            |  20 +--
 src/include/catalog/pg_authid.dat       |   5 +
 src/include/utils/guc.h                 |   1 +
 src/test/regress/expected/guc_privs.out | 173 ++++++++++++++++++++++++
 src/test/regress/sql/guc_privs.sql      | 113 ++++++++++++++++
 6 files changed, 311 insertions(+), 10 deletions(-)

diff --git a/doc/src/sgml/user-manag.sgml b/doc/src/sgml/user-manag.sgml
index 3bd08d6aef..548ece3acb 100644
--- a/doc/src/sgml/user-manag.sgml
+++ b/doc/src/sgml/user-manag.sgml
@@ -614,6 +614,10 @@ DROP ROLE doomed_role;
        <entry>pg_manage_query_tuning_settings</entry>
        <entry>Allow changing settings which control tuning of query planning and execution.</entry>
       </row>
+      <row>
+       <entry>pg_manage_stats_settings</entry>
+       <entry>Allow changing settings which control collection of statistics.</entry>
+      </row>
      </tbody>
     </tgroup>
    </table>
@@ -665,8 +669,9 @@ DROP ROLE doomed_role;
   <literal>pg_manage_logging_settings</literal>,
   <literal>pg_manage_replication_settings</literal>,
   <literal>pg_manage_connection_settings</literal>,
-  <literal>pg_manage_wal_settings</literal> and
-  <literal>pg_manage_query_tuning_settings</literal> roles are intended to
+  <literal>pg_manage_wal_settings</literal>,
+  <literal>pg_manage_query_tuning_settings</literal> and
+  <literal>pg_manage_stats_settings</literal> roles are intended to
   allow administrators to have trusted, but non-superuser, roles to configure
   the server.
   </para>
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 65f371138f..a676c4af09 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1575,7 +1575,7 @@ static struct config_bool ConfigureNamesBool[] =
 			gettext_noop("Enables the collection of information on the currently "
 						 "executing command of each session, along with "
 						 "the time at which that command began execution."),
-			GUC_SUPERUSER_ONLY
+			GUC_MANAGE_STATS_SETTINGS
 		},
 		&pgstat_track_activities,
 		true,
@@ -1585,7 +1585,7 @@ static struct config_bool ConfigureNamesBool[] =
 		{"track_counts", PGC_SUSET, STATS_COLLECTOR,
 			gettext_noop("Collects statistics on database activity."),
 			NULL,
-			GUC_SUPERUSER_ONLY
+			GUC_MANAGE_STATS_SETTINGS
 		},
 		&pgstat_track_counts,
 		true,
@@ -1595,7 +1595,7 @@ static struct config_bool ConfigureNamesBool[] =
 		{"track_io_timing", PGC_SUSET, STATS_COLLECTOR,
 			gettext_noop("Collects timing statistics for database I/O activity."),
 			NULL,
-			GUC_SUPERUSER_ONLY
+			GUC_MANAGE_STATS_SETTINGS
 		},
 		&track_io_timing,
 		false,
@@ -1605,7 +1605,7 @@ static struct config_bool ConfigureNamesBool[] =
 		{"track_wal_io_timing", PGC_SUSET, STATS_COLLECTOR,
 			gettext_noop("Collects timing statistics for WAL I/O activity."),
 			NULL,
-			GUC_SUPERUSER_ONLY
+			GUC_MANAGE_STATS_SETTINGS
 		},
 		&track_wal_io_timing,
 		false,
@@ -3726,7 +3726,7 @@ static struct config_int ConfigureNamesInt[] =
 		{"track_activity_query_size", PGC_POSTMASTER, STATS_COLLECTOR,
 			gettext_noop("Sets the size reserved for pg_stat_activity.query, in bytes."),
 			NULL,
-			GUC_SUPERUSER_ONLY,
+			GUC_MANAGE_STATS_SETTINGS,
 			GUC_UNIT_BYTE
 		},
 		&pgstat_track_activity_query_size,
@@ -4793,7 +4793,7 @@ static struct config_string ConfigureNamesString[] =
 		{"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
 			gettext_noop("Writes temporary statistics files to the specified directory."),
 			NULL,
-			GUC_SUPERUSER_ONLY
+			GUC_MANAGE_STATS_SETTINGS | GUC_WRITE_SERVER_FILES
 		},
 		&pgstat_temp_directory,
 		PG_STAT_TMP_DIR,
@@ -4981,7 +4981,7 @@ static struct config_enum ConfigureNamesEnum[] =
 		{"compute_query_id", PGC_SUSET, STATS_MONITORING,
 			gettext_noop("Compute query identifiers."),
 			NULL,
-			GUC_SUPERUSER_ONLY
+			GUC_MANAGE_STATS_SETTINGS
 		},
 		&compute_query_id,
 		COMPUTE_QUERY_ID_AUTO, compute_query_id_options,
@@ -5175,7 +5175,7 @@ static struct config_enum ConfigureNamesEnum[] =
 		{"track_functions", PGC_SUSET, STATS_COLLECTOR,
 			gettext_noop("Collects function-level statistics on database activity."),
 			NULL,
-			GUC_SUPERUSER_ONLY
+			GUC_MANAGE_STATS_SETTINGS
 		},
 		&pgstat_track_functions,
 		TRACK_FUNC_OFF, track_function_options,
@@ -7663,6 +7663,10 @@ role_has_privileges(Oid roleid, int privileges)
 		! has_privs_of_role(roleid, ROLE_PG_MANAGE_QUERY_TUNING_SETTINGS))
 		return false;
 
+	if ((privileges & GUC_MANAGE_STATS_SETTINGS) &&
+		! has_privs_of_role(roleid, ROLE_PG_MANAGE_STATS_SETTINGS))
+		return false;
+
 	return true;
 }
 
diff --git a/src/include/catalog/pg_authid.dat b/src/include/catalog/pg_authid.dat
index 68e305c34f..3f80cbd59b 100644
--- a/src/include/catalog/pg_authid.dat
+++ b/src/include/catalog/pg_authid.dat
@@ -119,5 +119,10 @@
   rolcreaterole => 'f', rolcreatedb => 'f', rolcanlogin => 'f',
   rolreplication => 'f', rolbypassrls => 't', rolconnlimit => '-1',
   rolpassword => '_null_', rolvaliduntil => '_null_' },
+{ oid => '9287', oid_symbol => 'ROLE_PG_MANAGE_STATS_SETTINGS',
+  rolname => 'pg_manage_stats_settings', rolsuper => 'f', rolinherit => 't',
+  rolcreaterole => 'f', rolcreatedb => 'f', rolcanlogin => 'f',
+  rolreplication => 'f', rolbypassrls => 't', rolconnlimit => '-1',
+  rolpassword => '_null_', rolvaliduntil => '_null_' },
 
 ]
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index bca2c113de..3e91f13cb8 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -210,6 +210,7 @@ typedef enum
 #define GUC_MANAGE_CONNECTION_SETTINGS		0x0040
 #define GUC_MANAGE_WAL_SETTINGS				0x0080
 #define GUC_MANAGE_QUERY_TUNING_SETTINGS	0x0200	/* 0x0100 = superuser */
+#define GUC_MANAGE_STATS_SETTINGS			0x0400
 
 /*
  * bit values in "flags" of a GUC variable
diff --git a/src/test/regress/expected/guc_privs.out b/src/test/regress/expected/guc_privs.out
index e748b6531b..4b8d50d93c 100644
--- a/src/test/regress/expected/guc_privs.out
+++ b/src/test/regress/expected/guc_privs.out
@@ -836,3 +836,176 @@ ALTER SYSTEM RESET cpu_index_tuple_cost;  -- ok
 RESET statement_timeout;
 RESET SESSION AUTHORIZATION;
 DROP ROLE regress_query_tuning_admin;
+-- Test role pg_manage_stats_settings
+-- Non-superuser with privileges to configure stats collection
+CREATE ROLE regress_stats_collation_admin NOSUPERUSER;
+GRANT pg_manage_stats_settings TO regress_stats_collation_admin;
+-- Perform all operations as user 'regress_stats_collation_admin' --
+SET SESSION AUTHORIZATION regress_stats_collation_admin;
+-- PGC_BACKEND
+SET ignore_system_indexes = OFF;  -- fail, cannot be set after connection start
+ERROR:  parameter "ignore_system_indexes" cannot be set after connection start
+RESET ignore_system_indexes;  -- fail, cannot be set after connection start
+ERROR:  parameter "ignore_system_indexes" cannot be set after connection start
+ALTER SYSTEM SET ignore_system_indexes = OFF;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "ignore_system_indexes"
+ALTER SYSTEM RESET ignore_system_indexes;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "ignore_system_indexes"
+-- PGC_INTERNAL
+SET block_size = 50;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+RESET block_size;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+ALTER SYSTEM SET block_size = 50;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+ALTER SYSTEM RESET block_size;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+-- PGC_POSTMASTER
+SET autovacuum_freeze_max_age = 1000050000;  -- fail, requires restart
+ERROR:  parameter "autovacuum_freeze_max_age" cannot be changed without restarting the server
+RESET autovacuum_freeze_max_age;  -- fail, requires restart
+ERROR:  parameter "autovacuum_freeze_max_age" cannot be changed without restarting the server
+ALTER SYSTEM SET autovacuum_freeze_max_age = 1000050000;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum_freeze_max_age"
+ALTER SYSTEM RESET autovacuum_freeze_max_age;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum_freeze_max_age"
+ALTER SYSTEM SET config_file = '/usr/local/data/postgresql.conf';  -- fail, cannot be changed
+ERROR:  parameter "config_file" cannot be changed
+ALTER SYSTEM RESET config_file;  -- fail, cannot be changed
+ERROR:  parameter "config_file" cannot be changed
+ALTER SYSTEM SET track_activity_query_size = 524338;  -- ok
+ALTER SYSTEM RESET track_activity_query_size;  -- ok
+-- PGC_SIGHUP
+SET autovacuum = OFF;  -- fail, requires reload
+ERROR:  parameter "autovacuum" cannot be changed now
+RESET autovacuum;  -- fail, requires reload
+ERROR:  parameter "autovacuum" cannot be changed now
+ALTER SYSTEM SET autovacuum = OFF;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum"
+ALTER SYSTEM RESET autovacuum;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum"
+-- PGC_SUSET
+SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+RESET lc_messages;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+ALTER SYSTEM SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+ALTER SYSTEM RESET lc_messages;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+SET track_activities = OFF;  -- ok
+RESET track_activities;  -- ok
+ALTER SYSTEM SET track_activities = OFF;  -- ok
+ALTER SYSTEM RESET track_activities;  -- ok
+-- PGC_SU_BACKEND
+SET jit_debugging_support = OFF;  -- fail, cannot be set after connection start
+ERROR:  parameter "jit_debugging_support" cannot be set after connection start
+RESET jit_debugging_support;  -- fail, cannot be set after connection start
+ERROR:  parameter "jit_debugging_support" cannot be set after connection start
+ALTER SYSTEM SET jit_debugging_support = OFF;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "jit_debugging_support"
+ALTER SYSTEM RESET jit_debugging_support;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "jit_debugging_support"
+-- PGC_USERSET
+SET DateStyle = 'ISO, MDY';  -- ok
+RESET DateStyle;  -- ok
+ALTER SYSTEM SET DateStyle = 'ISO, MDY';  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "datestyle"
+ALTER SYSTEM RESET DateStyle;  -- fail, regress_stats_collation_admin has insufficient privileges
+ERROR:  permission denied to set parameter "datestyle"
+ALTER SYSTEM SET ssl_renegotiation_limit = 0;  -- fail, cannot be changed
+ERROR:  parameter "ssl_renegotiation_limit" cannot be changed
+ALTER SYSTEM RESET ssl_renegotiation_limit;  -- fail, cannot be changed
+ERROR:  parameter "ssl_renegotiation_limit" cannot be changed
+-- Finished testing role pg_manage_stats_settings
+RESET statement_timeout;
+RESET SESSION AUTHORIZATION;
+DROP ROLE regress_stats_collation_admin;
+-- Test combination of roles pg_manage_stats_settings and pg_write_server_files
+-- Non-superuser with privileges to configure stats collection and recording
+CREATE ROLE regress_stats_full_admin NOSUPERUSER;
+GRANT pg_manage_stats_settings TO regress_stats_full_admin;
+GRANT pg_write_server_files TO regress_stats_full_admin;
+-- Perform all operations as user 'regress_stats_full_admin' --
+SET SESSION AUTHORIZATION regress_stats_full_admin;
+-- PGC_BACKEND
+SET ignore_system_indexes = OFF;  -- fail, cannot be set after connection start
+ERROR:  parameter "ignore_system_indexes" cannot be set after connection start
+RESET ignore_system_indexes;  -- fail, cannot be set after connection start
+ERROR:  parameter "ignore_system_indexes" cannot be set after connection start
+ALTER SYSTEM SET ignore_system_indexes = OFF;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "ignore_system_indexes"
+ALTER SYSTEM RESET ignore_system_indexes;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "ignore_system_indexes"
+-- PGC_INTERNAL
+SET block_size = 50;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+RESET block_size;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+ALTER SYSTEM SET block_size = 50;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+ALTER SYSTEM RESET block_size;  -- fail, cannot be changed
+ERROR:  parameter "block_size" cannot be changed
+-- PGC_POSTMASTER
+SET autovacuum_freeze_max_age = 1000050000;  -- fail, requires restart
+ERROR:  parameter "autovacuum_freeze_max_age" cannot be changed without restarting the server
+RESET autovacuum_freeze_max_age;  -- fail, requires restart
+ERROR:  parameter "autovacuum_freeze_max_age" cannot be changed without restarting the server
+ALTER SYSTEM SET autovacuum_freeze_max_age = 1000050000;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum_freeze_max_age"
+ALTER SYSTEM RESET autovacuum_freeze_max_age;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum_freeze_max_age"
+ALTER SYSTEM SET config_file = '/usr/local/data/postgresql.conf';  -- fail, cannot be changed
+ERROR:  parameter "config_file" cannot be changed
+ALTER SYSTEM RESET config_file;  -- fail, cannot be changed
+ERROR:  parameter "config_file" cannot be changed
+ALTER SYSTEM SET track_activity_query_size = 524338;  -- ok
+ALTER SYSTEM RESET track_activity_query_size;  -- ok
+-- PGC_SIGHUP
+SET autovacuum = OFF;  -- fail, requires reload
+ERROR:  parameter "autovacuum" cannot be changed now
+RESET autovacuum;  -- fail, requires reload
+ERROR:  parameter "autovacuum" cannot be changed now
+ALTER SYSTEM SET autovacuum = OFF;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum"
+ALTER SYSTEM RESET autovacuum;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "autovacuum"
+ALTER SYSTEM SET stats_temp_directory = 'pg_stat_tmp';  -- ok
+ALTER SYSTEM RESET stats_temp_directory;  -- ok
+-- PGC_SUSET
+SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+RESET lc_messages;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+ALTER SYSTEM SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+ALTER SYSTEM RESET lc_messages;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "lc_messages"
+SET track_activities = OFF;  -- ok
+RESET track_activities;  -- ok
+ALTER SYSTEM SET track_activities = OFF;  -- ok
+ALTER SYSTEM RESET track_activities;  -- ok
+-- PGC_SU_BACKEND
+SET jit_debugging_support = OFF;  -- fail, cannot be set after connection start
+ERROR:  parameter "jit_debugging_support" cannot be set after connection start
+RESET jit_debugging_support;  -- fail, cannot be set after connection start
+ERROR:  parameter "jit_debugging_support" cannot be set after connection start
+ALTER SYSTEM SET jit_debugging_support = OFF;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "jit_debugging_support"
+ALTER SYSTEM RESET jit_debugging_support;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "jit_debugging_support"
+-- PGC_USERSET
+SET DateStyle = 'ISO, MDY';  -- ok
+RESET DateStyle;  -- ok
+ALTER SYSTEM SET DateStyle = 'ISO, MDY';  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "datestyle"
+ALTER SYSTEM RESET DateStyle;  -- fail, regress_stats_full_admin has insufficient privileges
+ERROR:  permission denied to set parameter "datestyle"
+ALTER SYSTEM SET ssl_renegotiation_limit = 0;  -- fail, cannot be changed
+ERROR:  parameter "ssl_renegotiation_limit" cannot be changed
+ALTER SYSTEM RESET ssl_renegotiation_limit;  -- fail, cannot be changed
+ERROR:  parameter "ssl_renegotiation_limit" cannot be changed
+-- Finished testing combination of roles pg_manage_stats_settings and pg_write_server_files
+RESET statement_timeout;
+RESET SESSION AUTHORIZATION;
+DROP ROLE regress_stats_full_admin;
diff --git a/src/test/regress/sql/guc_privs.sql b/src/test/regress/sql/guc_privs.sql
index d30284f4c9..78b6df76cf 100644
--- a/src/test/regress/sql/guc_privs.sql
+++ b/src/test/regress/sql/guc_privs.sql
@@ -550,3 +550,116 @@ ALTER SYSTEM RESET cpu_index_tuple_cost;  -- ok
 RESET statement_timeout;
 RESET SESSION AUTHORIZATION;
 DROP ROLE regress_query_tuning_admin;
+-- Test role pg_manage_stats_settings
+-- Non-superuser with privileges to configure stats collection
+CREATE ROLE regress_stats_collation_admin NOSUPERUSER;
+GRANT pg_manage_stats_settings TO regress_stats_collation_admin;
+-- Perform all operations as user 'regress_stats_collation_admin' --
+SET SESSION AUTHORIZATION regress_stats_collation_admin;
+-- PGC_BACKEND
+SET ignore_system_indexes = OFF;  -- fail, cannot be set after connection start
+RESET ignore_system_indexes;  -- fail, cannot be set after connection start
+ALTER SYSTEM SET ignore_system_indexes = OFF;  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM RESET ignore_system_indexes;  -- fail, regress_stats_collation_admin has insufficient privileges
+-- PGC_INTERNAL
+SET block_size = 50;  -- fail, cannot be changed
+RESET block_size;  -- fail, cannot be changed
+ALTER SYSTEM SET block_size = 50;  -- fail, cannot be changed
+ALTER SYSTEM RESET block_size;  -- fail, cannot be changed
+-- PGC_POSTMASTER
+SET autovacuum_freeze_max_age = 1000050000;  -- fail, requires restart
+RESET autovacuum_freeze_max_age;  -- fail, requires restart
+ALTER SYSTEM SET autovacuum_freeze_max_age = 1000050000;  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM RESET autovacuum_freeze_max_age;  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM SET config_file = '/usr/local/data/postgresql.conf';  -- fail, cannot be changed
+ALTER SYSTEM RESET config_file;  -- fail, cannot be changed
+ALTER SYSTEM SET track_activity_query_size = 524338;  -- ok
+ALTER SYSTEM RESET track_activity_query_size;  -- ok
+-- PGC_SIGHUP
+SET autovacuum = OFF;  -- fail, requires reload
+RESET autovacuum;  -- fail, requires reload
+ALTER SYSTEM SET autovacuum = OFF;  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM RESET autovacuum;  -- fail, regress_stats_collation_admin has insufficient privileges
+-- PGC_SUSET
+SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_collation_admin has insufficient privileges
+RESET lc_messages;  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM RESET lc_messages;  -- fail, regress_stats_collation_admin has insufficient privileges
+SET track_activities = OFF;  -- ok
+RESET track_activities;  -- ok
+ALTER SYSTEM SET track_activities = OFF;  -- ok
+ALTER SYSTEM RESET track_activities;  -- ok
+-- PGC_SU_BACKEND
+SET jit_debugging_support = OFF;  -- fail, cannot be set after connection start
+RESET jit_debugging_support;  -- fail, cannot be set after connection start
+ALTER SYSTEM SET jit_debugging_support = OFF;  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM RESET jit_debugging_support;  -- fail, regress_stats_collation_admin has insufficient privileges
+-- PGC_USERSET
+SET DateStyle = 'ISO, MDY';  -- ok
+RESET DateStyle;  -- ok
+ALTER SYSTEM SET DateStyle = 'ISO, MDY';  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM RESET DateStyle;  -- fail, regress_stats_collation_admin has insufficient privileges
+ALTER SYSTEM SET ssl_renegotiation_limit = 0;  -- fail, cannot be changed
+ALTER SYSTEM RESET ssl_renegotiation_limit;  -- fail, cannot be changed
+-- Finished testing role pg_manage_stats_settings
+RESET statement_timeout;
+RESET SESSION AUTHORIZATION;
+DROP ROLE regress_stats_collation_admin;
+-- Test combination of roles pg_manage_stats_settings and pg_write_server_files
+-- Non-superuser with privileges to configure stats collection and recording
+CREATE ROLE regress_stats_full_admin NOSUPERUSER;
+GRANT pg_manage_stats_settings TO regress_stats_full_admin;
+GRANT pg_write_server_files TO regress_stats_full_admin;
+-- Perform all operations as user 'regress_stats_full_admin' --
+SET SESSION AUTHORIZATION regress_stats_full_admin;
+-- PGC_BACKEND
+SET ignore_system_indexes = OFF;  -- fail, cannot be set after connection start
+RESET ignore_system_indexes;  -- fail, cannot be set after connection start
+ALTER SYSTEM SET ignore_system_indexes = OFF;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM RESET ignore_system_indexes;  -- fail, regress_stats_full_admin has insufficient privileges
+-- PGC_INTERNAL
+SET block_size = 50;  -- fail, cannot be changed
+RESET block_size;  -- fail, cannot be changed
+ALTER SYSTEM SET block_size = 50;  -- fail, cannot be changed
+ALTER SYSTEM RESET block_size;  -- fail, cannot be changed
+-- PGC_POSTMASTER
+SET autovacuum_freeze_max_age = 1000050000;  -- fail, requires restart
+RESET autovacuum_freeze_max_age;  -- fail, requires restart
+ALTER SYSTEM SET autovacuum_freeze_max_age = 1000050000;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM RESET autovacuum_freeze_max_age;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM SET config_file = '/usr/local/data/postgresql.conf';  -- fail, cannot be changed
+ALTER SYSTEM RESET config_file;  -- fail, cannot be changed
+ALTER SYSTEM SET track_activity_query_size = 524338;  -- ok
+ALTER SYSTEM RESET track_activity_query_size;  -- ok
+-- PGC_SIGHUP
+SET autovacuum = OFF;  -- fail, requires reload
+RESET autovacuum;  -- fail, requires reload
+ALTER SYSTEM SET autovacuum = OFF;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM RESET autovacuum;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM SET stats_temp_directory = 'pg_stat_tmp';  -- ok
+ALTER SYSTEM RESET stats_temp_directory;  -- ok
+-- PGC_SUSET
+SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_full_admin has insufficient privileges
+RESET lc_messages;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM SET lc_messages = 'en_US.UTF-8';  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM RESET lc_messages;  -- fail, regress_stats_full_admin has insufficient privileges
+SET track_activities = OFF;  -- ok
+RESET track_activities;  -- ok
+ALTER SYSTEM SET track_activities = OFF;  -- ok
+ALTER SYSTEM RESET track_activities;  -- ok
+-- PGC_SU_BACKEND
+SET jit_debugging_support = OFF;  -- fail, cannot be set after connection start
+RESET jit_debugging_support;  -- fail, cannot be set after connection start
+ALTER SYSTEM SET jit_debugging_support = OFF;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM RESET jit_debugging_support;  -- fail, regress_stats_full_admin has insufficient privileges
+-- PGC_USERSET
+SET DateStyle = 'ISO, MDY';  -- ok
+RESET DateStyle;  -- ok
+ALTER SYSTEM SET DateStyle = 'ISO, MDY';  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM RESET DateStyle;  -- fail, regress_stats_full_admin has insufficient privileges
+ALTER SYSTEM SET ssl_renegotiation_limit = 0;  -- fail, cannot be changed
+ALTER SYSTEM RESET ssl_renegotiation_limit;  -- fail, cannot be changed
+-- Finished testing combination of roles pg_manage_stats_settings and pg_write_server_files
+RESET statement_timeout;
+RESET SESSION AUTHORIZATION;
+DROP ROLE regress_stats_full_admin;
-- 
2.21.1 (Apple Git-122.3)

