{"id":2272,"date":"2025-03-07T22:20:29","date_gmt":"2025-03-07T15:20:29","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=2272"},"modified":"2025-03-12T19:52:08","modified_gmt":"2025-03-12T12:52:08","slug":"postgresql-create-database","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/","title":{"rendered":"PostgreSQL CREATE DATABASE Statement"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to create a new database using the PostgreSQL <code>CREATE DATABASE<\/code> statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='postgresql-create-database-statement-overview'>PostgreSQL CREATE DATABASE statement overview <a href=\"#postgresql-create-database-statement-overview\" class=\"anchor\" id=\"postgresql-create-database-statement-overview\" title=\"Anchor for PostgreSQL CREATE DATABASE statement overview\">#<\/a><\/h2>\n\n\n\n<p>In PostgreSQL, a database is a collection of <a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-schema\/\">schemas<\/a>, tables, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-view\/\">views<\/a>, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-index\/\">indexes<\/a>, and other objects. PostgreSQL isolates each database from others, ensuring security.<\/p>\n\n\n\n<p>Each PostgreSQL server can have multiple databases. You can create a new database using the <code>CREATE DATABASE<\/code> statement.<\/p>\n\n\n\n<p>Here&#8217;s the basic syntax of the <code>CREATE DATABASE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> database_name;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>CREATE DATABASE<\/code> statement requires only the database name.<\/p>\n\n\n\n<p class=\"note\">The <code>CREATE DATABASE<\/code> has many other options I&#8217;ll cover in the following tutorial.<\/p>\n\n\n\n<p>If you create a database that already exists, you&#8217;ll encounter an error.<\/p>\n\n\n\n<p>We&#8217;ll show you how to create a database using psql and pgAdmin tools.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='create-a-new-database-using-psql'>Create a new database using psql <a href=\"#create-a-new-database-using-psql\" class=\"anchor\" id=\"create-a-new-database-using-psql\" title=\"Anchor for Create a new database using psql\">#<\/a><\/h2>\n\n\n\n<p>First, open a terminal on Linux or a command prompt on Windows and connect to your local PostgreSQL using the <code>psql<\/code> command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">psql -U postgres<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It&#8217;ll prompt you to enter the password for the <code>postgres<\/code> user. You need enter a valid password for the <code>postgres<\/code> user to connect.<\/p>\n\n\n\n<p>Second, execute the <code>CREATE DATABASE<\/code> statement to create a new database:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">DATABASE<\/span> sales;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>PostgreSQL will create a new database with the name <code>sales<\/code>.<\/p>\n\n\n\n<p>If the <code>sales<\/code> database already exists, you&#8217;ll get the following error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">ERROR: <span class=\"hljs-keyword\">database<\/span> \"sales\" already <span class=\"hljs-keyword\">exists<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, display detailed information about the <code>sales<\/code> database by executing the following command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">\\l sales<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">                                                                List <span class=\"hljs-keyword\">of<\/span> databases\n <span class=\"hljs-type\">Name<\/span>  |  <span class=\"hljs-keyword\">Owner<\/span>   | <span class=\"hljs-keyword\">Encoding<\/span> | Locale Provider |          <span class=\"hljs-keyword\">Collate<\/span>           |           Ctype            | Locale | ICU Rules | <span class=\"hljs-keyword\">Access<\/span> <span class=\"hljs-keyword\">privileges<\/span>\n<span class=\"hljs-comment\">-------+----------+----------+-----------------+----------------------------+----------------------------+--------+-----------+-------------------<\/span>\n sales | postgres | UTF8     | libc            | English_United States<span class=\"hljs-number\">.1252<\/span> | English_United States<span class=\"hljs-number\">.1252<\/span> |        |           |<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Alternatively, you can retrieve database names from the <code>pg_database<\/code> view using the following query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  datname\n<span class=\"hljs-keyword\">FROM<\/span>\n  pg_database\n<span class=\"hljs-keyword\">WHERE<\/span>\n  datname = <span class=\"hljs-string\">'sales'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> datname\n<span class=\"hljs-comment\">---------<\/span>\n sales<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='current-database'>Current Database <a href=\"#current-database\" class=\"anchor\" id=\"current-database\" title=\"Anchor for Current Database\">#<\/a><\/h2>\n\n\n\n<p>When connecting to a PostgreSQL using <code>psql<\/code> without specifying a database, you&#8217;re connecting to the <code>postgres<\/code> database by default. The <code>postgres<\/code> database becomes the current database.<\/p>\n\n\n\n<p>The prompt looks like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">postgres=#<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Alternatively, you can check the current database in <code>psql<\/code> using the <code>\\c<\/code> command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">\\c<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It&#8217;ll return the following output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">You are now connected <span class=\"hljs-keyword\">to<\/span> the <span class=\"hljs-keyword\">database<\/span> \"postgres\" <span class=\"hljs-keyword\">as<\/span> <span class=\"hljs-keyword\">user<\/span> \"postgres\".<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>After creating a new database, you can switch the current database to it using the <code>\\c<\/code> command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">\\c database_name<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example, the following command changes the current database to the <code>sales<\/code> database:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">\\c sales<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The prompt will be like the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">sales=#<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>It indicates that the current database is <code>sales<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='create-a-new-database-using-pgadmin'>Create a new database using pgAdmin <a href=\"#create-a-new-database-using-pgadmin\" class=\"anchor\" id=\"create-a-new-database-using-pgadmin\" title=\"Anchor for Create a new database using pgAdmin\">#<\/a><\/h2>\n\n\n\n<p>If you prefer a graphical user interface (GUI), pgAdmin is an excellent tool for managing and interacting PostgreSQL databases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='step-1-open-pgadmin'>Step 1: Open pgAdmin <a href=\"#step-1-open-pgadmin\" class=\"anchor\" id=\"step-1-open-pgadmin\" title=\"Anchor for Step 1: Open pgAdmin\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, launch pgAdmin application.<\/li>\n\n\n\n<li>Second, connect to your PostgreSQL server.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='step-2-navigate-to-databases'>Step 2: Navigate to Databases <a href=\"#step-2-navigate-to-databases\" class=\"anchor\" id=\"step-2-navigate-to-databases\" title=\"Anchor for Step 2: Navigate to Databases\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, expand the&nbsp;<strong>Servers<\/strong>&nbsp;section in the left sidebar. <\/li>\n\n\n\n<li>Second, expand your PostgreSQL server. <\/li>\n\n\n\n<li>Third, right-click on&nbsp;<strong>Databases<\/strong>.<\/li>\n\n\n\n<li>Finally, select&nbsp;<strong>Create &gt; Database<\/strong>&#8230;<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"132\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database.png\" alt=\"pgadmin create database\" class=\"wp-image-2280\" srcset=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database.png 707w, https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database-300x56.png 300w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='step-3-configure-the-database'>Step 3: Configure the Database <a href=\"#step-3-configure-the-database\" class=\"anchor\" id=\"step-3-configure-the-database\" title=\"Anchor for Step 3: Configure the Database\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, enter a name for your database in the <strong>Database<\/strong> input field, such as <code>hr<\/code>.<\/li>\n\n\n\n<li>Second, click the&nbsp;<strong>Save<\/strong> button&nbsp;to create the database.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"649\" height=\"602\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-enter-database-name.png\" alt=\"\" class=\"wp-image-2282\" srcset=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-enter-database-name.png 649w, https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-enter-database-name-300x278.png 300w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/figure>\n\n\n\n<p>Behind the scenes, pgAdmin uses the <code>CREATE DATABASE<\/code> statement to create the <code>hr<\/code> database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='step-4-verify-the-database'>Step 4: Verify the Database <a href=\"#step-4-verify-the-database\" class=\"anchor\" id=\"step-4-verify-the-database\" title=\"Anchor for Step 4: Verify the Database\">#<\/a><\/h3>\n\n\n\n<p>You&#8217;ll see the new database appear under the&nbsp;<strong>Databases<\/strong>&nbsp;section in pgAdmin:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"425\" height=\"405\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/postgresql-create-database-hr.png\" alt=\"PostgreSQL CREATE DATABASE Statement\" class=\"wp-image-2283\" srcset=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/postgresql-create-database-hr.png 425w, https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/postgresql-create-database-hr-300x286.png 300w\" sizes=\"auto, (max-width: 425px) 100vw, 425px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='database-owner'>Database owner <a href=\"#database-owner\" class=\"anchor\" id=\"database-owner\" title=\"Anchor for Database owner\">#<\/a><\/h2>\n\n\n\n<p>The user you use to create a database becomes the <strong>database owner<\/strong>. The database owner is a role (or user) that has special privileges, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Full control over the database: The owner can create, alter, and modify database objects (tables, views, indexes, functions, etc.).<\/li>\n\n\n\n<li>Grant and revoke privileges: The owner can <a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-grant\/\">grant<\/a> and <a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-revoke\/\">revoke<\/a> permissions on database objects to other users.<\/li>\n\n\n\n<li>Drop the database: Only the owner (or a superuser) can <a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-drop-database\/\">delete the database<\/a>.<\/li>\n\n\n\n<li>Manage extensions: the owner can manage extensions within the database.<\/li>\n<\/ul>\n\n\n\n<p>In the previous example, we used the <code>postgres<\/code> user, a superuser, to create the <code>sales<\/code> and <code>hr<\/code> databases. Therefore, the <code>postgres<\/code> user became the database owner of the <code>sales<\/code> and <code>hr<\/code> databases.<\/p>\n\n\n\n<p>The following query returns the database names and owners:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  datname,\n  pg_catalog.pg_get_userbyid (datdba) <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">owner<\/span>\n<span class=\"hljs-keyword\">FROM<\/span>\n  pg_database\n<span class=\"hljs-keyword\">WHERE<\/span>\n  datname <span class=\"hljs-keyword\">IN<\/span> (<span class=\"hljs-string\">'sales'<\/span>, <span class=\"hljs-string\">'hr'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"> datname |  <span class=\"hljs-keyword\">owner<\/span>\n<span class=\"hljs-comment\">---------+----------<\/span>\n sales   | postgres\n hr      | postgres<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that you can change the owner of a database using the <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-alter-database\/\">ALTER DATABASE<\/a><\/code> statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code>CREATE DATABASE<\/code> statement to create a new database.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2272\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL CREATE DATABASE Statement\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2272\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL CREATE DATABASE Statement\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to create a new database using the PostgreSQL CREATE DATABASE statement.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2269,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2272","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL CREATE DATABASE Statement<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to create a new database using the PostgreSQL CREATE DATABASE statement.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL CREATE DATABASE Statement\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to create a new database using the PostgreSQL CREATE DATABASE statement.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-12T12:52:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database.png\" \/>\n\t<meta property=\"og:image:width\" content=\"707\" \/>\n\t<meta property=\"og:image:height\" content=\"132\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/\",\"name\":\"PostgreSQL CREATE DATABASE Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/pgadmin-create-database.png\",\"datePublished\":\"2025-03-07T15:20:29+00:00\",\"dateModified\":\"2025-03-12T12:52:08+00:00\",\"description\":\"In this tutorial, you'll learn how to create a new database using the PostgreSQL CREATE DATABASE statement.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/pgadmin-create-database.png\",\"contentUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/pgadmin-create-database.png\",\"width\":707,\"height\":132,\"caption\":\"pgadmin create database\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/postgresql-create-database\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Database Administration\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-database-administration\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL CREATE DATABASE Statement\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL CREATE DATABASE Statement","description":"In this tutorial, you'll learn how to create a new database using the PostgreSQL CREATE DATABASE statement.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL CREATE DATABASE Statement","og_description":"In this tutorial, you'll learn how to create a new database using the PostgreSQL CREATE DATABASE statement.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-03-12T12:52:08+00:00","og_image":[{"width":707,"height":132,"url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/","url":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/","name":"PostgreSQL CREATE DATABASE Statement","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/#primaryimage"},"image":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database.png","datePublished":"2025-03-07T15:20:29+00:00","dateModified":"2025-03-12T12:52:08+00:00","description":"In this tutorial, you'll learn how to create a new database using the PostgreSQL CREATE DATABASE statement.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/#primaryimage","url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database.png","contentUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/03\/pgadmin-create-database.png","width":707,"height":132,"caption":"pgadmin create database"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/postgresql-create-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Database Administration","item":"https:\/\/www.pgtutorial.com\/postgresql-database-administration\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL CREATE DATABASE Statement"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=2272"}],"version-history":[{"count":12,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2272\/revisions"}],"predecessor-version":[{"id":2416,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2272\/revisions\/2416"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2269"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=2272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}