PostgreSQL – Rename Schema
You can rename a schema using the ALTER SCHEMA
statement. Here’s the basic syntax for renaming a schema:
ALTER SCHEMA old_schema_name RENAME TO new_schema_name;
Replace old_schema_name
with the current name of the schema you want to rename, and new_schema_name
with the new name you want to assign to the schema.
Here’s an example:
ALTER SCHEMA my_schema RENAME TO renamed_schema;
This statement renames the schema my_schema
to renamed_schema
. Make sure you have the necessary privileges to rename schemas, and be aware that renaming a schema will also update the schema name for all objects contained within it.
If there are any objects in the schema (tables, views, functions, etc.), they will remain in the schema after the rename operation, and their schema association will be updated accordingly.