Is `pg_user` a view or a catalog?

2019-07-24 08:50发布

问题:

From https://www.postgresql.org/docs/9.5/static/view-pg-user.html under "System Catalogs"

The view pg_user provides access to information about database users. This is simply a publicly readable view of pg_shadow that blanks out the password field.

Is pg_user a view or a catalog?

  • pg_user is described under "System Catalogs" in the postgresq manual, which seems to suggest pg_user is a catalog/database. ( Am I correct that a catalog is the same concept as a database? (I learned this from a highly upvoted post)?)

  • But the quote calls pg_user a view. Which database's view is pg_user? I didn't find the answer in the link, but I have seen pg_catalog.pg_user works. But pg_catalog is not a catalog or database, but a schema of any database.

Thanks.

回答1:

Unfortunately all of these terms are overloaded.

It is like how a 'schema' can be either the namespace itself, or the definition of all of the objects which exist inside that namespace.

A 'catalog' is either the database itself (which is a terminology adopted by the SQL standards committee, which everyone but them seems to regret), or it is a table or view which lets you introspect into the structure of that database.

So 'view' describes its implementation, while 'catalog' describes its purpose.

In this case it is a bit more confusing because pg_user is a shared catalog (or at least, it is view over shared catalog tables). It is shared between all the databases in the cluster, as PostgreSQL users are not created per-database but are cluster-wide.