Renaming

ALTER SCHEMA ... RENAME TO

Lock mode ACCESS EXCLUSIVE
Risk HIGH
Blocks reads, writes, other DDL
pgfence rule rename-schema
ALTER SCHEMA billing RENAME TO billing_v2;

What this does

Breaks every schema-qualified query, view, function, and ORM connection config that references the old schema name the instant it commits. There is no transition period at the database level.

Safe rewrite

Create the target schema and migrate objects one by one instead of renaming in place

-- Create the target schema first, then migrate objects one by one.
-- Move tables, views, and functions with ALTER ... SET SCHEMA.
-- Update application code, ORM configs, and connection strings.
-- Drop the old schema only after all references are gone.

Read more

More in Renaming