A schema is a logical namespace that organizes objects such as tables, views, functions, and data types in a single database. A schema operates like a folder or directory, allowing one to group related objects, manage access, and avoid naming conflicts. For example, you can have schemas with different names (customers, products) that have tables with the same name, orders (customers.orders, products.orders). Schemas also allow database administrators to implement access controls by controlling permissions. Below are some schema commands in PostgreSQL:
List all schemas
\dn or SELECT schema_name FROM information_schema.schemata;
Create schema
CREATE SCHEMA schema_name;
Drop schema
DROP SCHEMA schema_name;
Set search path
SET search_path TO schema1, public;
View search path
SHOW search_path;
List tables in a schema
\dt schema_name.*
Move table to another schema
ALTER TABLE current_schema.table_name SET SCHEMA new_schema;