PostgreSQL CREATE SCHEMA (original) (raw)

Last Updated : 15 Jul, 2025

**PostgreSQL provides the CREATE SCHEMA statement to create a new schema in a database. **By creating schemas, users can effectively separate data into **logical groups, making it easier to manage and access information. Schemas also enhance security by controlling **object visibility and **permissions, allowing specific users to access or modify objects within a **particular schema without impacting others

In this article, we will explain PostgreSQL CREATE SCHEMA, a powerful statement that allows us to create a new schema within a **database. Understanding how to create a schema in **PostgreSQL is essential for organizing our **database objects and managing access effectively

PostgreSQL - CREATE SCHEMA

The PostgreSQL **CREATE SCHEMA statement is a powerful command used to create a new schema within a database. A schema serves as a container for organizing database objects like **tables, **views, and **functions, enabling users to maintain a **structured and **secure environment for managing data. This functionality is essential for enhancing **database organization and access control.

**Syntax

CREATE SCHEMA [IF NOT EXISTS] schema_name;

**key terms

Creating a Schema for a User

To create a schema owned by a specific user, use the following syntax:

CREATE SCHEMA [IF NOT EXISTS] AUTHORIZATION user_name;

PostgreSQL CREATE SCHEMA Examples

Now that we have known the basics of creating a schema in **PostgreSQL, let's jump into some examples to better understand the concept.

Example 1: Creating a Basic Schema

The following statement creates a new schema named 'marketing':

CREATE SCHEMA IF NOT EXISTS marketing;

The following statement returns all schemas from the current database:

SELECT

**Output

PostgreSQL-CREATE-SCHEMA-Example1

PostgreSQL CREATE SCHEMA Example1

**Explanation:

**Example 2: Creating a Schema for a User

In this example, we will create a new role named **Raju. To perform this, we first need to create the user using the following statement:

CREATE USER Raju WITH ENCRYPTED PASSWORD 'Postgres123';

Now, create a schema for the user 'Raju':

CREATE SCHEMA AUTHORIZATION Raju;

You can also create a schema and assign ownership to 'Raju':

CREATE SCHEMA IF NOT EXISTS geeksforgeeks AUTHORIZATION Raju;

Query to List All Schemas

The following statement returns all schemas from the current database:

SELECT

**Output

PostgreSQL-CREATE-SCHEMA-Example2

PostgreSQL CREATE SCHEMA Example2

**Explanation:

Important Points About PostgreSQL CREATE SCHEMA Statement

Conclusion

In conclusion, mastering the **CREATE SCHEMA syntax in PostgreSQL is crucial for effective PostgreSQL schema management, enabling us to organize our database objects efficiently. By utilizing options like **AUTHORIZATION, we can control ownership and permissions within our schemas.

This knowledge empowers us to structure our database in a way that enhances **performance and **security, ensuring optimal use of resources. Implementing these practices will significantly contribute to better **database organization and **management in our projects.