2003-11-13 23:13:39 +01:00
|
|
|
/*
|
|
|
|
* PostgreSQL System Views
|
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
2003-11-13 23:13:39 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/catalog/system_views.sql
|
Adjust behavior of single-user -j mode for better initdb error reporting.
Previously, -j caused the entire input file to be read in and executed as
a single command string. That's undesirable, not least because any error
causes the entire file to be regurgitated as the "failing query". Some
experimentation suggests a better rule: end the command string when we see
a semicolon immediately followed by two newlines, ie, an empty line after
a query. This serves nicely to break up the existing examples such as
information_schema.sql and system_views.sql. A limitation is that it's
no longer possible to write such a sequence within a string literal or
multiline comment in a file meant to be read with -j; but there are no
instances of such a problem within the data currently used by initdb.
(If someone does make such a mistake in future, it'll be obvious because
they'll get an unterminated-literal or unterminated-comment syntax error.)
Other than that, there shouldn't be any negative consequences; you're not
forced to end statements that way, it's just a better idea in most cases.
In passing, remove src/include/tcop/tcopdebug.h, which is dead code
because it's not included anywhere, and hasn't been for more than
ten years. One of the debug-support symbols it purported to describe
has been unreferenced for at least the same amount of time, and the
other is removed by this commit on the grounds that it was useless:
forcing -j mode all the time would have broken initdb. The lack of
complaints about that, or about the missing inclusion, shows that
no one has tried to use TCOP_DONTUSENEWLINE in many years.
2015-12-18 01:34:15 +01:00
|
|
|
*
|
|
|
|
* Note: this file is read in single-user -j mode, which means that the
|
|
|
|
* command terminator is semicolon-newline-newline; whenever the backend
|
|
|
|
* sees that, it stops and executes what it's got. If you write a lot of
|
|
|
|
* statements without empty lines between, they'll all get quoted to you
|
|
|
|
* in any error message about one of them, so don't do that. Also, you
|
|
|
|
* cannot write a semicolon immediately followed by an empty line in a
|
|
|
|
* string literal (including a function body!) or a multiline comment.
|
2003-11-13 23:13:39 +01:00
|
|
|
*/
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_roles AS
|
|
|
|
SELECT
|
2005-06-28 07:09:14 +02:00
|
|
|
rolname,
|
2014-12-23 19:35:49 +01:00
|
|
|
rolsuper,
|
|
|
|
rolinherit,
|
|
|
|
rolcreaterole,
|
|
|
|
rolcreatedb,
|
|
|
|
rolcanlogin,
|
|
|
|
rolreplication,
|
2005-07-31 19:19:22 +02:00
|
|
|
rolconnlimit,
|
2005-06-28 07:09:14 +02:00
|
|
|
'********'::text as rolpassword,
|
|
|
|
rolvaliduntil,
|
2014-12-23 19:35:49 +01:00
|
|
|
rolbypassrls,
|
2009-10-08 00:14:26 +02:00
|
|
|
setconfig as rolconfig,
|
|
|
|
pg_authid.oid
|
|
|
|
FROM pg_authid LEFT JOIN pg_db_role_setting s
|
|
|
|
ON (pg_authid.oid = setrole AND setdatabase = 0);
|
2005-06-28 07:09:14 +02:00
|
|
|
|
|
|
|
CREATE VIEW pg_shadow AS
|
|
|
|
SELECT
|
|
|
|
rolname AS usename,
|
2009-10-08 00:14:26 +02:00
|
|
|
pg_authid.oid AS usesysid,
|
2014-12-23 19:35:49 +01:00
|
|
|
rolcreatedb AS usecreatedb,
|
|
|
|
rolsuper AS usesuper,
|
|
|
|
rolreplication AS userepl,
|
2015-01-29 03:47:15 +01:00
|
|
|
rolbypassrls AS usebypassrls,
|
2005-06-28 07:09:14 +02:00
|
|
|
rolpassword AS passwd,
|
2018-09-29 00:21:48 +02:00
|
|
|
rolvaliduntil AS valuntil,
|
2009-10-08 00:14:26 +02:00
|
|
|
setconfig AS useconfig
|
|
|
|
FROM pg_authid LEFT JOIN pg_db_role_setting s
|
|
|
|
ON (pg_authid.oid = setrole AND setdatabase = 0)
|
2014-12-23 19:35:49 +01:00
|
|
|
WHERE rolcanlogin;
|
2005-06-28 07:09:14 +02:00
|
|
|
|
2021-03-27 10:17:12 +01:00
|
|
|
REVOKE ALL ON pg_shadow FROM public;
|
2005-06-28 07:09:14 +02:00
|
|
|
|
|
|
|
CREATE VIEW pg_group AS
|
|
|
|
SELECT
|
|
|
|
rolname AS groname,
|
|
|
|
oid AS grosysid,
|
Ensure that pg_auth_members.grantor is always valid.
Previously, "GRANT foo TO bar" or "GRANT foo TO bar GRANTED BY baz"
would record the OID of the grantor in pg_auth_members.grantor, but
that role could later be dropped without modifying or removing the
pg_auth_members record. That's not great, because we typically try
to avoid dangling references in catalog data.
Now, a role grant depends on the grantor, and the grantor can't be
dropped without removing the grant or changing the grantor. "DROP
OWNED BY" will remove the grant, just as it does for other kinds of
privileges. "REASSIGN OWNED BY" will not, again just like what we do
in other cases involving privileges.
pg_auth_members now has an OID column, because that is needed in order
for dependencies to work. It also now has an index on the grantor
column, because otherwise dropping a role would require a sequential
scan of the entire table to see whether the role's OID is in use as
a grantor. That probably wouldn't be too large a problem in practice,
but it seems better to have an index just in case.
A follow-on patch is planned with the goal of more thoroughly
rationalizing the behavior of role grants. This patch is just trying
to do enough to make sure that the data we store in the catalogs is at
some basic level valid.
Patch by me, reviewed by Stephen Frost
Discussion: http://postgr.es/m/CA+TgmoaFr-RZeQ+WoQ5nKPv97oT9+aDgK_a5+qWHSgbDsMp1Vg@mail.gmail.com
2022-08-18 19:13:02 +02:00
|
|
|
ARRAY(SELECT member FROM pg_auth_members WHERE roleid = pg_authid.oid) AS grolist
|
2005-06-28 07:09:14 +02:00
|
|
|
FROM pg_authid
|
2014-12-23 19:35:49 +01:00
|
|
|
WHERE NOT rolcanlogin;
|
2005-06-28 07:09:14 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_user AS
|
|
|
|
SELECT
|
|
|
|
usename,
|
|
|
|
usesysid,
|
|
|
|
usecreatedb,
|
|
|
|
usesuper,
|
2010-12-29 11:05:03 +01:00
|
|
|
userepl,
|
2015-01-29 03:47:15 +01:00
|
|
|
usebypassrls,
|
2010-11-23 21:27:50 +01:00
|
|
|
'********'::text as passwd,
|
|
|
|
valuntil,
|
|
|
|
useconfig
|
2003-11-13 23:13:39 +01:00
|
|
|
FROM pg_shadow;
|
|
|
|
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
CREATE VIEW pg_policies AS
|
|
|
|
SELECT
|
2014-10-03 22:31:53 +02:00
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS tablename,
|
Rename pg_rowsecurity -> pg_policy and other fixes
As pointed out by Robert, we should really have named pg_rowsecurity
pg_policy, as the objects stored in that catalog are policies. This
patch fixes that and updates the column names to start with 'pol' to
match the new catalog name.
The security consideration for COPY with row level security, also
pointed out by Robert, has also been addressed by remembering and
re-checking the OID of the relation initially referenced during COPY
processing, to make sure it hasn't changed under us by the time we
finish planning out the query which has been built.
Robert and Alvaro also commented on missing OCLASS and OBJECT entries
for POLICY (formerly ROWSECURITY or POLICY, depending) in various
places. This patch fixes that too, which also happens to add the
ability to COMMENT on policies.
In passing, attempt to improve the consistency of messages, comments,
and documentation as well. This removes various incarnations of
'row-security', 'row-level security', 'Row-security', etc, in favor
of 'policy', 'row level security' or 'row_security' as appropriate.
Happy Thanksgiving!
2014-11-27 07:06:36 +01:00
|
|
|
pol.polname AS policyname,
|
2016-12-05 21:50:55 +01:00
|
|
|
CASE
|
|
|
|
WHEN pol.polpermissive THEN
|
|
|
|
'PERMISSIVE'
|
|
|
|
ELSE
|
|
|
|
'RESTRICTIVE'
|
|
|
|
END AS permissive,
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
CASE
|
Rename pg_rowsecurity -> pg_policy and other fixes
As pointed out by Robert, we should really have named pg_rowsecurity
pg_policy, as the objects stored in that catalog are policies. This
patch fixes that and updates the column names to start with 'pol' to
match the new catalog name.
The security consideration for COPY with row level security, also
pointed out by Robert, has also been addressed by remembering and
re-checking the OID of the relation initially referenced during COPY
processing, to make sure it hasn't changed under us by the time we
finish planning out the query which has been built.
Robert and Alvaro also commented on missing OCLASS and OBJECT entries
for POLICY (formerly ROWSECURITY or POLICY, depending) in various
places. This patch fixes that too, which also happens to add the
ability to COMMENT on policies.
In passing, attempt to improve the consistency of messages, comments,
and documentation as well. This removes various incarnations of
'row-security', 'row-level security', 'Row-security', etc, in favor
of 'policy', 'row level security' or 'row_security' as appropriate.
Happy Thanksgiving!
2014-11-27 07:06:36 +01:00
|
|
|
WHEN pol.polroles = '{0}' THEN
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
string_to_array('public', '')
|
|
|
|
ELSE
|
|
|
|
ARRAY
|
|
|
|
(
|
|
|
|
SELECT rolname
|
|
|
|
FROM pg_catalog.pg_authid
|
Rename pg_rowsecurity -> pg_policy and other fixes
As pointed out by Robert, we should really have named pg_rowsecurity
pg_policy, as the objects stored in that catalog are policies. This
patch fixes that and updates the column names to start with 'pol' to
match the new catalog name.
The security consideration for COPY with row level security, also
pointed out by Robert, has also been addressed by remembering and
re-checking the OID of the relation initially referenced during COPY
processing, to make sure it hasn't changed under us by the time we
finish planning out the query which has been built.
Robert and Alvaro also commented on missing OCLASS and OBJECT entries
for POLICY (formerly ROWSECURITY or POLICY, depending) in various
places. This patch fixes that too, which also happens to add the
ability to COMMENT on policies.
In passing, attempt to improve the consistency of messages, comments,
and documentation as well. This removes various incarnations of
'row-security', 'row-level security', 'Row-security', etc, in favor
of 'policy', 'row level security' or 'row_security' as appropriate.
Happy Thanksgiving!
2014-11-27 07:06:36 +01:00
|
|
|
WHERE oid = ANY (pol.polroles) ORDER BY 1
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
)
|
|
|
|
END AS roles,
|
2015-01-24 22:16:22 +01:00
|
|
|
CASE pol.polcmd
|
|
|
|
WHEN 'r' THEN 'SELECT'
|
|
|
|
WHEN 'a' THEN 'INSERT'
|
|
|
|
WHEN 'w' THEN 'UPDATE'
|
|
|
|
WHEN 'd' THEN 'DELETE'
|
|
|
|
WHEN '*' THEN 'ALL'
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
END AS cmd,
|
Rename pg_rowsecurity -> pg_policy and other fixes
As pointed out by Robert, we should really have named pg_rowsecurity
pg_policy, as the objects stored in that catalog are policies. This
patch fixes that and updates the column names to start with 'pol' to
match the new catalog name.
The security consideration for COPY with row level security, also
pointed out by Robert, has also been addressed by remembering and
re-checking the OID of the relation initially referenced during COPY
processing, to make sure it hasn't changed under us by the time we
finish planning out the query which has been built.
Robert and Alvaro also commented on missing OCLASS and OBJECT entries
for POLICY (formerly ROWSECURITY or POLICY, depending) in various
places. This patch fixes that too, which also happens to add the
ability to COMMENT on policies.
In passing, attempt to improve the consistency of messages, comments,
and documentation as well. This removes various incarnations of
'row-security', 'row-level security', 'Row-security', etc, in favor
of 'policy', 'row level security' or 'row_security' as appropriate.
Happy Thanksgiving!
2014-11-27 07:06:36 +01:00
|
|
|
pg_catalog.pg_get_expr(pol.polqual, pol.polrelid) AS qual,
|
|
|
|
pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid) AS with_check
|
|
|
|
FROM pg_catalog.pg_policy pol
|
|
|
|
JOIN pg_catalog.pg_class C ON (C.oid = pol.polrelid)
|
2014-10-03 22:31:53 +02:00
|
|
|
LEFT JOIN pg_catalog.pg_namespace N ON (N.oid = C.relnamespace);
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_rules AS
|
|
|
|
SELECT
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS tablename,
|
|
|
|
R.rulename AS rulename,
|
|
|
|
pg_get_ruledef(R.oid) AS definition
|
|
|
|
FROM (pg_rewrite R JOIN pg_class C ON (C.oid = R.ev_class))
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2003-11-13 23:13:39 +01:00
|
|
|
WHERE R.rulename != '_RETURN';
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_views AS
|
|
|
|
SELECT
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS viewname,
|
|
|
|
pg_get_userbyid(C.relowner) AS viewowner,
|
|
|
|
pg_get_viewdef(C.oid) AS definition
|
|
|
|
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2003-11-13 23:13:39 +01:00
|
|
|
WHERE C.relkind = 'v';
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_tables AS
|
|
|
|
SELECT
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS tablename,
|
|
|
|
pg_get_userbyid(C.relowner) AS tableowner,
|
2004-10-11 19:24:41 +02:00
|
|
|
T.spcname AS tablespace,
|
2010-11-23 21:27:50 +01:00
|
|
|
C.relhasindex AS hasindexes,
|
|
|
|
C.relhasrules AS hasrules,
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
C.relhastriggers AS hastriggers,
|
Code review for row security.
Buildfarm member tick identified an issue where the policies in the
relcache for a relation were were being replaced underneath a running
query, leading to segfaults while processing the policies to be added
to a query. Similar to how TupleDesc RuleLocks are handled, add in a
equalRSDesc() function to check if the policies have actually changed
and, if not, swap back the rsdesc field (using the original instead of
the temporairly built one; the whole structure is swapped and then
specific fields swapped back). This now passes a CLOBBER_CACHE_ALWAYS
for me and should resolve the buildfarm error.
In addition to addressing this, add a new chapter in Data Definition
under Privileges which explains row security and provides examples of
its usage, change \d to always list policies (even if row security is
disabled- but note that it is disabled, or enabled with no policies),
rework check_role_for_policy (it really didn't need the entire policy,
but it did need to be using has_privs_of_role()), and change the field
in pg_class to relrowsecurity from relhasrowsecurity, based on
Heikki's suggestion. Also from Heikki, only issue SET ROW_SECURITY in
pg_restore when talking to a 9.5+ server, list Bypass RLS in \du, and
document --enable-row-security options for pg_dump and pg_restore.
Lastly, fix a number of minor whitespace and typo issues from Heikki,
Dimitri, add a missing #include, per Peter E, fix a few minor
variable-assigned-but-not-used and resource leak issues from Coverity
and add tab completion for role attribute bypassrls as well.
2014-09-24 22:32:22 +02:00
|
|
|
C.relrowsecurity AS rowsecurity
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2004-07-21 22:43:53 +02:00
|
|
|
LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace)
|
2017-03-10 19:15:47 +01:00
|
|
|
WHERE C.relkind IN ('r', 'p');
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2013-03-04 01:23:31 +01:00
|
|
|
CREATE VIEW pg_matviews AS
|
|
|
|
SELECT
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS matviewname,
|
|
|
|
pg_get_userbyid(C.relowner) AS matviewowner,
|
|
|
|
T.spcname AS tablespace,
|
|
|
|
C.relhasindex AS hasindexes,
|
2013-05-06 19:26:51 +02:00
|
|
|
C.relispopulated AS ispopulated,
|
2013-03-04 01:23:31 +01:00
|
|
|
pg_get_viewdef(C.oid) AS definition
|
|
|
|
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
|
|
|
LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace)
|
|
|
|
WHERE C.relkind = 'm';
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_indexes AS
|
|
|
|
SELECT
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS tablename,
|
|
|
|
I.relname AS indexname,
|
2004-10-11 19:24:41 +02:00
|
|
|
T.spcname AS tablespace,
|
2010-11-23 21:27:50 +01:00
|
|
|
pg_get_indexdef(I.oid) AS indexdef
|
|
|
|
FROM pg_index X JOIN pg_class C ON (C.oid = X.indrelid)
|
|
|
|
JOIN pg_class I ON (I.oid = X.indexrelid)
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2004-10-11 19:24:41 +02:00
|
|
|
LEFT JOIN pg_tablespace T ON (T.oid = I.reltablespace)
|
2018-12-18 08:37:51 +01:00
|
|
|
WHERE C.relkind IN ('r', 'm', 'p') AND I.relkind IN ('i', 'I');
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2021-04-17 00:20:42 +02:00
|
|
|
CREATE VIEW pg_sequences AS
|
2016-11-18 18:00:00 +01:00
|
|
|
SELECT
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS sequencename,
|
|
|
|
pg_get_userbyid(C.relowner) AS sequenceowner,
|
2017-02-10 21:12:32 +01:00
|
|
|
S.seqtypid::regtype AS data_type,
|
2016-12-20 18:00:00 +01:00
|
|
|
S.seqstart AS start_value,
|
|
|
|
S.seqmin AS min_value,
|
|
|
|
S.seqmax AS max_value,
|
|
|
|
S.seqincrement AS increment_by,
|
|
|
|
S.seqcycle AS cycle,
|
|
|
|
S.seqcache AS cache_size,
|
2017-02-06 21:17:27 +01:00
|
|
|
CASE
|
|
|
|
WHEN has_sequence_privilege(C.oid, 'SELECT,USAGE'::text)
|
|
|
|
THEN pg_sequence_last_value(C.oid)
|
|
|
|
ELSE NULL
|
|
|
|
END AS last_value
|
2016-12-20 18:00:00 +01:00
|
|
|
FROM pg_sequence S JOIN pg_class C ON (C.oid = S.seqrelid)
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2016-11-18 18:00:00 +01:00
|
|
|
WHERE NOT pg_is_other_temp_schema(N.oid)
|
|
|
|
AND relkind = 'S';
|
|
|
|
|
2015-07-28 22:21:22 +02:00
|
|
|
CREATE VIEW pg_stats WITH (security_barrier) AS
|
2010-11-23 21:27:50 +01:00
|
|
|
SELECT
|
|
|
|
nspname AS schemaname,
|
|
|
|
relname AS tablename,
|
|
|
|
attname AS attname,
|
|
|
|
stainherit AS inherited,
|
|
|
|
stanullfrac AS null_frac,
|
|
|
|
stawidth AS avg_width,
|
|
|
|
stadistinct AS n_distinct,
|
2008-07-14 02:51:46 +02:00
|
|
|
CASE
|
2012-03-04 02:20:19 +01:00
|
|
|
WHEN stakind1 = 1 THEN stavalues1
|
|
|
|
WHEN stakind2 = 1 THEN stavalues2
|
|
|
|
WHEN stakind3 = 1 THEN stavalues3
|
|
|
|
WHEN stakind4 = 1 THEN stavalues4
|
|
|
|
WHEN stakind5 = 1 THEN stavalues5
|
2008-07-14 02:51:46 +02:00
|
|
|
END AS most_common_vals,
|
|
|
|
CASE
|
2012-03-04 02:20:19 +01:00
|
|
|
WHEN stakind1 = 1 THEN stanumbers1
|
|
|
|
WHEN stakind2 = 1 THEN stanumbers2
|
|
|
|
WHEN stakind3 = 1 THEN stanumbers3
|
|
|
|
WHEN stakind4 = 1 THEN stanumbers4
|
|
|
|
WHEN stakind5 = 1 THEN stanumbers5
|
2008-07-14 02:51:46 +02:00
|
|
|
END AS most_common_freqs,
|
|
|
|
CASE
|
|
|
|
WHEN stakind1 = 2 THEN stavalues1
|
|
|
|
WHEN stakind2 = 2 THEN stavalues2
|
|
|
|
WHEN stakind3 = 2 THEN stavalues3
|
|
|
|
WHEN stakind4 = 2 THEN stavalues4
|
2012-03-04 02:20:19 +01:00
|
|
|
WHEN stakind5 = 2 THEN stavalues5
|
2008-07-14 02:51:46 +02:00
|
|
|
END AS histogram_bounds,
|
|
|
|
CASE
|
|
|
|
WHEN stakind1 = 3 THEN stanumbers1[1]
|
|
|
|
WHEN stakind2 = 3 THEN stanumbers2[1]
|
|
|
|
WHEN stakind3 = 3 THEN stanumbers3[1]
|
|
|
|
WHEN stakind4 = 3 THEN stanumbers4[1]
|
2012-03-04 02:20:19 +01:00
|
|
|
WHEN stakind5 = 3 THEN stanumbers5[1]
|
|
|
|
END AS correlation,
|
|
|
|
CASE
|
|
|
|
WHEN stakind1 = 4 THEN stavalues1
|
|
|
|
WHEN stakind2 = 4 THEN stavalues2
|
|
|
|
WHEN stakind3 = 4 THEN stavalues3
|
|
|
|
WHEN stakind4 = 4 THEN stavalues4
|
|
|
|
WHEN stakind5 = 4 THEN stavalues5
|
|
|
|
END AS most_common_elems,
|
|
|
|
CASE
|
|
|
|
WHEN stakind1 = 4 THEN stanumbers1
|
|
|
|
WHEN stakind2 = 4 THEN stanumbers2
|
|
|
|
WHEN stakind3 = 4 THEN stanumbers3
|
|
|
|
WHEN stakind4 = 4 THEN stanumbers4
|
|
|
|
WHEN stakind5 = 4 THEN stanumbers5
|
|
|
|
END AS most_common_elem_freqs,
|
|
|
|
CASE
|
|
|
|
WHEN stakind1 = 5 THEN stanumbers1
|
|
|
|
WHEN stakind2 = 5 THEN stanumbers2
|
|
|
|
WHEN stakind3 = 5 THEN stanumbers3
|
|
|
|
WHEN stakind4 = 5 THEN stanumbers4
|
|
|
|
WHEN stakind5 = 5 THEN stanumbers5
|
|
|
|
END AS elem_count_histogram
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_statistic s JOIN pg_class c ON (c.oid = s.starelid)
|
|
|
|
JOIN pg_attribute a ON (c.oid = attrelid AND attnum = s.staattnum)
|
|
|
|
LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
|
2015-07-28 22:21:22 +02:00
|
|
|
WHERE NOT attisdropped
|
|
|
|
AND has_column_privilege(c.oid, a.attnum, 'select')
|
|
|
|
AND (c.relrowsecurity = false OR NOT row_security_active(c.oid));
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2021-03-27 10:17:12 +01:00
|
|
|
REVOKE ALL ON pg_statistic FROM public;
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2019-06-13 17:25:04 +02:00
|
|
|
CREATE VIEW pg_stats_ext WITH (security_barrier) AS
|
|
|
|
SELECT cn.nspname AS schemaname,
|
|
|
|
c.relname AS tablename,
|
|
|
|
sn.nspname AS statistics_schemaname,
|
|
|
|
s.stxname AS statistics_name,
|
|
|
|
pg_get_userbyid(s.stxowner) AS statistics_owner,
|
|
|
|
( SELECT array_agg(a.attname ORDER BY a.attnum)
|
|
|
|
FROM unnest(s.stxkeys) k
|
|
|
|
JOIN pg_attribute a
|
|
|
|
ON (a.attrelid = s.stxrelid AND a.attnum = k)
|
|
|
|
) AS attnames,
|
Extended statistics on expressions
Allow defining extended statistics on expressions, not just just on
simple column references. With this commit, expressions are supported
by all existing extended statistics kinds, improving the same types of
estimates. A simple example may look like this:
CREATE TABLE t (a int);
CREATE STATISTICS s ON mod(a,10), mod(a,20) FROM t;
ANALYZE t;
The collected statistics are useful e.g. to estimate queries with those
expressions in WHERE or GROUP BY clauses:
SELECT * FROM t WHERE mod(a,10) = 0 AND mod(a,20) = 0;
SELECT 1 FROM t GROUP BY mod(a,10), mod(a,20);
This introduces new internal statistics kind 'e' (expressions) which is
built automatically when the statistics object definition includes any
expressions. This represents single-expression statistics, as if there
was an expression index (but without the index maintenance overhead).
The statistics is stored in pg_statistics_ext_data as an array of
composite types, which is possible thanks to 79f6a942bd.
CREATE STATISTICS allows building statistics on a single expression, in
which case in which case it's not possible to specify statistics kinds.
A new system view pg_stats_ext_exprs can be used to display expression
statistics, similarly to pg_stats and pg_stats_ext views.
ALTER TABLE ... ALTER COLUMN ... TYPE now treats indexes the same way it
treats indexes, i.e. it drops and recreates the statistics. This means
all statistics are reset, and we no longer try to preserve at least the
functional dependencies. This should not be a major issue in practice,
as the functional dependencies actually rely on per-column statistics,
which were always reset anyway.
Author: Tomas Vondra
Reviewed-by: Justin Pryzby, Dean Rasheed, Zhihong Yu
Discussion: https://postgr.es/m/ad7891d2-e90c-b446-9fe2-7419143847d7%40enterprisedb.com
2021-03-26 23:22:01 +01:00
|
|
|
pg_get_statisticsobjdef_expressions(s.oid) as exprs,
|
2019-06-13 17:25:04 +02:00
|
|
|
s.stxkind AS kinds,
|
Add stxdinherit flag to pg_statistic_ext_data
Add pg_statistic_ext_data.stxdinherit flag, so that for each extended
statistics definition we can store two versions of data - one for the
relation alone, one for the whole inheritance tree. This is analogous to
pg_statistic.stainherit, but we failed to include such flag in catalogs
for extended statistics, and we had to work around it (see commits
859b3003de, 36c4bc6e72 and 20b9fa308e).
This changes the relationship between the two catalogs storing extended
statistics objects (pg_statistic_ext and pg_statistic_ext_data). Until
now, there was a simple 1:1 mapping - for each definition there was one
pg_statistic_ext_data row, and this row was inserted while creating the
statistics (and then updated during ANALYZE). With the stxdinherit flag,
we don't know how many rows there will be (child relations may be added
after the statistics object is defined), so there may be up to two rows.
We could make CREATE STATISTICS to always create both rows, but that
seems wasteful - without partitioning we only need stxdinherit=false
rows, and declaratively partitioned tables need only stxdinherit=true.
So we no longer initialize pg_statistic_ext_data in CREATE STATISTICS,
and instead make that a responsibility of ANALYZE. Which is what we do
for regular statistics too.
Patch by me, with extensive improvements and fixes by Justin Pryzby.
Author: Tomas Vondra, Justin Pryzby
Reviewed-by: Tomas Vondra, Justin Pryzby
Discussion: https://postgr.es/m/20210923212624.GI831%40telsasoft.com
2022-01-16 13:37:56 +01:00
|
|
|
sd.stxdinherit AS inherited,
|
2019-06-13 17:25:04 +02:00
|
|
|
sd.stxdndistinct AS n_distinct,
|
|
|
|
sd.stxddependencies AS dependencies,
|
|
|
|
m.most_common_vals,
|
|
|
|
m.most_common_val_nulls,
|
|
|
|
m.most_common_freqs,
|
|
|
|
m.most_common_base_freqs
|
|
|
|
FROM pg_statistic_ext s JOIN pg_class c ON (c.oid = s.stxrelid)
|
|
|
|
JOIN pg_statistic_ext_data sd ON (s.oid = sd.stxoid)
|
|
|
|
LEFT JOIN pg_namespace cn ON (cn.oid = c.relnamespace)
|
|
|
|
LEFT JOIN pg_namespace sn ON (sn.oid = s.stxnamespace)
|
|
|
|
LEFT JOIN LATERAL
|
|
|
|
( SELECT array_agg(values) AS most_common_vals,
|
|
|
|
array_agg(nulls) AS most_common_val_nulls,
|
|
|
|
array_agg(frequency) AS most_common_freqs,
|
|
|
|
array_agg(base_frequency) AS most_common_base_freqs
|
|
|
|
FROM pg_mcv_list_items(sd.stxdmcv)
|
|
|
|
) m ON sd.stxdmcv IS NOT NULL
|
|
|
|
WHERE NOT EXISTS
|
|
|
|
( SELECT 1
|
|
|
|
FROM unnest(stxkeys) k
|
|
|
|
JOIN pg_attribute a
|
|
|
|
ON (a.attrelid = s.stxrelid AND a.attnum = k)
|
|
|
|
WHERE NOT has_column_privilege(c.oid, a.attnum, 'select') )
|
|
|
|
AND (c.relrowsecurity = false OR NOT row_security_active(c.oid));
|
|
|
|
|
Extended statistics on expressions
Allow defining extended statistics on expressions, not just just on
simple column references. With this commit, expressions are supported
by all existing extended statistics kinds, improving the same types of
estimates. A simple example may look like this:
CREATE TABLE t (a int);
CREATE STATISTICS s ON mod(a,10), mod(a,20) FROM t;
ANALYZE t;
The collected statistics are useful e.g. to estimate queries with those
expressions in WHERE or GROUP BY clauses:
SELECT * FROM t WHERE mod(a,10) = 0 AND mod(a,20) = 0;
SELECT 1 FROM t GROUP BY mod(a,10), mod(a,20);
This introduces new internal statistics kind 'e' (expressions) which is
built automatically when the statistics object definition includes any
expressions. This represents single-expression statistics, as if there
was an expression index (but without the index maintenance overhead).
The statistics is stored in pg_statistics_ext_data as an array of
composite types, which is possible thanks to 79f6a942bd.
CREATE STATISTICS allows building statistics on a single expression, in
which case in which case it's not possible to specify statistics kinds.
A new system view pg_stats_ext_exprs can be used to display expression
statistics, similarly to pg_stats and pg_stats_ext views.
ALTER TABLE ... ALTER COLUMN ... TYPE now treats indexes the same way it
treats indexes, i.e. it drops and recreates the statistics. This means
all statistics are reset, and we no longer try to preserve at least the
functional dependencies. This should not be a major issue in practice,
as the functional dependencies actually rely on per-column statistics,
which were always reset anyway.
Author: Tomas Vondra
Reviewed-by: Justin Pryzby, Dean Rasheed, Zhihong Yu
Discussion: https://postgr.es/m/ad7891d2-e90c-b446-9fe2-7419143847d7%40enterprisedb.com
2021-03-26 23:22:01 +01:00
|
|
|
CREATE VIEW pg_stats_ext_exprs WITH (security_barrier) AS
|
|
|
|
SELECT cn.nspname AS schemaname,
|
|
|
|
c.relname AS tablename,
|
|
|
|
sn.nspname AS statistics_schemaname,
|
|
|
|
s.stxname AS statistics_name,
|
|
|
|
pg_get_userbyid(s.stxowner) AS statistics_owner,
|
|
|
|
stat.expr,
|
Add stxdinherit flag to pg_statistic_ext_data
Add pg_statistic_ext_data.stxdinherit flag, so that for each extended
statistics definition we can store two versions of data - one for the
relation alone, one for the whole inheritance tree. This is analogous to
pg_statistic.stainherit, but we failed to include such flag in catalogs
for extended statistics, and we had to work around it (see commits
859b3003de, 36c4bc6e72 and 20b9fa308e).
This changes the relationship between the two catalogs storing extended
statistics objects (pg_statistic_ext and pg_statistic_ext_data). Until
now, there was a simple 1:1 mapping - for each definition there was one
pg_statistic_ext_data row, and this row was inserted while creating the
statistics (and then updated during ANALYZE). With the stxdinherit flag,
we don't know how many rows there will be (child relations may be added
after the statistics object is defined), so there may be up to two rows.
We could make CREATE STATISTICS to always create both rows, but that
seems wasteful - without partitioning we only need stxdinherit=false
rows, and declaratively partitioned tables need only stxdinherit=true.
So we no longer initialize pg_statistic_ext_data in CREATE STATISTICS,
and instead make that a responsibility of ANALYZE. Which is what we do
for regular statistics too.
Patch by me, with extensive improvements and fixes by Justin Pryzby.
Author: Tomas Vondra, Justin Pryzby
Reviewed-by: Tomas Vondra, Justin Pryzby
Discussion: https://postgr.es/m/20210923212624.GI831%40telsasoft.com
2022-01-16 13:37:56 +01:00
|
|
|
sd.stxdinherit AS inherited,
|
Extended statistics on expressions
Allow defining extended statistics on expressions, not just just on
simple column references. With this commit, expressions are supported
by all existing extended statistics kinds, improving the same types of
estimates. A simple example may look like this:
CREATE TABLE t (a int);
CREATE STATISTICS s ON mod(a,10), mod(a,20) FROM t;
ANALYZE t;
The collected statistics are useful e.g. to estimate queries with those
expressions in WHERE or GROUP BY clauses:
SELECT * FROM t WHERE mod(a,10) = 0 AND mod(a,20) = 0;
SELECT 1 FROM t GROUP BY mod(a,10), mod(a,20);
This introduces new internal statistics kind 'e' (expressions) which is
built automatically when the statistics object definition includes any
expressions. This represents single-expression statistics, as if there
was an expression index (but without the index maintenance overhead).
The statistics is stored in pg_statistics_ext_data as an array of
composite types, which is possible thanks to 79f6a942bd.
CREATE STATISTICS allows building statistics on a single expression, in
which case in which case it's not possible to specify statistics kinds.
A new system view pg_stats_ext_exprs can be used to display expression
statistics, similarly to pg_stats and pg_stats_ext views.
ALTER TABLE ... ALTER COLUMN ... TYPE now treats indexes the same way it
treats indexes, i.e. it drops and recreates the statistics. This means
all statistics are reset, and we no longer try to preserve at least the
functional dependencies. This should not be a major issue in practice,
as the functional dependencies actually rely on per-column statistics,
which were always reset anyway.
Author: Tomas Vondra
Reviewed-by: Justin Pryzby, Dean Rasheed, Zhihong Yu
Discussion: https://postgr.es/m/ad7891d2-e90c-b446-9fe2-7419143847d7%40enterprisedb.com
2021-03-26 23:22:01 +01:00
|
|
|
(stat.a).stanullfrac AS null_frac,
|
|
|
|
(stat.a).stawidth AS avg_width,
|
|
|
|
(stat.a).stadistinct AS n_distinct,
|
|
|
|
(CASE
|
|
|
|
WHEN (stat.a).stakind1 = 1 THEN (stat.a).stavalues1
|
|
|
|
WHEN (stat.a).stakind2 = 1 THEN (stat.a).stavalues2
|
|
|
|
WHEN (stat.a).stakind3 = 1 THEN (stat.a).stavalues3
|
|
|
|
WHEN (stat.a).stakind4 = 1 THEN (stat.a).stavalues4
|
|
|
|
WHEN (stat.a).stakind5 = 1 THEN (stat.a).stavalues5
|
|
|
|
END) AS most_common_vals,
|
|
|
|
(CASE
|
|
|
|
WHEN (stat.a).stakind1 = 1 THEN (stat.a).stanumbers1
|
|
|
|
WHEN (stat.a).stakind2 = 1 THEN (stat.a).stanumbers2
|
|
|
|
WHEN (stat.a).stakind3 = 1 THEN (stat.a).stanumbers3
|
|
|
|
WHEN (stat.a).stakind4 = 1 THEN (stat.a).stanumbers4
|
|
|
|
WHEN (stat.a).stakind5 = 1 THEN (stat.a).stanumbers5
|
|
|
|
END) AS most_common_freqs,
|
|
|
|
(CASE
|
|
|
|
WHEN (stat.a).stakind1 = 2 THEN (stat.a).stavalues1
|
|
|
|
WHEN (stat.a).stakind2 = 2 THEN (stat.a).stavalues2
|
|
|
|
WHEN (stat.a).stakind3 = 2 THEN (stat.a).stavalues3
|
|
|
|
WHEN (stat.a).stakind4 = 2 THEN (stat.a).stavalues4
|
|
|
|
WHEN (stat.a).stakind5 = 2 THEN (stat.a).stavalues5
|
|
|
|
END) AS histogram_bounds,
|
|
|
|
(CASE
|
|
|
|
WHEN (stat.a).stakind1 = 3 THEN (stat.a).stanumbers1[1]
|
|
|
|
WHEN (stat.a).stakind2 = 3 THEN (stat.a).stanumbers2[1]
|
|
|
|
WHEN (stat.a).stakind3 = 3 THEN (stat.a).stanumbers3[1]
|
|
|
|
WHEN (stat.a).stakind4 = 3 THEN (stat.a).stanumbers4[1]
|
|
|
|
WHEN (stat.a).stakind5 = 3 THEN (stat.a).stanumbers5[1]
|
|
|
|
END) correlation,
|
|
|
|
(CASE
|
|
|
|
WHEN (stat.a).stakind1 = 4 THEN (stat.a).stavalues1
|
|
|
|
WHEN (stat.a).stakind2 = 4 THEN (stat.a).stavalues2
|
|
|
|
WHEN (stat.a).stakind3 = 4 THEN (stat.a).stavalues3
|
|
|
|
WHEN (stat.a).stakind4 = 4 THEN (stat.a).stavalues4
|
|
|
|
WHEN (stat.a).stakind5 = 4 THEN (stat.a).stavalues5
|
|
|
|
END) AS most_common_elems,
|
|
|
|
(CASE
|
|
|
|
WHEN (stat.a).stakind1 = 4 THEN (stat.a).stanumbers1
|
|
|
|
WHEN (stat.a).stakind2 = 4 THEN (stat.a).stanumbers2
|
|
|
|
WHEN (stat.a).stakind3 = 4 THEN (stat.a).stanumbers3
|
|
|
|
WHEN (stat.a).stakind4 = 4 THEN (stat.a).stanumbers4
|
|
|
|
WHEN (stat.a).stakind5 = 4 THEN (stat.a).stanumbers5
|
|
|
|
END) AS most_common_elem_freqs,
|
|
|
|
(CASE
|
|
|
|
WHEN (stat.a).stakind1 = 5 THEN (stat.a).stanumbers1
|
|
|
|
WHEN (stat.a).stakind2 = 5 THEN (stat.a).stanumbers2
|
|
|
|
WHEN (stat.a).stakind3 = 5 THEN (stat.a).stanumbers3
|
|
|
|
WHEN (stat.a).stakind4 = 5 THEN (stat.a).stanumbers4
|
|
|
|
WHEN (stat.a).stakind5 = 5 THEN (stat.a).stanumbers5
|
|
|
|
END) AS elem_count_histogram
|
|
|
|
FROM pg_statistic_ext s JOIN pg_class c ON (c.oid = s.stxrelid)
|
|
|
|
LEFT JOIN pg_statistic_ext_data sd ON (s.oid = sd.stxoid)
|
|
|
|
LEFT JOIN pg_namespace cn ON (cn.oid = c.relnamespace)
|
|
|
|
LEFT JOIN pg_namespace sn ON (sn.oid = s.stxnamespace)
|
|
|
|
JOIN LATERAL (
|
|
|
|
SELECT unnest(pg_get_statisticsobjdef_expressions(s.oid)) AS expr,
|
|
|
|
unnest(sd.stxdexpr)::pg_statistic AS a
|
|
|
|
) stat ON (stat.expr IS NOT NULL);
|
|
|
|
|
2019-06-16 17:00:23 +02:00
|
|
|
-- unprivileged users may read pg_statistic_ext but not pg_statistic_ext_data
|
2021-03-27 10:17:12 +01:00
|
|
|
REVOKE ALL ON pg_statistic_ext_data FROM public;
|
2019-06-13 17:25:04 +02:00
|
|
|
|
2017-01-19 18:00:00 +01:00
|
|
|
CREATE VIEW pg_publication_tables AS
|
|
|
|
SELECT
|
|
|
|
P.pubname AS pubname,
|
|
|
|
N.nspname AS schemaname,
|
2022-05-19 04:50:55 +02:00
|
|
|
C.relname AS tablename,
|
|
|
|
( SELECT array_agg(a.attname ORDER BY a.attnum)
|
2022-09-07 00:00:32 +02:00
|
|
|
FROM pg_attribute a
|
2023-01-13 10:19:23 +01:00
|
|
|
WHERE a.attrelid = GPT.relid AND
|
|
|
|
a.attnum = ANY(GPT.attrs)
|
2022-05-19 04:50:55 +02:00
|
|
|
) AS attnames,
|
|
|
|
pg_get_expr(GPT.qual, GPT.relid) AS rowfilter
|
2019-05-22 17:46:57 +02:00
|
|
|
FROM pg_publication P,
|
|
|
|
LATERAL pg_get_publication_tables(P.pubname) GPT,
|
|
|
|
pg_class C JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
|
|
|
WHERE C.oid = GPT.relid;
|
2017-01-19 18:00:00 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_locks AS
|
2008-09-21 21:38:56 +02:00
|
|
|
SELECT * FROM pg_lock_status() AS L;
|
2005-06-18 00:32:51 +02:00
|
|
|
|
2006-01-18 07:49:30 +01:00
|
|
|
CREATE VIEW pg_cursors AS
|
2008-09-21 21:38:56 +02:00
|
|
|
SELECT * FROM pg_cursor() AS C;
|
2006-01-18 07:49:30 +01:00
|
|
|
|
2011-02-08 22:08:41 +01:00
|
|
|
CREATE VIEW pg_available_extensions AS
|
2011-02-14 22:07:00 +01:00
|
|
|
SELECT E.name, E.default_version, X.extversion AS installed_version,
|
|
|
|
E.comment
|
2011-02-08 22:08:41 +01:00
|
|
|
FROM pg_available_extensions() AS E
|
2011-02-14 22:07:00 +01:00
|
|
|
LEFT JOIN pg_extension AS X ON E.name = X.extname;
|
|
|
|
|
|
|
|
CREATE VIEW pg_available_extension_versions AS
|
|
|
|
SELECT E.name, E.version, (X.extname IS NOT NULL) AS installed,
|
Invent "trusted" extensions, and remove the pg_pltemplate catalog.
This patch creates a new extension property, "trusted". An extension
that's marked that way in its control file can be installed by a
non-superuser who has the CREATE privilege on the current database,
even if the extension contains objects that normally would have to be
created by a superuser. The objects within the extension will (by
default) be owned by the bootstrap superuser, but the extension itself
will be owned by the calling user. This allows replicating the old
behavior around trusted procedural languages, without all the
special-case logic in CREATE LANGUAGE. We have, however, chosen to
loosen the rules slightly: formerly, only a database owner could take
advantage of the special case that allowed installation of a trusted
language, but now anyone who has CREATE privilege can do so.
Having done that, we can delete the pg_pltemplate catalog, moving the
knowledge it contained into the extension script files for the various
PLs. This ends up being no change at all for the in-core PLs, but it is
a large step forward for external PLs: they can now have the same ease
of installation as core PLs do. The old "trusted PL" behavior was only
available to PLs that had entries in pg_pltemplate, but now any
extension can be marked trusted if appropriate.
This also removes one of the stumbling blocks for our Python 2 -> 3
migration, since the association of "plpythonu" with Python 2 is no
longer hard-wired into pg_pltemplate's initial contents. Exactly where
we go from here on that front remains to be settled, but one problem
is fixed.
Patch by me, reviewed by Peter Eisentraut, Stephen Frost, and others.
Discussion: https://postgr.es/m/5889.1566415762@sss.pgh.pa.us
2020-01-30 00:42:43 +01:00
|
|
|
E.superuser, E.trusted, E.relocatable,
|
|
|
|
E.schema, E.requires, E.comment
|
2011-02-14 22:07:00 +01:00
|
|
|
FROM pg_available_extension_versions() AS E
|
|
|
|
LEFT JOIN pg_extension AS X
|
|
|
|
ON E.name = X.extname AND E.version = X.extversion;
|
2011-02-08 22:08:41 +01:00
|
|
|
|
2005-06-18 00:32:51 +02:00
|
|
|
CREATE VIEW pg_prepared_xacts AS
|
2005-06-18 21:33:42 +02:00
|
|
|
SELECT P.transaction, P.gid, P.prepared,
|
2005-06-28 07:09:14 +02:00
|
|
|
U.rolname AS owner, D.datname AS database
|
2005-06-18 00:32:51 +02:00
|
|
|
FROM pg_prepared_xact() AS P
|
2005-06-28 07:09:14 +02:00
|
|
|
LEFT JOIN pg_authid U ON P.ownerid = U.oid
|
2005-06-18 21:33:42 +02:00
|
|
|
LEFT JOIN pg_database D ON P.dbid = D.oid;
|
2005-06-18 00:32:51 +02:00
|
|
|
|
2006-01-08 08:00:27 +01:00
|
|
|
CREATE VIEW pg_prepared_statements AS
|
2008-09-21 21:38:56 +02:00
|
|
|
SELECT * FROM pg_prepared_statement() AS P;
|
2006-01-08 08:00:27 +01:00
|
|
|
|
2010-09-28 02:55:27 +02:00
|
|
|
CREATE VIEW pg_seclabels AS
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
CASE WHEN rel.relkind IN ('r', 'p') THEN 'table'::text
|
|
|
|
WHEN rel.relkind = 'v' THEN 'view'::text
|
|
|
|
WHEN rel.relkind = 'm' THEN 'materialized view'::text
|
|
|
|
WHEN rel.relkind = 'S' THEN 'sequence'::text
|
|
|
|
WHEN rel.relkind = 'f' THEN 'foreign table'::text END AS objtype,
|
|
|
|
rel.relnamespace AS objnamespace,
|
|
|
|
CASE WHEN pg_table_is_visible(rel.oid)
|
|
|
|
THEN quote_ident(rel.relname)
|
|
|
|
ELSE quote_ident(nsp.nspname) || '.' || quote_ident(rel.relname)
|
|
|
|
END AS objname,
|
|
|
|
l.provider, l.label
|
2010-09-28 02:55:27 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_class rel ON l.classoid = rel.tableoid AND l.objoid = rel.oid
|
|
|
|
JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
|
2010-09-28 02:55:27 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid = 0
|
2010-09-28 02:55:27 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
'column'::text AS objtype,
|
|
|
|
rel.relnamespace AS objnamespace,
|
|
|
|
CASE WHEN pg_table_is_visible(rel.oid)
|
|
|
|
THEN quote_ident(rel.relname)
|
|
|
|
ELSE quote_ident(nsp.nspname) || '.' || quote_ident(rel.relname)
|
|
|
|
END || '.' || att.attname AS objname,
|
|
|
|
l.provider, l.label
|
2010-09-28 02:55:27 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_class rel ON l.classoid = rel.tableoid AND l.objoid = rel.oid
|
|
|
|
JOIN pg_attribute att
|
|
|
|
ON rel.oid = att.attrelid AND l.objsubid = att.attnum
|
|
|
|
JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
|
2010-09-28 02:55:27 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid != 0
|
2010-09-28 02:55:27 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
CASE pro.prokind
|
2018-03-02 14:57:38 +01:00
|
|
|
WHEN 'a' THEN 'aggregate'::text
|
|
|
|
WHEN 'f' THEN 'function'::text
|
|
|
|
WHEN 'p' THEN 'procedure'::text
|
|
|
|
WHEN 'w' THEN 'window'::text END AS objtype,
|
2019-04-09 14:37:37 +02:00
|
|
|
pro.pronamespace AS objnamespace,
|
|
|
|
CASE WHEN pg_function_is_visible(pro.oid)
|
|
|
|
THEN quote_ident(pro.proname)
|
|
|
|
ELSE quote_ident(nsp.nspname) || '.' || quote_ident(pro.proname)
|
|
|
|
END || '(' || pg_catalog.pg_get_function_arguments(pro.oid) || ')' AS objname,
|
|
|
|
l.provider, l.label
|
2010-09-28 02:55:27 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_proc pro ON l.classoid = pro.tableoid AND l.objoid = pro.oid
|
|
|
|
JOIN pg_namespace nsp ON pro.pronamespace = nsp.oid
|
2010-09-28 02:55:27 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid = 0
|
2010-09-28 02:55:27 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
CASE WHEN typ.typtype = 'd' THEN 'domain'::text
|
|
|
|
ELSE 'type'::text END AS objtype,
|
|
|
|
typ.typnamespace AS objnamespace,
|
|
|
|
CASE WHEN pg_type_is_visible(typ.oid)
|
|
|
|
THEN quote_ident(typ.typname)
|
|
|
|
ELSE quote_ident(nsp.nspname) || '.' || quote_ident(typ.typname)
|
|
|
|
END AS objname,
|
|
|
|
l.provider, l.label
|
2010-09-28 02:55:27 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_type typ ON l.classoid = typ.tableoid AND l.objoid = typ.oid
|
|
|
|
JOIN pg_namespace nsp ON typ.typnamespace = nsp.oid
|
2010-09-28 02:55:27 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid = 0
|
2010-09-28 02:55:27 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
'large object'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
l.objoid::text AS objname,
|
|
|
|
l.provider, l.label
|
2010-09-28 02:55:27 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_largeobject_metadata lom ON l.objoid = lom.oid
|
2010-09-28 02:55:27 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.classoid = 'pg_catalog.pg_largeobject'::regclass AND l.objsubid = 0
|
2010-09-28 02:55:27 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
'language'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
quote_ident(lan.lanname) AS objname,
|
|
|
|
l.provider, l.label
|
2010-09-28 02:55:27 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_language lan ON l.classoid = lan.tableoid AND l.objoid = lan.oid
|
2010-09-28 02:55:27 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid = 0
|
2010-09-28 02:55:27 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
'schema'::text AS objtype,
|
|
|
|
nsp.oid AS objnamespace,
|
|
|
|
quote_ident(nsp.nspname) AS objname,
|
|
|
|
l.provider, l.label
|
2010-09-28 02:55:27 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_namespace nsp ON l.classoid = nsp.tableoid AND l.objoid = nsp.oid
|
2010-09-28 02:55:27 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid = 0
|
2011-07-20 19:18:24 +02:00
|
|
|
UNION ALL
|
2012-07-18 16:16:16 +02:00
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
'event trigger'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
quote_ident(evt.evtname) AS objname,
|
|
|
|
l.provider, l.label
|
2012-07-18 16:16:16 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_event_trigger evt ON l.classoid = evt.tableoid
|
|
|
|
AND l.objoid = evt.oid
|
2012-07-18 16:16:16 +02:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid = 0
|
2012-07-18 16:16:16 +02:00
|
|
|
UNION ALL
|
2017-03-25 04:25:24 +01:00
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, l.objsubid,
|
|
|
|
'publication'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
quote_ident(p.pubname) AS objname,
|
|
|
|
l.provider, l.label
|
2017-03-25 04:25:24 +01:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_seclabel l
|
|
|
|
JOIN pg_publication p ON l.classoid = p.tableoid AND l.objoid = p.oid
|
2017-03-25 04:25:24 +01:00
|
|
|
WHERE
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objsubid = 0
|
2017-03-25 04:25:24 +01:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, 0::int4 AS objsubid,
|
|
|
|
'subscription'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
quote_ident(s.subname) AS objname,
|
|
|
|
l.provider, l.label
|
2017-03-25 04:25:24 +01:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_shseclabel l
|
|
|
|
JOIN pg_subscription s ON l.classoid = s.tableoid AND l.objoid = s.oid
|
2017-03-25 04:25:24 +01:00
|
|
|
UNION ALL
|
2011-07-20 19:18:24 +02:00
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, 0::int4 AS objsubid,
|
|
|
|
'database'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
quote_ident(dat.datname) AS objname,
|
|
|
|
l.provider, l.label
|
2011-07-20 19:18:24 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_shseclabel l
|
|
|
|
JOIN pg_database dat ON l.classoid = dat.tableoid AND l.objoid = dat.oid
|
2011-07-20 19:18:24 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, 0::int4 AS objsubid,
|
|
|
|
'tablespace'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
quote_ident(spc.spcname) AS objname,
|
|
|
|
l.provider, l.label
|
2011-07-20 19:18:24 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_shseclabel l
|
|
|
|
JOIN pg_tablespace spc ON l.classoid = spc.tableoid AND l.objoid = spc.oid
|
2011-07-20 19:18:24 +02:00
|
|
|
UNION ALL
|
|
|
|
SELECT
|
2019-04-09 14:37:37 +02:00
|
|
|
l.objoid, l.classoid, 0::int4 AS objsubid,
|
|
|
|
'role'::text AS objtype,
|
|
|
|
NULL::oid AS objnamespace,
|
|
|
|
quote_ident(rol.rolname) AS objname,
|
|
|
|
l.provider, l.label
|
2011-07-20 19:18:24 +02:00
|
|
|
FROM
|
2019-04-09 14:37:37 +02:00
|
|
|
pg_shseclabel l
|
|
|
|
JOIN pg_authid rol ON l.classoid = rol.tableoid AND l.objoid = rol.oid;
|
2010-09-28 02:55:27 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_settings AS
|
|
|
|
SELECT * FROM pg_show_all_settings() AS A;
|
2005-06-18 00:32:51 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE RULE pg_settings_u AS
|
|
|
|
ON UPDATE TO pg_settings
|
|
|
|
WHERE new.name = old.name DO
|
2005-06-18 00:32:51 +02:00
|
|
|
SELECT set_config(old.name, new.setting, 'f');
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE RULE pg_settings_n AS
|
|
|
|
ON UPDATE TO pg_settings
|
2005-06-18 00:32:51 +02:00
|
|
|
DO INSTEAD NOTHING;
|
|
|
|
|
|
|
|
GRANT SELECT, UPDATE ON pg_settings TO PUBLIC;
|
|
|
|
|
2015-05-09 01:09:26 +02:00
|
|
|
CREATE VIEW pg_file_settings AS
|
|
|
|
SELECT * FROM pg_show_all_file_settings() AS A;
|
|
|
|
|
2021-03-27 10:17:12 +01:00
|
|
|
REVOKE ALL ON pg_file_settings FROM PUBLIC;
|
2015-05-09 01:09:26 +02:00
|
|
|
REVOKE EXECUTE ON FUNCTION pg_show_all_file_settings() FROM PUBLIC;
|
|
|
|
|
2017-01-31 00:00:26 +01:00
|
|
|
CREATE VIEW pg_hba_file_rules AS
|
|
|
|
SELECT * FROM pg_hba_file_rules() AS A;
|
|
|
|
|
2021-03-27 10:17:12 +01:00
|
|
|
REVOKE ALL ON pg_hba_file_rules FROM PUBLIC;
|
2017-01-31 00:00:26 +01:00
|
|
|
REVOKE EXECUTE ON FUNCTION pg_hba_file_rules() FROM PUBLIC;
|
|
|
|
|
2022-03-29 03:15:48 +02:00
|
|
|
CREATE VIEW pg_ident_file_mappings AS
|
|
|
|
SELECT * FROM pg_ident_file_mappings() AS A;
|
|
|
|
|
|
|
|
REVOKE ALL ON pg_ident_file_mappings FROM PUBLIC;
|
|
|
|
REVOKE EXECUTE ON FUNCTION pg_ident_file_mappings() FROM PUBLIC;
|
|
|
|
|
2006-09-16 22:14:34 +02:00
|
|
|
CREATE VIEW pg_timezone_abbrevs AS
|
|
|
|
SELECT * FROM pg_timezone_abbrevs();
|
|
|
|
|
|
|
|
CREATE VIEW pg_timezone_names AS
|
|
|
|
SELECT * FROM pg_timezone_names();
|
2006-07-25 05:51:23 +02:00
|
|
|
|
2016-02-17 18:12:06 +01:00
|
|
|
CREATE VIEW pg_config AS
|
|
|
|
SELECT * FROM pg_config();
|
|
|
|
|
2021-03-27 10:17:12 +01:00
|
|
|
REVOKE ALL ON pg_config FROM PUBLIC;
|
2016-02-17 18:12:06 +01:00
|
|
|
REVOKE EXECUTE ON FUNCTION pg_config() FROM PUBLIC;
|
|
|
|
|
2020-01-09 16:59:07 +01:00
|
|
|
CREATE VIEW pg_shmem_allocations AS
|
|
|
|
SELECT * FROM pg_get_shmem_allocations();
|
|
|
|
|
|
|
|
REVOKE ALL ON pg_shmem_allocations FROM PUBLIC;
|
2021-10-27 21:37:09 +02:00
|
|
|
GRANT SELECT ON pg_shmem_allocations TO pg_read_all_stats;
|
2020-01-09 16:59:07 +01:00
|
|
|
REVOKE EXECUTE ON FUNCTION pg_get_shmem_allocations() FROM PUBLIC;
|
2021-10-27 21:37:09 +02:00
|
|
|
GRANT EXECUTE ON FUNCTION pg_get_shmem_allocations() TO pg_read_all_stats;
|
2020-01-09 16:59:07 +01:00
|
|
|
|
2020-08-19 08:34:43 +02:00
|
|
|
CREATE VIEW pg_backend_memory_contexts AS
|
|
|
|
SELECT * FROM pg_get_backend_memory_contexts();
|
|
|
|
|
2020-08-26 03:50:02 +02:00
|
|
|
REVOKE ALL ON pg_backend_memory_contexts FROM PUBLIC;
|
2021-10-27 21:37:09 +02:00
|
|
|
GRANT SELECT ON pg_backend_memory_contexts TO pg_read_all_stats;
|
2020-08-26 03:50:02 +02:00
|
|
|
REVOKE EXECUTE ON FUNCTION pg_get_backend_memory_contexts() FROM PUBLIC;
|
2021-10-27 21:37:09 +02:00
|
|
|
GRANT EXECUTE ON FUNCTION pg_get_backend_memory_contexts() TO pg_read_all_stats;
|
2020-08-26 03:50:02 +02:00
|
|
|
|
2005-06-18 00:32:51 +02:00
|
|
|
-- Statistics views
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_all_tables AS
|
|
|
|
SELECT
|
|
|
|
C.oid AS relid,
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS relname,
|
|
|
|
pg_stat_get_numscans(C.oid) AS seq_scan,
|
2022-10-14 20:11:34 +02:00
|
|
|
pg_stat_get_lastscan(C.oid) AS last_seq_scan,
|
2010-11-23 21:27:50 +01:00
|
|
|
pg_stat_get_tuples_returned(C.oid) AS seq_tup_read,
|
|
|
|
sum(pg_stat_get_numscans(I.indexrelid))::bigint AS idx_scan,
|
2022-10-14 20:11:34 +02:00
|
|
|
max(pg_stat_get_lastscan(I.indexrelid)) AS last_idx_scan,
|
2005-10-06 04:29:23 +02:00
|
|
|
sum(pg_stat_get_tuples_fetched(I.indexrelid))::bigint +
|
2010-11-23 21:27:50 +01:00
|
|
|
pg_stat_get_tuples_fetched(C.oid) AS idx_tup_fetch,
|
|
|
|
pg_stat_get_tuples_inserted(C.oid) AS n_tup_ins,
|
|
|
|
pg_stat_get_tuples_updated(C.oid) AS n_tup_upd,
|
2006-11-24 22:18:42 +01:00
|
|
|
pg_stat_get_tuples_deleted(C.oid) AS n_tup_del,
|
2007-09-20 19:56:33 +02:00
|
|
|
pg_stat_get_tuples_hot_updated(C.oid) AS n_tup_hot_upd,
|
2023-03-23 19:16:17 +01:00
|
|
|
pg_stat_get_tuples_newpage_updated(C.oid) AS n_tup_newpage_upd,
|
2010-11-23 21:27:50 +01:00
|
|
|
pg_stat_get_live_tuples(C.oid) AS n_live_tup,
|
2007-01-02 21:59:32 +01:00
|
|
|
pg_stat_get_dead_tuples(C.oid) AS n_dead_tup,
|
2013-07-05 15:02:09 +02:00
|
|
|
pg_stat_get_mod_since_analyze(C.oid) AS n_mod_since_analyze,
|
Trigger autovacuum based on number of INSERTs
Traditionally autovacuum has only ever invoked a worker based on the
estimated number of dead tuples in a table and for anti-wraparound
purposes. For the latter, with certain classes of tables such as
insert-only tables, anti-wraparound vacuums could be the first vacuum that
the table ever receives. This could often lead to autovacuum workers being
busy for extended periods of time due to having to potentially freeze
every page in the table. This could be particularly bad for very large
tables. New clusters, or recently pg_restored clusters could suffer even
more as many large tables may have the same relfrozenxid, which could
result in large numbers of tables requiring an anti-wraparound vacuum all
at once.
Here we aim to reduce the work required by anti-wraparound and aggressive
vacuums in general, by triggering autovacuum when the table has received
enough INSERTs. This is controlled by adding two new GUCs and reloptions;
autovacuum_vacuum_insert_threshold and
autovacuum_vacuum_insert_scale_factor. These work exactly the same as the
existing scale factor and threshold controls, only base themselves off the
number of inserts since the last vacuum, rather than the number of dead
tuples. New controls were added rather than reusing the existing
controls, to allow these new vacuums to be tuned independently and perhaps
even completely disabled altogether, which can be done by setting
autovacuum_vacuum_insert_threshold to -1.
We make no attempt to skip index cleanup operations on these vacuums as
they may trigger for an insert-mostly table which continually doesn't have
enough dead tuples to trigger an autovacuum for the purpose of removing
those dead tuples. If we were to skip cleaning the indexes in this case,
then it is possible for the index(es) to become bloated over time.
There are additional benefits to triggering autovacuums based on inserts,
as tables which never contain enough dead tuples to trigger an autovacuum
are now more likely to receive a vacuum, which can mark more of the table
as "allvisible" and encourage the query planner to make use of Index Only
Scans.
Currently, we still obey vacuum_freeze_min_age when triggering these new
autovacuums based on INSERTs. For large insert-only tables, it may be
beneficial to lower the table's autovacuum_freeze_min_age so that tuples
are eligible to be frozen sooner. Here we've opted not to zero that for
these types of vacuums, since the table may just be insert-mostly and we
may otherwise freeze tuples that are still destined to be updated or
removed in the near future.
There was some debate to what exactly the new scale factor and threshold
should default to. For now, these are set to 0.2 and 1000, respectively.
There may be some motivation to adjust these before the release.
Author: Laurenz Albe, Darafei Praliaskouski
Reviewed-by: Alvaro Herrera, Masahiko Sawada, Chris Travers, Andres Freund, Justin Pryzby
Discussion: https://postgr.es/m/CAC8Q8t%2Bj36G_bLF%3D%2B0iMo6jGNWnLnWb1tujXuJr-%2Bx8ZCCTqoQ%40mail.gmail.com
2020-03-28 07:20:12 +01:00
|
|
|
pg_stat_get_ins_since_vacuum(C.oid) AS n_ins_since_vacuum,
|
2006-11-24 22:18:42 +01:00
|
|
|
pg_stat_get_last_vacuum_time(C.oid) as last_vacuum,
|
|
|
|
pg_stat_get_last_autovacuum_time(C.oid) as last_autovacuum,
|
|
|
|
pg_stat_get_last_analyze_time(C.oid) as last_analyze,
|
2010-08-21 12:59:17 +02:00
|
|
|
pg_stat_get_last_autoanalyze_time(C.oid) as last_autoanalyze,
|
|
|
|
pg_stat_get_vacuum_count(C.oid) AS vacuum_count,
|
|
|
|
pg_stat_get_autovacuum_count(C.oid) AS autovacuum_count,
|
|
|
|
pg_stat_get_analyze_count(C.oid) AS analyze_count,
|
|
|
|
pg_stat_get_autoanalyze_count(C.oid) AS autoanalyze_count
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_class C LEFT JOIN
|
|
|
|
pg_index I ON C.oid = I.indrelid
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2021-04-08 07:19:36 +02:00
|
|
|
WHERE C.relkind IN ('r', 't', 'm', 'p')
|
2003-11-13 23:13:39 +01:00
|
|
|
GROUP BY C.oid, N.nspname, C.relname;
|
|
|
|
|
2010-08-08 18:27:06 +02:00
|
|
|
CREATE VIEW pg_stat_xact_all_tables AS
|
|
|
|
SELECT
|
|
|
|
C.oid AS relid,
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS relname,
|
|
|
|
pg_stat_get_xact_numscans(C.oid) AS seq_scan,
|
|
|
|
pg_stat_get_xact_tuples_returned(C.oid) AS seq_tup_read,
|
|
|
|
sum(pg_stat_get_xact_numscans(I.indexrelid))::bigint AS idx_scan,
|
|
|
|
sum(pg_stat_get_xact_tuples_fetched(I.indexrelid))::bigint +
|
|
|
|
pg_stat_get_xact_tuples_fetched(C.oid) AS idx_tup_fetch,
|
|
|
|
pg_stat_get_xact_tuples_inserted(C.oid) AS n_tup_ins,
|
|
|
|
pg_stat_get_xact_tuples_updated(C.oid) AS n_tup_upd,
|
|
|
|
pg_stat_get_xact_tuples_deleted(C.oid) AS n_tup_del,
|
2023-03-23 19:16:17 +01:00
|
|
|
pg_stat_get_xact_tuples_hot_updated(C.oid) AS n_tup_hot_upd,
|
|
|
|
pg_stat_get_xact_tuples_newpage_updated(C.oid) AS n_tup_newpage_upd
|
2010-08-08 18:27:06 +02:00
|
|
|
FROM pg_class C LEFT JOIN
|
|
|
|
pg_index I ON C.oid = I.indrelid
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2021-04-08 07:19:36 +02:00
|
|
|
WHERE C.relkind IN ('r', 't', 'm', 'p')
|
2010-08-08 18:27:06 +02:00
|
|
|
GROUP BY C.oid, N.nspname, C.relname;
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_sys_tables AS
|
|
|
|
SELECT * FROM pg_stat_all_tables
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname IN ('pg_catalog', 'information_schema') OR
|
|
|
|
schemaname ~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-08-08 18:27:06 +02:00
|
|
|
CREATE VIEW pg_stat_xact_sys_tables AS
|
|
|
|
SELECT * FROM pg_stat_xact_all_tables
|
|
|
|
WHERE schemaname IN ('pg_catalog', 'information_schema') OR
|
|
|
|
schemaname ~ '^pg_toast';
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_user_tables AS
|
|
|
|
SELECT * FROM pg_stat_all_tables
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
|
|
|
|
schemaname !~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-08-08 18:27:06 +02:00
|
|
|
CREATE VIEW pg_stat_xact_user_tables AS
|
|
|
|
SELECT * FROM pg_stat_xact_all_tables
|
|
|
|
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
|
|
|
|
schemaname !~ '^pg_toast';
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_all_tables AS
|
|
|
|
SELECT
|
|
|
|
C.oid AS relid,
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS relname,
|
|
|
|
pg_stat_get_blocks_fetched(C.oid) -
|
|
|
|
pg_stat_get_blocks_hit(C.oid) AS heap_blks_read,
|
|
|
|
pg_stat_get_blocks_hit(C.oid) AS heap_blks_hit,
|
2022-03-24 21:33:13 +01:00
|
|
|
I.idx_blks_read AS idx_blks_read,
|
|
|
|
I.idx_blks_hit AS idx_blks_hit,
|
2010-11-23 21:27:50 +01:00
|
|
|
pg_stat_get_blocks_fetched(T.oid) -
|
|
|
|
pg_stat_get_blocks_hit(T.oid) AS toast_blks_read,
|
|
|
|
pg_stat_get_blocks_hit(T.oid) AS toast_blks_hit,
|
2022-03-24 21:33:13 +01:00
|
|
|
X.idx_blks_read AS tidx_blks_read,
|
|
|
|
X.idx_blks_hit AS tidx_blks_hit
|
2010-11-23 21:27:50 +01:00
|
|
|
FROM pg_class C LEFT JOIN
|
2022-03-24 21:33:13 +01:00
|
|
|
pg_class T ON C.reltoastrelid = T.oid
|
2010-11-23 21:27:50 +01:00
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2022-03-24 21:33:13 +01:00
|
|
|
LEFT JOIN LATERAL (
|
|
|
|
SELECT sum(pg_stat_get_blocks_fetched(indexrelid) -
|
|
|
|
pg_stat_get_blocks_hit(indexrelid))::bigint
|
|
|
|
AS idx_blks_read,
|
|
|
|
sum(pg_stat_get_blocks_hit(indexrelid))::bigint
|
|
|
|
AS idx_blks_hit
|
|
|
|
FROM pg_index WHERE indrelid = C.oid ) I ON true
|
|
|
|
LEFT JOIN LATERAL (
|
|
|
|
SELECT sum(pg_stat_get_blocks_fetched(indexrelid) -
|
|
|
|
pg_stat_get_blocks_hit(indexrelid))::bigint
|
|
|
|
AS idx_blks_read,
|
|
|
|
sum(pg_stat_get_blocks_hit(indexrelid))::bigint
|
|
|
|
AS idx_blks_hit
|
|
|
|
FROM pg_index WHERE indrelid = T.oid ) X ON true
|
|
|
|
WHERE C.relkind IN ('r', 't', 'm');
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_sys_tables AS
|
|
|
|
SELECT * FROM pg_statio_all_tables
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname IN ('pg_catalog', 'information_schema') OR
|
|
|
|
schemaname ~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_user_tables AS
|
|
|
|
SELECT * FROM pg_statio_all_tables
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
|
|
|
|
schemaname !~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_all_indexes AS
|
|
|
|
SELECT
|
|
|
|
C.oid AS relid,
|
|
|
|
I.oid AS indexrelid,
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS relname,
|
|
|
|
I.relname AS indexrelname,
|
|
|
|
pg_stat_get_numscans(I.oid) AS idx_scan,
|
2022-10-14 20:11:34 +02:00
|
|
|
pg_stat_get_lastscan(I.oid) AS last_idx_scan,
|
2010-11-23 21:27:50 +01:00
|
|
|
pg_stat_get_tuples_returned(I.oid) AS idx_tup_read,
|
|
|
|
pg_stat_get_tuples_fetched(I.oid) AS idx_tup_fetch
|
|
|
|
FROM pg_class C JOIN
|
|
|
|
pg_index X ON C.oid = X.indrelid JOIN
|
|
|
|
pg_class I ON I.oid = X.indexrelid
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2013-03-04 01:23:31 +01:00
|
|
|
WHERE C.relkind IN ('r', 't', 'm');
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_sys_indexes AS
|
|
|
|
SELECT * FROM pg_stat_all_indexes
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname IN ('pg_catalog', 'information_schema') OR
|
|
|
|
schemaname ~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_user_indexes AS
|
|
|
|
SELECT * FROM pg_stat_all_indexes
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
|
|
|
|
schemaname !~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_all_indexes AS
|
|
|
|
SELECT
|
|
|
|
C.oid AS relid,
|
|
|
|
I.oid AS indexrelid,
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS relname,
|
|
|
|
I.relname AS indexrelname,
|
|
|
|
pg_stat_get_blocks_fetched(I.oid) -
|
|
|
|
pg_stat_get_blocks_hit(I.oid) AS idx_blks_read,
|
|
|
|
pg_stat_get_blocks_hit(I.oid) AS idx_blks_hit
|
|
|
|
FROM pg_class C JOIN
|
|
|
|
pg_index X ON C.oid = X.indrelid JOIN
|
|
|
|
pg_class I ON I.oid = X.indexrelid
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2013-03-04 01:23:31 +01:00
|
|
|
WHERE C.relkind IN ('r', 't', 'm');
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_sys_indexes AS
|
|
|
|
SELECT * FROM pg_statio_all_indexes
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname IN ('pg_catalog', 'information_schema') OR
|
|
|
|
schemaname ~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_user_indexes AS
|
|
|
|
SELECT * FROM pg_statio_all_indexes
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
|
|
|
|
schemaname !~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_all_sequences AS
|
|
|
|
SELECT
|
|
|
|
C.oid AS relid,
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
C.relname AS relname,
|
|
|
|
pg_stat_get_blocks_fetched(C.oid) -
|
|
|
|
pg_stat_get_blocks_hit(C.oid) AS blks_read,
|
|
|
|
pg_stat_get_blocks_hit(C.oid) AS blks_hit
|
|
|
|
FROM pg_class C
|
|
|
|
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
2003-11-13 23:13:39 +01:00
|
|
|
WHERE C.relkind = 'S';
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_sys_sequences AS
|
|
|
|
SELECT * FROM pg_statio_all_sequences
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname IN ('pg_catalog', 'information_schema') OR
|
|
|
|
schemaname ~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_statio_user_sequences AS
|
|
|
|
SELECT * FROM pg_statio_all_sequences
|
2007-07-26 00:16:18 +02:00
|
|
|
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
|
|
|
|
schemaname !~ '^pg_toast';
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_activity AS
|
|
|
|
SELECT
|
2008-05-07 16:41:56 +02:00
|
|
|
S.datid AS datid,
|
|
|
|
D.datname AS datname,
|
2012-01-19 14:19:20 +01:00
|
|
|
S.pid,
|
2020-02-06 01:18:06 +01:00
|
|
|
S.leader_pid,
|
2008-05-07 16:41:56 +02:00
|
|
|
S.usesysid,
|
|
|
|
U.rolname AS usename,
|
2009-11-29 19:14:32 +01:00
|
|
|
S.application_name,
|
2010-04-26 16:22:37 +02:00
|
|
|
S.client_addr,
|
2011-02-17 22:03:28 +01:00
|
|
|
S.client_hostname,
|
2010-04-26 16:22:37 +02:00
|
|
|
S.client_port,
|
|
|
|
S.backend_start,
|
2008-05-07 16:41:56 +02:00
|
|
|
S.xact_start,
|
|
|
|
S.query_start,
|
2012-01-19 14:19:20 +01:00
|
|
|
S.state_change,
|
2016-03-10 18:44:09 +01:00
|
|
|
S.wait_event_type,
|
|
|
|
S.wait_event,
|
2012-01-19 14:19:20 +01:00
|
|
|
S.state,
|
2014-02-25 18:34:04 +01:00
|
|
|
S.backend_xid,
|
|
|
|
s.backend_xmin,
|
2021-04-20 18:22:26 +02:00
|
|
|
S.query_id,
|
2017-03-27 04:02:22 +02:00
|
|
|
S.query,
|
|
|
|
S.backend_type
|
2016-08-19 23:13:47 +02:00
|
|
|
FROM pg_stat_get_activity(NULL) AS S
|
|
|
|
LEFT JOIN pg_database AS D ON (S.datid = D.oid)
|
|
|
|
LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid);
|
2003-11-13 23:13:39 +01:00
|
|
|
|
2011-01-07 12:35:38 +01:00
|
|
|
CREATE VIEW pg_stat_replication AS
|
|
|
|
SELECT
|
2012-01-19 14:19:20 +01:00
|
|
|
S.pid,
|
2011-01-07 12:35:38 +01:00
|
|
|
S.usesysid,
|
|
|
|
U.rolname AS usename,
|
|
|
|
S.application_name,
|
|
|
|
S.client_addr,
|
2011-02-17 22:03:28 +01:00
|
|
|
S.client_hostname,
|
2011-01-07 12:35:38 +01:00
|
|
|
S.client_port,
|
|
|
|
S.backend_start,
|
2014-02-25 18:34:04 +01:00
|
|
|
S.backend_xmin,
|
2011-01-11 21:25:28 +01:00
|
|
|
W.state,
|
2017-05-11 17:49:59 +02:00
|
|
|
W.sent_lsn,
|
|
|
|
W.write_lsn,
|
|
|
|
W.flush_lsn,
|
|
|
|
W.replay_lsn,
|
2017-03-23 15:05:28 +01:00
|
|
|
W.write_lag,
|
|
|
|
W.flush_lag,
|
|
|
|
W.replay_lag,
|
2011-03-06 23:49:16 +01:00
|
|
|
W.sync_priority,
|
2018-12-09 08:35:06 +01:00
|
|
|
W.sync_state,
|
2020-07-13 04:36:05 +02:00
|
|
|
W.reply_time
|
2016-08-19 23:13:47 +02:00
|
|
|
FROM pg_stat_get_activity(NULL) AS S
|
|
|
|
JOIN pg_stat_get_wal_senders() AS W ON (S.pid = W.pid)
|
|
|
|
LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid);
|
2011-01-07 12:35:38 +01:00
|
|
|
|
Collect statistics about SLRU caches
There's a number of SLRU caches used to access important data like clog,
commit timestamps, multixact, asynchronous notifications, etc. Until now
we had no easy way to monitor these shared caches, compute hit ratios,
number of reads/writes etc.
This commit extends the statistics collector to track this information
for a predefined list of SLRUs, and also introduces a new system view
pg_stat_slru displaying the data.
The list of built-in SLRUs is fixed, but additional SLRUs may be defined
in extensions. Unfortunately, there's no suitable registry of SLRUs, so
this patch simply defines a fixed list of SLRUs with entries for the
built-in ones and one entry for all additional SLRUs. Extensions adding
their own SLRU are fairly rare, so this seems acceptable.
This patch only allows monitoring of SLRUs, not tuning. The SLRU sizes
are still fixed (hard-coded in the code) and it's not entirely clear
which of the SLRUs might need a GUC to tune size. In a way, allowing us
to determine that is one of the goals of this patch.
Bump catversion as the patch introduces new functions and system view.
Author: Tomas Vondra
Reviewed-by: Alvaro Herrera
Discussion: https://www.postgresql.org/message-id/flat/20200119143707.gyinppnigokesjok@development
2020-04-02 02:11:38 +02:00
|
|
|
CREATE VIEW pg_stat_slru AS
|
|
|
|
SELECT
|
|
|
|
s.name,
|
|
|
|
s.blks_zeroed,
|
|
|
|
s.blks_hit,
|
|
|
|
s.blks_read,
|
|
|
|
s.blks_written,
|
|
|
|
s.blks_exists,
|
|
|
|
s.flushes,
|
|
|
|
s.truncates,
|
|
|
|
s.stats_reset
|
|
|
|
FROM pg_stat_get_slru() s;
|
|
|
|
|
2016-01-07 20:21:19 +01:00
|
|
|
CREATE VIEW pg_stat_wal_receiver AS
|
|
|
|
SELECT
|
|
|
|
s.pid,
|
|
|
|
s.status,
|
|
|
|
s.receive_start_lsn,
|
|
|
|
s.receive_start_tli,
|
2020-05-17 02:22:07 +02:00
|
|
|
s.written_lsn,
|
|
|
|
s.flushed_lsn,
|
2016-01-07 20:21:19 +01:00
|
|
|
s.received_tli,
|
|
|
|
s.last_msg_send_time,
|
|
|
|
s.last_msg_receipt_time,
|
|
|
|
s.latest_end_lsn,
|
|
|
|
s.latest_end_time,
|
2016-06-29 22:57:17 +02:00
|
|
|
s.slot_name,
|
2018-03-31 00:51:22 +02:00
|
|
|
s.sender_host,
|
|
|
|
s.sender_port,
|
2016-07-07 05:59:39 +02:00
|
|
|
s.conninfo
|
2016-01-07 20:21:19 +01:00
|
|
|
FROM pg_stat_get_wal_receiver() s
|
|
|
|
WHERE s.pid IS NOT NULL;
|
|
|
|
|
2022-04-07 09:28:40 +02:00
|
|
|
CREATE VIEW pg_stat_recovery_prefetch AS
|
|
|
|
SELECT
|
|
|
|
s.stats_reset,
|
|
|
|
s.prefetch,
|
|
|
|
s.hit,
|
|
|
|
s.skip_init,
|
|
|
|
s.skip_new,
|
|
|
|
s.skip_fpw,
|
|
|
|
s.skip_rep,
|
|
|
|
s.wal_distance,
|
|
|
|
s.block_distance,
|
|
|
|
s.io_depth
|
|
|
|
FROM pg_stat_get_recovery_prefetch() s;
|
|
|
|
|
2017-01-19 18:00:00 +01:00
|
|
|
CREATE VIEW pg_stat_subscription AS
|
|
|
|
SELECT
|
|
|
|
su.oid AS subid,
|
|
|
|
su.subname,
|
|
|
|
st.pid,
|
2023-01-18 04:33:12 +01:00
|
|
|
st.leader_pid,
|
2017-03-23 13:36:36 +01:00
|
|
|
st.relid,
|
2017-01-19 18:00:00 +01:00
|
|
|
st.received_lsn,
|
|
|
|
st.last_msg_send_time,
|
|
|
|
st.last_msg_receipt_time,
|
|
|
|
st.latest_end_lsn,
|
|
|
|
st.latest_end_time
|
|
|
|
FROM pg_subscription su
|
|
|
|
LEFT JOIN pg_stat_get_subscription(NULL) st
|
|
|
|
ON (st.subid = su.oid);
|
|
|
|
|
2015-04-12 19:07:46 +02:00
|
|
|
CREATE VIEW pg_stat_ssl AS
|
|
|
|
SELECT
|
|
|
|
S.pid,
|
|
|
|
S.ssl,
|
|
|
|
S.sslversion AS version,
|
|
|
|
S.sslcipher AS cipher,
|
|
|
|
S.sslbits AS bits,
|
2019-02-01 00:17:45 +01:00
|
|
|
S.ssl_client_dn AS client_dn,
|
|
|
|
S.ssl_client_serial AS client_serial,
|
|
|
|
S.ssl_issuer_dn AS issuer_dn
|
2019-11-12 21:19:41 +01:00
|
|
|
FROM pg_stat_get_activity(NULL) AS S
|
|
|
|
WHERE S.client_port IS NOT NULL;
|
2015-04-12 19:07:46 +02:00
|
|
|
|
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
|
|
|
CREATE VIEW pg_stat_gssapi AS
|
|
|
|
SELECT
|
|
|
|
S.pid,
|
|
|
|
S.gss_auth AS gss_authenticated,
|
|
|
|
S.gss_princ AS principal,
|
|
|
|
S.gss_enc AS encrypted
|
2019-11-12 21:19:41 +01:00
|
|
|
FROM pg_stat_get_activity(NULL) AS S
|
|
|
|
WHERE S.client_port IS NOT NULL;
|
GSSAPI encryption support
On both the frontend and backend, prepare for GSSAPI encryption
support by moving common code for error handling into a separate file.
Fix a TODO for handling multiple status messages in the process.
Eliminate the OIDs, which have not been needed for some time.
Add frontend and backend encryption support functions. Keep the
context initiation for authentication-only separate on both the
frontend and backend in order to avoid concerns about changing the
requested flags to include encryption support.
In postmaster, pull GSSAPI authorization checking into a shared
function. Also share the initiator name between the encryption and
non-encryption codepaths.
For HBA, add "hostgssenc" and "hostnogssenc" entries that behave
similarly to their SSL counterparts. "hostgssenc" requires either
"gss", "trust", or "reject" for its authentication.
Similarly, add a "gssencmode" parameter to libpq. Supported values are
"disable", "require", and "prefer". Notably, negotiation will only be
attempted if credentials can be acquired. Move credential acquisition
into its own function to support this behavior.
Add a simple pg_stat_gssapi view similar to pg_stat_ssl, for monitoring
if GSSAPI authentication was used, what principal was used, and if
encryption is being used on the connection.
Finally, add documentation for everything new, and update existing
documentation on connection security.
Thanks to Michael Paquier for the Windows fixes.
Author: Robbie Harwood, with changes to the read/write functions by me.
Reviewed in various forms and at different times by: Michael Paquier,
Andres Freund, David Steele.
Discussion: https://www.postgresql.org/message-id/flat/jlg1tgq1ktm.fsf@thriss.redhat.com
2019-04-03 21:02:33 +02:00
|
|
|
|
2014-02-01 04:45:17 +01:00
|
|
|
CREATE VIEW pg_replication_slots AS
|
|
|
|
SELECT
|
|
|
|
L.slot_name,
|
Introduce logical decoding.
This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables. The output format is controlled by a
so-called "output plugin"; an example is included. To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.
Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.
Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.
2014-03-03 22:32:18 +01:00
|
|
|
L.plugin,
|
2014-02-01 04:45:17 +01:00
|
|
|
L.slot_type,
|
|
|
|
L.datoid,
|
|
|
|
D.datname AS database,
|
2016-12-08 18:00:00 +01:00
|
|
|
L.temporary,
|
2014-02-01 04:45:17 +01:00
|
|
|
L.active,
|
2015-04-22 09:42:36 +02:00
|
|
|
L.active_pid,
|
2014-02-01 04:45:17 +01:00
|
|
|
L.xmin,
|
Introduce logical decoding.
This feature, building on previous commits, allows the write-ahead log
stream to be decoded into a series of logical changes; that is,
inserts, updates, and deletes and the transactions which contain them.
It is capable of handling decoding even across changes to the schema
of the effected tables. The output format is controlled by a
so-called "output plugin"; an example is included. To make use of
this in a real replication system, the output plugin will need to be
modified to produce output in the format appropriate to that system,
and to perform filtering.
Currently, information can be extracted from the logical decoding
system only via SQL; future commits will add the ability to stream
changes via walsender.
Andres Freund, with review and other contributions from many other
people, including Álvaro Herrera, Abhijit Menon-Sen, Peter Gheogegan,
Kevin Grittner, Robert Haas, Heikki Linnakangas, Fujii Masao, Abhijit
Menon-Sen, Michael Paquier, Simon Riggs, Craig Ringer, and Steve
Singer.
2014-03-03 22:32:18 +01:00
|
|
|
L.catalog_xmin,
|
2015-08-10 13:28:18 +02:00
|
|
|
L.restart_lsn,
|
2020-04-08 00:35:00 +02:00
|
|
|
L.confirmed_flush_lsn,
|
|
|
|
L.wal_status,
|
2021-03-03 02:58:43 +01:00
|
|
|
L.safe_wal_size,
|
|
|
|
L.two_phase
|
2014-02-01 04:45:17 +01:00
|
|
|
FROM pg_get_replication_slots() AS L
|
|
|
|
LEFT JOIN pg_database D ON (L.datoid = D.oid);
|
|
|
|
|
2021-04-27 05:39:11 +02:00
|
|
|
CREATE VIEW pg_stat_replication_slots AS
|
|
|
|
SELECT
|
|
|
|
s.slot_name,
|
|
|
|
s.spill_txns,
|
|
|
|
s.spill_count,
|
|
|
|
s.spill_bytes,
|
|
|
|
s.stream_txns,
|
|
|
|
s.stream_count,
|
|
|
|
s.stream_bytes,
|
|
|
|
s.total_txns,
|
|
|
|
s.total_bytes,
|
|
|
|
s.stats_reset
|
|
|
|
FROM pg_replication_slots as r,
|
|
|
|
LATERAL pg_stat_get_replication_slot(slot_name) as s
|
|
|
|
WHERE r.datoid IS NOT NULL; -- excluding physical slots
|
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_database AS
|
|
|
|
SELECT
|
|
|
|
D.oid AS datid,
|
|
|
|
D.datname AS datname,
|
2019-04-12 14:04:50 +02:00
|
|
|
CASE
|
2019-04-17 13:51:48 +02:00
|
|
|
WHEN (D.oid = (0)::oid) THEN 0
|
2019-04-12 14:04:50 +02:00
|
|
|
ELSE pg_stat_get_db_numbackends(D.oid)
|
|
|
|
END AS numbackends,
|
2010-11-23 21:27:50 +01:00
|
|
|
pg_stat_get_db_xact_commit(D.oid) AS xact_commit,
|
|
|
|
pg_stat_get_db_xact_rollback(D.oid) AS xact_rollback,
|
|
|
|
pg_stat_get_db_blocks_fetched(D.oid) -
|
|
|
|
pg_stat_get_db_blocks_hit(D.oid) AS blks_read,
|
2007-03-16 18:57:36 +01:00
|
|
|
pg_stat_get_db_blocks_hit(D.oid) AS blks_hit,
|
|
|
|
pg_stat_get_db_tuples_returned(D.oid) AS tup_returned,
|
|
|
|
pg_stat_get_db_tuples_fetched(D.oid) AS tup_fetched,
|
|
|
|
pg_stat_get_db_tuples_inserted(D.oid) AS tup_inserted,
|
|
|
|
pg_stat_get_db_tuples_updated(D.oid) AS tup_updated,
|
2011-01-03 12:46:03 +01:00
|
|
|
pg_stat_get_db_tuples_deleted(D.oid) AS tup_deleted,
|
2011-02-10 15:09:35 +01:00
|
|
|
pg_stat_get_db_conflict_all(D.oid) AS conflicts,
|
2012-01-26 14:41:19 +01:00
|
|
|
pg_stat_get_db_temp_files(D.oid) AS temp_files,
|
|
|
|
pg_stat_get_db_temp_bytes(D.oid) AS temp_bytes,
|
2012-01-26 15:58:19 +01:00
|
|
|
pg_stat_get_db_deadlocks(D.oid) AS deadlocks,
|
2019-03-09 19:45:17 +01:00
|
|
|
pg_stat_get_db_checksum_failures(D.oid) AS checksum_failures,
|
2019-04-12 14:04:50 +02:00
|
|
|
pg_stat_get_db_checksum_last_failure(D.oid) AS checksum_last_failure,
|
2012-04-30 20:02:47 +02:00
|
|
|
pg_stat_get_db_blk_read_time(D.oid) AS blk_read_time,
|
|
|
|
pg_stat_get_db_blk_write_time(D.oid) AS blk_write_time,
|
2021-01-17 13:34:09 +01:00
|
|
|
pg_stat_get_db_session_time(D.oid) AS session_time,
|
|
|
|
pg_stat_get_db_active_time(D.oid) AS active_time,
|
|
|
|
pg_stat_get_db_idle_in_transaction_time(D.oid) AS idle_in_transaction_time,
|
|
|
|
pg_stat_get_db_sessions(D.oid) AS sessions,
|
|
|
|
pg_stat_get_db_sessions_abandoned(D.oid) AS sessions_abandoned,
|
|
|
|
pg_stat_get_db_sessions_fatal(D.oid) AS sessions_fatal,
|
|
|
|
pg_stat_get_db_sessions_killed(D.oid) AS sessions_killed,
|
2011-02-10 15:09:35 +01:00
|
|
|
pg_stat_get_db_stat_reset_time(D.oid) AS stats_reset
|
2019-04-12 14:04:50 +02:00
|
|
|
FROM (
|
|
|
|
SELECT 0 AS oid, NULL::name AS datname
|
|
|
|
UNION ALL
|
|
|
|
SELECT oid, datname FROM pg_database
|
|
|
|
) D;
|
2011-01-03 12:46:03 +01:00
|
|
|
|
|
|
|
CREATE VIEW pg_stat_database_conflicts AS
|
|
|
|
SELECT
|
|
|
|
D.oid AS datid,
|
|
|
|
D.datname AS datname,
|
|
|
|
pg_stat_get_db_conflict_tablespace(D.oid) AS confl_tablespace,
|
|
|
|
pg_stat_get_db_conflict_lock(D.oid) AS confl_lock,
|
|
|
|
pg_stat_get_db_conflict_snapshot(D.oid) AS confl_snapshot,
|
|
|
|
pg_stat_get_db_conflict_bufferpin(D.oid) AS confl_bufferpin,
|
|
|
|
pg_stat_get_db_conflict_startup_deadlock(D.oid) AS confl_deadlock
|
2003-11-13 23:13:39 +01:00
|
|
|
FROM pg_database D;
|
2007-03-30 20:34:56 +02:00
|
|
|
|
2010-11-23 21:27:50 +01:00
|
|
|
CREATE VIEW pg_stat_user_functions AS
|
2008-05-15 02:17:41 +02:00
|
|
|
SELECT
|
2010-11-23 21:27:50 +01:00
|
|
|
P.oid AS funcid,
|
2008-05-15 02:17:41 +02:00
|
|
|
N.nspname AS schemaname,
|
|
|
|
P.proname AS funcname,
|
|
|
|
pg_stat_get_function_calls(P.oid) AS calls,
|
2012-04-30 20:02:47 +02:00
|
|
|
pg_stat_get_function_total_time(P.oid) AS total_time,
|
|
|
|
pg_stat_get_function_self_time(P.oid) AS self_time
|
2008-05-15 02:17:41 +02:00
|
|
|
FROM pg_proc P LEFT JOIN pg_namespace N ON (N.oid = P.pronamespace)
|
2010-11-23 21:27:50 +01:00
|
|
|
WHERE P.prolang != 12 -- fast check to eliminate built-in functions
|
2008-05-15 02:17:41 +02:00
|
|
|
AND pg_stat_get_function_calls(P.oid) IS NOT NULL;
|
|
|
|
|
2010-08-08 18:27:06 +02:00
|
|
|
CREATE VIEW pg_stat_xact_user_functions AS
|
|
|
|
SELECT
|
|
|
|
P.oid AS funcid,
|
|
|
|
N.nspname AS schemaname,
|
|
|
|
P.proname AS funcname,
|
|
|
|
pg_stat_get_xact_function_calls(P.oid) AS calls,
|
2012-04-30 20:02:47 +02:00
|
|
|
pg_stat_get_xact_function_total_time(P.oid) AS total_time,
|
|
|
|
pg_stat_get_xact_function_self_time(P.oid) AS self_time
|
2010-08-08 18:27:06 +02:00
|
|
|
FROM pg_proc P LEFT JOIN pg_namespace N ON (N.oid = P.pronamespace)
|
|
|
|
WHERE P.prolang != 12 -- fast check to eliminate built-in functions
|
|
|
|
AND pg_stat_get_xact_function_calls(P.oid) IS NOT NULL;
|
|
|
|
|
2014-01-28 18:58:22 +01:00
|
|
|
CREATE VIEW pg_stat_archiver AS
|
|
|
|
SELECT
|
|
|
|
s.archived_count,
|
|
|
|
s.last_archived_wal,
|
|
|
|
s.last_archived_time,
|
|
|
|
s.failed_count,
|
|
|
|
s.last_failed_wal,
|
|
|
|
s.last_failed_time,
|
|
|
|
s.stats_reset
|
|
|
|
FROM pg_stat_get_archiver() s;
|
|
|
|
|
2007-03-30 20:34:56 +02:00
|
|
|
CREATE VIEW pg_stat_bgwriter AS
|
2007-06-28 02:02:40 +02:00
|
|
|
SELECT
|
|
|
|
pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints_timed,
|
|
|
|
pg_stat_get_bgwriter_requested_checkpoints() AS checkpoints_req,
|
2012-04-05 20:03:21 +02:00
|
|
|
pg_stat_get_checkpoint_write_time() AS checkpoint_write_time,
|
2012-04-06 03:36:42 +02:00
|
|
|
pg_stat_get_checkpoint_sync_time() AS checkpoint_sync_time,
|
2007-06-28 02:02:40 +02:00
|
|
|
pg_stat_get_bgwriter_buf_written_checkpoints() AS buffers_checkpoint,
|
|
|
|
pg_stat_get_bgwriter_buf_written_clean() AS buffers_clean,
|
2007-09-25 22:03:38 +02:00
|
|
|
pg_stat_get_bgwriter_maxwritten_clean() AS maxwritten_clean,
|
|
|
|
pg_stat_get_buf_written_backend() AS buffers_backend,
|
2010-11-15 18:42:59 +01:00
|
|
|
pg_stat_get_buf_fsync_backend() AS buffers_backend_fsync,
|
2011-02-10 15:09:35 +01:00
|
|
|
pg_stat_get_buf_alloc() AS buffers_alloc,
|
|
|
|
pg_stat_get_bgwriter_stat_reset_time() AS stats_reset;
|
2007-08-21 03:11:32 +02:00
|
|
|
|
Add pg_stat_io view, providing more detailed IO statistics
Builds on 28e626bde00 and f30d62c2fc6. See the former for motivation.
Rows of the view show IO operations for a particular backend type, IO target
object, IO context combination (e.g. a client backend's operations on
permanent relations in shared buffers) and each column in the view is the
total number of IO Operations done (e.g. writes). So a cell in the view would
be, for example, the number of blocks of relation data written from shared
buffers by client backends since the last stats reset.
In anticipation of tracking WAL IO and non-block-oriented IO (such as
temporary file IO), the "op_bytes" column specifies the unit of the "reads",
"writes", and "extends" columns for a given row.
Rows for combinations of IO operation, backend type, target object and context
that never occur, are ommitted entirely. For example, checkpointer will never
operate on temporary relations.
Similarly, if an IO operation never occurs for such a combination, the IO
operation's cell will be null, to distinguish from 0 observed IO
operations. For example, bgwriter should not perform reads.
Note that some of the cells in the view are redundant with fields in
pg_stat_bgwriter (e.g. buffers_backend). For now, these have been kept for
backwards compatibility.
Bumps catversion.
Author: Melanie Plageman <melanieplageman@gmail.com>
Author: Samay Sharma <smilingsamay@gmail.com>
Reviewed-by: Maciek Sakrejda <m.sakrejda@gmail.com>
Reviewed-by: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/20200124195226.lth52iydq2n2uilq@alap3.anarazel.de
2023-02-11 18:51:58 +01:00
|
|
|
CREATE VIEW pg_stat_io AS
|
|
|
|
SELECT
|
|
|
|
b.backend_type,
|
|
|
|
b.io_object,
|
|
|
|
b.io_context,
|
|
|
|
b.reads,
|
|
|
|
b.writes,
|
|
|
|
b.extends,
|
|
|
|
b.op_bytes,
|
2023-03-31 04:22:40 +02:00
|
|
|
b.hits,
|
Add pg_stat_io view, providing more detailed IO statistics
Builds on 28e626bde00 and f30d62c2fc6. See the former for motivation.
Rows of the view show IO operations for a particular backend type, IO target
object, IO context combination (e.g. a client backend's operations on
permanent relations in shared buffers) and each column in the view is the
total number of IO Operations done (e.g. writes). So a cell in the view would
be, for example, the number of blocks of relation data written from shared
buffers by client backends since the last stats reset.
In anticipation of tracking WAL IO and non-block-oriented IO (such as
temporary file IO), the "op_bytes" column specifies the unit of the "reads",
"writes", and "extends" columns for a given row.
Rows for combinations of IO operation, backend type, target object and context
that never occur, are ommitted entirely. For example, checkpointer will never
operate on temporary relations.
Similarly, if an IO operation never occurs for such a combination, the IO
operation's cell will be null, to distinguish from 0 observed IO
operations. For example, bgwriter should not perform reads.
Note that some of the cells in the view are redundant with fields in
pg_stat_bgwriter (e.g. buffers_backend). For now, these have been kept for
backwards compatibility.
Bumps catversion.
Author: Melanie Plageman <melanieplageman@gmail.com>
Author: Samay Sharma <smilingsamay@gmail.com>
Reviewed-by: Maciek Sakrejda <m.sakrejda@gmail.com>
Reviewed-by: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/20200124195226.lth52iydq2n2uilq@alap3.anarazel.de
2023-02-11 18:51:58 +01:00
|
|
|
b.evictions,
|
|
|
|
b.reuses,
|
|
|
|
b.fsyncs,
|
|
|
|
b.stats_reset
|
|
|
|
FROM pg_stat_get_io() b;
|
|
|
|
|
2020-10-02 03:17:11 +02:00
|
|
|
CREATE VIEW pg_stat_wal AS
|
|
|
|
SELECT
|
2020-12-02 05:00:15 +01:00
|
|
|
w.wal_records,
|
|
|
|
w.wal_fpi,
|
|
|
|
w.wal_bytes,
|
2020-10-02 03:17:11 +02:00
|
|
|
w.wal_buffers_full,
|
Track total amounts of times spent writing and syncing WAL data to disk.
This commit adds new GUC track_wal_io_timing. When this is enabled,
the total amounts of time XLogWrite writes and issue_xlog_fsync syncs
WAL data to disk are counted in pg_stat_wal. This information would be
useful to check how much WAL write and sync affect the performance.
Enabling track_wal_io_timing will make the server query the operating
system for the current time every time WAL is written or synced,
which may cause significant overhead on some platforms. To avoid such
additional overhead in the server with track_io_timing enabled,
this commit introduces track_wal_io_timing as a separate parameter from
track_io_timing.
Note that WAL write and sync activity by walreceiver has not been tracked yet.
This commit makes the server also track the numbers of times XLogWrite
writes and issue_xlog_fsync syncs WAL data to disk, in pg_stat_wal,
regardless of the setting of track_wal_io_timing. This counters can be
used to calculate the WAL write and sync time per request, for example.
Bump PGSTAT_FILE_FORMAT_ID.
Bump catalog version.
Author: Masahiro Ikeda
Reviewed-By: Japin Li, Hayato Kuroda, Masahiko Sawada, David Johnston, Fujii Masao
Discussion: https://postgr.es/m/0509ad67b585a5b86a83d445dfa75392@oss.nttdata.com
2021-03-09 08:52:06 +01:00
|
|
|
w.wal_write,
|
|
|
|
w.wal_sync,
|
|
|
|
w.wal_write_time,
|
|
|
|
w.wal_sync_time,
|
2020-10-02 03:17:11 +02:00
|
|
|
w.stats_reset
|
|
|
|
FROM pg_stat_get_wal() w;
|
|
|
|
|
2020-01-15 15:02:09 +01:00
|
|
|
CREATE VIEW pg_stat_progress_analyze AS
|
|
|
|
SELECT
|
|
|
|
S.pid AS pid, S.datid AS datid, D.datname AS datname,
|
|
|
|
CAST(S.relid AS oid) AS relid,
|
|
|
|
CASE S.param1 WHEN 0 THEN 'initializing'
|
|
|
|
WHEN 1 THEN 'acquiring sample rows'
|
|
|
|
WHEN 2 THEN 'acquiring inherited sample rows'
|
|
|
|
WHEN 3 THEN 'computing statistics'
|
|
|
|
WHEN 4 THEN 'computing extended statistics'
|
|
|
|
WHEN 5 THEN 'finalizing analyze'
|
|
|
|
END AS phase,
|
|
|
|
S.param2 AS sample_blks_total,
|
|
|
|
S.param3 AS sample_blks_scanned,
|
|
|
|
S.param4 AS ext_stats_total,
|
|
|
|
S.param5 AS ext_stats_computed,
|
|
|
|
S.param6 AS child_tables_total,
|
|
|
|
S.param7 AS child_tables_done,
|
|
|
|
CAST(S.param8 AS oid) AS current_child_table_relid
|
|
|
|
FROM pg_stat_get_progress_info('ANALYZE') AS S
|
|
|
|
LEFT JOIN pg_database D ON S.datid = D.oid;
|
|
|
|
|
2016-03-15 18:31:18 +01:00
|
|
|
CREATE VIEW pg_stat_progress_vacuum AS
|
2019-04-09 14:37:37 +02:00
|
|
|
SELECT
|
|
|
|
S.pid AS pid, S.datid AS datid, D.datname AS datname,
|
|
|
|
S.relid AS relid,
|
|
|
|
CASE S.param1 WHEN 0 THEN 'initializing'
|
|
|
|
WHEN 1 THEN 'scanning heap'
|
|
|
|
WHEN 2 THEN 'vacuuming indexes'
|
|
|
|
WHEN 3 THEN 'vacuuming heap'
|
|
|
|
WHEN 4 THEN 'cleaning up indexes'
|
|
|
|
WHEN 5 THEN 'truncating heap'
|
|
|
|
WHEN 6 THEN 'performing final cleanup'
|
|
|
|
END AS phase,
|
|
|
|
S.param2 AS heap_blks_total, S.param3 AS heap_blks_scanned,
|
|
|
|
S.param4 AS heap_blks_vacuumed, S.param5 AS index_vacuum_count,
|
|
|
|
S.param6 AS max_dead_tuples, S.param7 AS num_dead_tuples
|
2016-03-15 18:31:18 +01:00
|
|
|
FROM pg_stat_get_progress_info('VACUUM') AS S
|
2019-04-09 14:37:37 +02:00
|
|
|
LEFT JOIN pg_database D ON S.datid = D.oid;
|
2016-03-15 18:31:18 +01:00
|
|
|
|
2019-03-25 15:59:04 +01:00
|
|
|
CREATE VIEW pg_stat_progress_cluster AS
|
|
|
|
SELECT
|
|
|
|
S.pid AS pid,
|
|
|
|
S.datid AS datid,
|
|
|
|
D.datname AS datname,
|
|
|
|
S.relid AS relid,
|
|
|
|
CASE S.param1 WHEN 1 THEN 'CLUSTER'
|
|
|
|
WHEN 2 THEN 'VACUUM FULL'
|
|
|
|
END AS command,
|
|
|
|
CASE S.param2 WHEN 0 THEN 'initializing'
|
|
|
|
WHEN 1 THEN 'seq scanning heap'
|
|
|
|
WHEN 2 THEN 'index scanning heap'
|
|
|
|
WHEN 3 THEN 'sorting tuples'
|
|
|
|
WHEN 4 THEN 'writing new heap'
|
|
|
|
WHEN 5 THEN 'swapping relation files'
|
|
|
|
WHEN 6 THEN 'rebuilding index'
|
|
|
|
WHEN 7 THEN 'performing final cleanup'
|
|
|
|
END AS phase,
|
2019-04-07 10:31:32 +02:00
|
|
|
CAST(S.param3 AS oid) AS cluster_index_relid,
|
2019-03-25 15:59:04 +01:00
|
|
|
S.param4 AS heap_tuples_scanned,
|
|
|
|
S.param5 AS heap_tuples_written,
|
|
|
|
S.param6 AS heap_blks_total,
|
|
|
|
S.param7 AS heap_blks_scanned,
|
|
|
|
S.param8 AS index_rebuild_count
|
|
|
|
FROM pg_stat_get_progress_info('CLUSTER') AS S
|
|
|
|
LEFT JOIN pg_database D ON S.datid = D.oid;
|
|
|
|
|
Report progress of CREATE INDEX operations
This uses the progress reporting infrastructure added by c16dc1aca5e0,
adding support for CREATE INDEX and CREATE INDEX CONCURRENTLY.
There are two pieces to this: one is index-AM-agnostic, and the other is
AM-specific. The latter is fairly elaborate for btrees, including
reportage for parallel index builds and the separate phases that btree
index creation uses; other index AMs, which are much simpler in their
building procedures, have simplistic reporting only, but that seems
sufficient, at least for non-concurrent builds.
The index-AM-agnostic part is fairly complete, providing insight into
the CONCURRENTLY wait phases as well as block-based progress during the
index validation table scan. (The index validation index scan requires
patching each AM, which has not been included here.)
Reviewers: Rahila Syed, Pavan Deolasee, Tatsuro Yamada
Discussion: https://postgr.es/m/20181220220022.mg63bhk26zdpvmcj@alvherre.pgsql
2019-04-02 20:18:08 +02:00
|
|
|
CREATE VIEW pg_stat_progress_create_index AS
|
2019-04-09 14:37:37 +02:00
|
|
|
SELECT
|
|
|
|
S.pid AS pid, S.datid AS datid, D.datname AS datname,
|
|
|
|
S.relid AS relid,
|
|
|
|
CAST(S.param7 AS oid) AS index_relid,
|
2019-06-04 09:16:02 +02:00
|
|
|
CASE S.param1 WHEN 1 THEN 'CREATE INDEX'
|
|
|
|
WHEN 2 THEN 'CREATE INDEX CONCURRENTLY'
|
|
|
|
WHEN 3 THEN 'REINDEX'
|
|
|
|
WHEN 4 THEN 'REINDEX CONCURRENTLY'
|
|
|
|
END AS command,
|
2019-04-09 14:37:37 +02:00
|
|
|
CASE S.param10 WHEN 0 THEN 'initializing'
|
|
|
|
WHEN 1 THEN 'waiting for writers before build'
|
|
|
|
WHEN 2 THEN 'building index' ||
|
|
|
|
COALESCE((': ' || pg_indexam_progress_phasename(S.param9::oid, S.param11)),
|
|
|
|
'')
|
|
|
|
WHEN 3 THEN 'waiting for writers before validation'
|
|
|
|
WHEN 4 THEN 'index validation: scanning index'
|
|
|
|
WHEN 5 THEN 'index validation: sorting tuples'
|
|
|
|
WHEN 6 THEN 'index validation: scanning table'
|
|
|
|
WHEN 7 THEN 'waiting for old snapshots'
|
|
|
|
WHEN 8 THEN 'waiting for readers before marking dead'
|
|
|
|
WHEN 9 THEN 'waiting for readers before dropping'
|
|
|
|
END as phase,
|
|
|
|
S.param4 AS lockers_total,
|
|
|
|
S.param5 AS lockers_done,
|
|
|
|
S.param6 AS current_locker_pid,
|
|
|
|
S.param16 AS blocks_total,
|
|
|
|
S.param17 AS blocks_done,
|
|
|
|
S.param12 AS tuples_total,
|
|
|
|
S.param13 AS tuples_done,
|
|
|
|
S.param14 AS partitions_total,
|
|
|
|
S.param15 AS partitions_done
|
|
|
|
FROM pg_stat_get_progress_info('CREATE INDEX') AS S
|
|
|
|
LEFT JOIN pg_database D ON S.datid = D.oid;
|
Report progress of CREATE INDEX operations
This uses the progress reporting infrastructure added by c16dc1aca5e0,
adding support for CREATE INDEX and CREATE INDEX CONCURRENTLY.
There are two pieces to this: one is index-AM-agnostic, and the other is
AM-specific. The latter is fairly elaborate for btrees, including
reportage for parallel index builds and the separate phases that btree
index creation uses; other index AMs, which are much simpler in their
building procedures, have simplistic reporting only, but that seems
sufficient, at least for non-concurrent builds.
The index-AM-agnostic part is fairly complete, providing insight into
the CONCURRENTLY wait phases as well as block-based progress during the
index validation table scan. (The index validation index scan requires
patching each AM, which has not been included here.)
Reviewers: Rahila Syed, Pavan Deolasee, Tatsuro Yamada
Discussion: https://postgr.es/m/20181220220022.mg63bhk26zdpvmcj@alvherre.pgsql
2019-04-02 20:18:08 +02:00
|
|
|
|
2020-03-03 04:03:43 +01:00
|
|
|
CREATE VIEW pg_stat_progress_basebackup AS
|
|
|
|
SELECT
|
|
|
|
S.pid AS pid,
|
|
|
|
CASE S.param1 WHEN 0 THEN 'initializing'
|
|
|
|
WHEN 1 THEN 'waiting for checkpoint to finish'
|
|
|
|
WHEN 2 THEN 'estimating backup size'
|
|
|
|
WHEN 3 THEN 'streaming database files'
|
|
|
|
WHEN 4 THEN 'waiting for wal archiving to finish'
|
|
|
|
WHEN 5 THEN 'transferring wal files'
|
|
|
|
END AS phase,
|
2020-07-17 15:07:54 +02:00
|
|
|
CASE S.param2 WHEN -1 THEN NULL ELSE S.param2 END AS backup_total,
|
|
|
|
S.param3 AS backup_streamed,
|
|
|
|
S.param4 AS tablespaces_total,
|
|
|
|
S.param5 AS tablespaces_streamed
|
2020-03-03 04:03:43 +01:00
|
|
|
FROM pg_stat_get_progress_info('BASEBACKUP') AS S;
|
|
|
|
|
2021-01-06 21:46:26 +01:00
|
|
|
|
|
|
|
CREATE VIEW pg_stat_progress_copy AS
|
|
|
|
SELECT
|
|
|
|
S.pid AS pid, S.datid AS datid, D.datname AS datname,
|
|
|
|
S.relid AS relid,
|
2021-03-09 06:21:03 +01:00
|
|
|
CASE S.param5 WHEN 1 THEN 'COPY FROM'
|
|
|
|
WHEN 2 THEN 'COPY TO'
|
|
|
|
END AS command,
|
|
|
|
CASE S.param6 WHEN 1 THEN 'FILE'
|
|
|
|
WHEN 2 THEN 'PROGRAM'
|
|
|
|
WHEN 3 THEN 'PIPE'
|
|
|
|
WHEN 4 THEN 'CALLBACK'
|
|
|
|
END AS "type",
|
2021-01-06 21:46:26 +01:00
|
|
|
S.param1 AS bytes_processed,
|
|
|
|
S.param2 AS bytes_total,
|
2021-03-09 06:21:03 +01:00
|
|
|
S.param3 AS tuples_processed,
|
|
|
|
S.param4 AS tuples_excluded
|
2021-01-06 21:46:26 +01:00
|
|
|
FROM pg_stat_get_progress_info('COPY') AS S
|
|
|
|
LEFT JOIN pg_database D ON S.datid = D.oid;
|
|
|
|
|
2008-12-19 17:25:19 +01:00
|
|
|
CREATE VIEW pg_user_mappings AS
|
|
|
|
SELECT
|
|
|
|
U.oid AS umid,
|
|
|
|
S.oid AS srvid,
|
|
|
|
S.srvname AS srvname,
|
|
|
|
U.umuser AS umuser,
|
|
|
|
CASE WHEN U.umuser = 0 THEN
|
|
|
|
'public'
|
|
|
|
ELSE
|
|
|
|
A.rolname
|
|
|
|
END AS usename,
|
2017-08-07 16:09:28 +02:00
|
|
|
CASE WHEN (U.umuser <> 0 AND A.rolname = current_user
|
|
|
|
AND (pg_has_role(S.srvowner, 'USAGE')
|
|
|
|
OR has_server_privilege(S.oid, 'USAGE')))
|
2017-05-08 16:24:24 +02:00
|
|
|
OR (U.umuser = 0 AND pg_has_role(S.srvowner, 'USAGE'))
|
|
|
|
OR (SELECT rolsuper FROM pg_authid WHERE rolname = current_user)
|
|
|
|
THEN U.umoptions
|
|
|
|
ELSE NULL END AS umoptions
|
2008-12-19 17:25:19 +01:00
|
|
|
FROM pg_user_mapping U
|
2016-08-19 23:13:47 +02:00
|
|
|
JOIN pg_foreign_server S ON (U.umserver = S.oid)
|
|
|
|
LEFT JOIN pg_authid A ON (A.oid = U.umuser);
|
2008-12-19 17:25:19 +01:00
|
|
|
|
2021-03-27 10:17:12 +01:00
|
|
|
REVOKE ALL ON pg_user_mapping FROM public;
|
2008-12-19 17:25:19 +01:00
|
|
|
|
Introduce replication progress tracking infrastructure.
When implementing a replication solution ontop of logical decoding, two
related problems exist:
* How to safely keep track of replication progress
* How to change replication behavior, based on the origin of a row;
e.g. to avoid loops in bi-directional replication setups
The solution to these problems, as implemented here, consist out of
three parts:
1) 'replication origins', which identify nodes in a replication setup.
2) 'replication progress tracking', which remembers, for each
replication origin, how far replay has progressed in a efficient and
crash safe manner.
3) The ability to filter out changes performed on the behest of a
replication origin during logical decoding; this allows complex
replication topologies. E.g. by filtering all replayed changes out.
Most of this could also be implemented in "userspace", e.g. by inserting
additional rows contain origin information, but that ends up being much
less efficient and more complicated. We don't want to require various
replication solutions to reimplement logic for this independently. The
infrastructure is intended to be generic enough to be reusable.
This infrastructure also replaces the 'nodeid' infrastructure of commit
timestamps. It is intended to provide all the former capabilities,
except that there's only 2^16 different origins; but now they integrate
with logical decoding. Additionally more functionality is accessible via
SQL. Since the commit timestamp infrastructure has also been introduced
in 9.5 (commit 73c986add) changing the API is not a problem.
For now the number of origins for which the replication progress can be
tracked simultaneously is determined by the max_replication_slots
GUC. That GUC is not a perfect match to configure this, but there
doesn't seem to be sufficient reason to introduce a separate new one.
Bumps both catversion and wal page magic.
Author: Andres Freund, with contributions from Petr Jelinek and Craig Ringer
Reviewed-By: Heikki Linnakangas, Petr Jelinek, Robert Haas, Steve Singer
Discussion: 20150216002155.GI15326@awork2.anarazel.de,
20140923182422.GA15776@alap3.anarazel.de,
20131114172632.GE7522@alap2.anarazel.de
2015-04-29 19:30:53 +02:00
|
|
|
CREATE VIEW pg_replication_origin_status AS
|
|
|
|
SELECT *
|
|
|
|
FROM pg_show_replication_origin_status();
|
|
|
|
|
|
|
|
REVOKE ALL ON pg_replication_origin_status FROM public;
|
|
|
|
|
2021-06-03 20:54:06 +02:00
|
|
|
-- All columns of pg_subscription except subconninfo are publicly readable.
|
2017-01-19 18:00:00 +01:00
|
|
|
REVOKE ALL ON pg_subscription FROM public;
|
2022-04-07 06:09:25 +02:00
|
|
|
GRANT SELECT (oid, subdbid, subskiplsn, subname, subowner, subenabled,
|
2022-07-21 05:17:38 +02:00
|
|
|
subbinary, substream, subtwophasestate, subdisableonerr,
|
2023-04-04 18:03:03 +02:00
|
|
|
subpasswordrequired, subrunasowner,
|
2022-07-21 05:17:38 +02:00
|
|
|
subslotname, subsynccommit, subpublications, suborigin)
|
2017-03-03 20:13:48 +01:00
|
|
|
ON pg_subscription TO public;
|
2021-11-30 04:24:30 +01:00
|
|
|
|
2022-03-01 01:47:52 +01:00
|
|
|
CREATE VIEW pg_stat_subscription_stats AS
|
2021-11-30 04:24:30 +01:00
|
|
|
SELECT
|
2022-03-01 01:47:52 +01:00
|
|
|
ss.subid,
|
2021-11-30 04:24:30 +01:00
|
|
|
s.subname,
|
2022-03-01 01:47:52 +01:00
|
|
|
ss.apply_error_count,
|
|
|
|
ss.sync_error_count,
|
|
|
|
ss.stats_reset
|
|
|
|
FROM pg_subscription as s,
|
|
|
|
pg_stat_get_subscription_stats(s.oid) as ss;
|