In shortly, I usually explain to my junior teammate when they starting to research about PostgreSQL.
In PostgreSQL:
- A Database Server is like an Industrial Zone, there will have many Databases-Cluster (Building)
- Each Database-Cluster (Building) have many Databases. Those are like the floors in Building. The Databases is here as you call the Catalogs. Those Databases-Catalogs (floors) are quite independent with each other, you can not using others materials directly, you must use somethings just like stair, electric wire ... (in database is DBLINK).
- Okay, next, each Database-Catalogs have many Schemas, which are like many Rooms on your floors. Those Schemas can use the material from each others.
- Then, each Schemas have many cell elements such as Table, View, Function, Sequence .... All schemas have the same structure.
Now, back to you example:
- students: is Database (which you call Catalogs)
- public: is schema.
- student: is table.
public | student | table | postgres
is corresponding with schema | table | kind of table | owner of table
You can list:
- catalogs (Database) by the command
\l
in psql or query select * from pg_database;
- Schemas under a catalog by the command
\dn
in psql or query select * from information_schema.schemata;
- Tables under a schemas by the query
select * from pg_tables WHERE schemaname = 'Your schema';
You can show:
- Current Database (Catalogs) by the query
select current_database();
- Current Schema by the query
select current_schema;
Please pay attention that PostgreSQL have two system schema call information_schema and pg_catalog, this maybe make you confuse.
The pg_catalog is a system schema. More information.
The system catalogs are the place where a relational database management system stores schema metadata, such as information about tables and columns, and internal bookkeeping information. PostgreSQL's system catalogs are regular tables. You can drop and recreate the tables, add columns, insert and update values, and severely mess up your system that way. Normally, one should not change the system catalogs by hand, there are always SQL commands to do that. (For example, CREATE DATABASE inserts a row into the pg_database catalog — and actually creates the database on disk.) There are some exceptions for particularly esoteric operations, such as adding index access methods.
The information_schema is a system schema. More information.
The information schema consists of a set of views that contain information about the objects defined in the current database. The information schema is defined in the SQL standard and can therefore be expected to be portable and remain stable — unlike the system catalogs, which are specific to PostgreSQL and are modeled after implementation concerns. The information schema views do not, however, contain information about PostgreSQL-specific features; to inquire about those you need to query the system catalogs or other PostgreSQL-specific views.
I hope these information will help you clearly.