Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
sql-alterdefaultprivileges.html167 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ALTER DEFAULT PRIVILEGES</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-alterdatabase.html" title="ALTER DATABASE" /><link rel="next" href="sql-alterdomain.html" title="ALTER DOMAIN" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">ALTER DEFAULT PRIVILEGES</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterdatabase.html" title="ALTER DATABASE">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-alterdomain.html" title="ALTER DOMAIN">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-ALTERDEFAULTPRIVILEGES"><div class="titlepage"></div><a id="id-1.9.3.8.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER DEFAULT PRIVILEGES</span></h2><p>ALTER DEFAULT PRIVILEGES — define default access privileges</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">3ALTER DEFAULT PRIVILEGES4    [ FOR { ROLE | USER } <em class="replaceable"><code>target_role</code></em> [, ...] ]5    [ IN SCHEMA <em class="replaceable"><code>schema_name</code></em> [, ...] ]6    <em class="replaceable"><code>abbreviated_grant_or_revoke</code></em>7 8<span class="phrase">where <em class="replaceable"><code>abbreviated_grant_or_revoke</code></em> is one of:</span>9 10GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }11    [, ...] | ALL [ PRIVILEGES ] }12    ON TABLES13    TO { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...] [ WITH GRANT OPTION ]14 15GRANT { { USAGE | SELECT | UPDATE }16    [, ...] | ALL [ PRIVILEGES ] }17    ON SEQUENCES18    TO { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...] [ WITH GRANT OPTION ]19 20GRANT { EXECUTE | ALL [ PRIVILEGES ] }21    ON { FUNCTIONS | ROUTINES }22    TO { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...] [ WITH GRANT OPTION ]23 24GRANT { USAGE | ALL [ PRIVILEGES ] }25    ON TYPES26    TO { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...] [ WITH GRANT OPTION ]27 28GRANT { { USAGE | CREATE }29    [, ...] | ALL [ PRIVILEGES ] }30    ON SCHEMAS31    TO { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...] [ WITH GRANT OPTION ]32 33REVOKE [ GRANT OPTION FOR ]34    { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }35    [, ...] | ALL [ PRIVILEGES ] }36    ON TABLES37    FROM { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...]38    [ CASCADE | RESTRICT ]39 40REVOKE [ GRANT OPTION FOR ]41    { { USAGE | SELECT | UPDATE }42    [, ...] | ALL [ PRIVILEGES ] }43    ON SEQUENCES44    FROM { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...]45    [ CASCADE | RESTRICT ]46 47REVOKE [ GRANT OPTION FOR ]48    { EXECUTE | ALL [ PRIVILEGES ] }49    ON { FUNCTIONS | ROUTINES }50    FROM { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...]51    [ CASCADE | RESTRICT ]52 53REVOKE [ GRANT OPTION FOR ]54    { USAGE | ALL [ PRIVILEGES ] }55    ON TYPES56    FROM { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...]57    [ CASCADE | RESTRICT ]58 59REVOKE [ GRANT OPTION FOR ]60    { { USAGE | CREATE }61    [, ...] | ALL [ PRIVILEGES ] }62    ON SCHEMAS63    FROM { [ GROUP ] <em class="replaceable"><code>role_name</code></em> | PUBLIC } [, ...]64    [ CASCADE | RESTRICT ]65</pre></div><div class="refsect1" id="SQL-ALTERDEFAULTPRIVILEGES-DESCRIPTION"><h2>Description</h2><p>66   <code class="command">ALTER DEFAULT PRIVILEGES</code> allows you to set the67   privileges that will be applied to objects created in the future.68   (It does not affect privileges assigned to already-existing objects.)69   Privileges can be set globally (i.e., for all objects created in the70   current database), or just for objects created in specified schemas.71  </p><p>72   While you can change your own default privileges and the defaults of73   roles that you are a member of, at object creation time, new object74   permissions are only affected by the default privileges of the current75   role, and are not inherited from any roles in which the current role76   is a member.77  </p><p>78   As explained in <a class="xref" href="ddl-priv.html" title="5.7. Privileges">Section 5.7</a>,79   the default privileges for any object type normally grant all grantable80   permissions to the object owner, and may grant some privileges to81   <code class="literal">PUBLIC</code> as well.  However, this behavior can be changed by82   altering the global default privileges with83   <code class="command">ALTER DEFAULT PRIVILEGES</code>.84  </p><p>85   Currently,86   only the privileges for schemas, tables (including views and foreign87   tables), sequences, functions, and types (including domains) can be88   altered.  For this command, functions include aggregates and procedures.89   The words <code class="literal">FUNCTIONS</code> and <code class="literal">ROUTINES</code> are90   equivalent in this command.  (<code class="literal">ROUTINES</code> is preferred91   going forward as the standard term for functions and procedures taken92   together.  In earlier PostgreSQL releases, only the93   word <code class="literal">FUNCTIONS</code> was allowed.  It is not possible to set94   default privileges for functions and procedures separately.)95  </p><p>96   Default privileges that are specified per-schema are added to whatever97   the global default privileges are for the particular object type.98   This means you cannot revoke privileges per-schema if they are granted99   globally (either by default, or according to a previous <code class="command">ALTER100   DEFAULT PRIVILEGES</code> command that did not specify a schema).101   Per-schema <code class="literal">REVOKE</code> is only useful to reverse the102   effects of a previous per-schema <code class="literal">GRANT</code>.103  </p><div class="refsect2" id="id-1.9.3.8.5.7"><h3>Parameters</h3><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>target_role</code></em></span></dt><dd><p>104      Change default privileges for objects created by the105      <em class="replaceable"><code>target_role</code></em>, or the current106      role if unspecified.107     </p></dd><dt><span class="term"><em class="replaceable"><code>schema_name</code></em></span></dt><dd><p>108      The name of an existing schema.  If specified, the default privileges109      are altered for objects later created in that schema.110      If <code class="literal">IN SCHEMA</code> is omitted, the global default privileges111      are altered.112      <code class="literal">IN SCHEMA</code> is not allowed when setting privileges113      for schemas, since schemas can't be nested.114     </p></dd><dt><span class="term"><em class="replaceable"><code>role_name</code></em></span></dt><dd><p>115      The name of an existing role to grant or revoke privileges for.116      This parameter, and all the other parameters in117      <em class="replaceable"><code>abbreviated_grant_or_revoke</code></em>,118      act as described under119      <a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a> or120      <a class="xref" href="sql-revoke.html" title="REVOKE"><span class="refentrytitle">REVOKE</span></a>,121      except that one is setting permissions for a whole class of objects122      rather than specific named objects.123     </p></dd></dl></div></div></div><div class="refsect1" id="SQL-ALTERDEFAULTPRIVILEGES-NOTES"><h2>Notes</h2><p>124   Use <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a>'s <code class="command">\ddp</code> command125   to obtain information about existing assignments of default privileges.126   The meaning of the privilege display is the same as explained for127   <code class="command">\dp</code> in <a class="xref" href="ddl-priv.html" title="5.7. Privileges">Section 5.7</a>.128  </p><p>129   If you wish to drop a role for which the default privileges have been130   altered, it is necessary to reverse the changes in its default privileges131   or use <code class="command">DROP OWNED BY</code> to get rid of the default privileges entry132   for the role.133  </p></div><div class="refsect1" id="SQL-ALTERDEFAULTPRIVILEGES-EXAMPLES"><h2>Examples</h2><p>134   Grant SELECT privilege to everyone for all tables (and views) you135   subsequently create in schema <code class="literal">myschema</code>, and allow136   role <code class="literal">webuser</code> to INSERT into them too:137 138</p><pre class="programlisting">139ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT SELECT ON TABLES TO PUBLIC;140ALTER DEFAULT PRIVILEGES IN SCHEMA myschema GRANT INSERT ON TABLES TO webuser;141</pre><p>142  </p><p>143   Undo the above, so that subsequently-created tables won't have any144   more permissions than normal:145 146</p><pre class="programlisting">147ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE SELECT ON TABLES FROM PUBLIC;148ALTER DEFAULT PRIVILEGES IN SCHEMA myschema REVOKE INSERT ON TABLES FROM webuser;149</pre><p>150  </p><p>151   Remove the public EXECUTE permission that is normally granted on functions,152   for all functions subsequently created by role <code class="literal">admin</code>:153</p><pre class="programlisting">154ALTER DEFAULT PRIVILEGES FOR ROLE admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;155</pre><p>156   Note however that you <span class="emphasis"><em>cannot</em></span> accomplish that effect157   with a command limited to a single schema.  This command has no effect,158   unless it is undoing a matching <code class="literal">GRANT</code>:159</p><pre class="programlisting">160ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;161</pre><p>162   That's because per-schema default privileges can only add privileges to163   the global setting, not remove privileges granted by it.164  </p></div><div class="refsect1" id="id-1.9.3.8.8"><h2>Compatibility</h2><p>165   There is no <code class="command">ALTER DEFAULT PRIVILEGES</code> statement in the SQL166   standard.167  </p></div><div class="refsect1" id="id-1.9.3.8.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-grant.html" title="GRANT"><span class="refentrytitle">GRANT</span></a>, <a class="xref" href="sql-revoke.html" title="REVOKE"><span class="refentrytitle">REVOKE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-alterdatabase.html" title="ALTER DATABASE">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-alterdomain.html" title="ALTER DOMAIN">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER DATABASE </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ALTER DOMAIN</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai