❖ Database Objects |
RDBMSs manage different kinds of objects
How are the different types of objects represented?
How do we go from a name (or OID) to bytes stored on disk?
❖ Catalogs |
Consider what information the RDBMS needs about relations:
This information is stored in the system catalog tables
Standard for catalogs in SQL:2003: INFORMATION_SCHEMA
❖ Catalogs (cont) |
The catalog is affected by several types of SQL operations:
create
as
drop
alter
grant
on
E.g. drop table Groups;
delete from Tables where schema = 'public' and name = 'groups';
❖ Catalogs (cont) |
In PostgreSQL, the system catalog is available to users via:
psql
\d
information_schema
select * from information_schema.tables;
pg_catalog
pg_tables
❖ Catalogs (cont) |
You can explore the PostgreSQl catalog via psql
\d
\d Table
Table
\df
\df+ Function
Function
\ef Function
Function
\dv
\d+ View
View
❖ Catalogs (cont) |
A PostgreSQL installation (cluster) typically has many DBs
Some catalog information is global, e.g.
PGDATA/pg_global
❖ Catalogs (cont) |
Side-note: PostgreSQL tuples contain
create table
oid |
unique identifying number for tuple (optional) | |
tableoid |
which table this tuple belongs to | |
xmin/xmax |
which transaction created/deleted tuple (for MVCC) |
❖ Representing Databases |
Above the level of individual DB schemata, we have:
pg_database
pg_namespace
pg_tablespace
Keys are names (strings) and must be unique within cluster.
❖ Representing Databases (cont) |
pg_database
oid, datname, datdba, datacl[], encoding, ...
pg_namespace
oid, nspname, nspowner, nspacl[]
pg_tablespace
oid, spcname, spcowner, spcacl[]
Role=Privileges/Grantor
where Privileges is a string enumerating privileges, e.g.
jas=arwdRxt/jas,fred=r/jas,joe=rwad/jas
❖ Representing Tables |
Representing one table needs tuples in several catalog tables.
Due to O-O heritage, base table for tables is called pg_class
The pg_class
CREATE TYPE AS
pg_class
Some fields from the pg_class
oid, relname, relnamespace, reltype, relowner
relkind, reltuples, relnatts, relhaspkey, relacl, ...
❖ Representing Tables (cont) |
Details of catalog tables representing database tables
pg_class
relname, relnamespace, reltype, relowner, ...
relkind, relnatts, relhaspkey, relacl[], ...
pg_attribute
attrelid, attname, atttypid, attnum, ...
pg_type
typname, typnamespace, typowner, typlen, ...
typtype, typrelid, typinput, typoutput, ...
Produced: 15 Feb 2021