This section examines about how to make another data set in your PostgreSQL. PostgreSQL gives two different ways of making another information base −
- Utilizing CREATE DATABASE, a SQL order.
- Utilizing createdb an order line executable.
Using CREATE DATABASE
This order will make an information base from PostgreSQL shell brief, however you ought to have proper advantage to make a data set. Of course, the new data set will be made by cloning the standard framework information base template1.
Syntax
The fundamental language structure of CREATE DATABASE explanation is as per the following −
CREATE DATABASE dbname;
where dbname is the name of an information base to make.
Example
Coming up next is a basic model, which will make testdb in your PostgreSQL blueprint
postgres=# CREATE DATABASE testdb;
postgres-#
Using createdb Command
PostgreSQL order line executable createdb is a covering around the SQL order CREATE DATABASE. The lone distinction between this order and SQL order CREATE DATABASE is that the previous can be straightforwardly run from the order line and it permits a remark to be added into the information base, across the board order.
Syntax
The punctuation for createdb is as demonstrated beneath −
createdb [option...] [dbname [description]]
Parameters
The table given underneath records the boundaries with their portrayals.
S. No. | Parameter & Description |
---|---|
1 |
dbname The name of a database to create. |
2 |
description Specifies a comment to be associated with the newly created database. |
3 |
options command-line arguments, which createdb accepts. |
Options
The accompanying table records the order line contentions createdb acknowledges −
S. No. | Option & Description |
---|---|
1 |
-D tablespace Specifies the default tablespace for the database. |
2 |
-e Echo the commands that createdb generates and sends to the server. |
3 |
-E encoding Specifies the character encoding scheme to be used in this database. |
4 |
-l locale Specifies the locale to be used in this database. |
5 |
-T template Specifies the template database from which to build this database. |
6 |
--help Show help about createdb command line arguments, and exit. |
7 |
-h host Specifies the host name of the machine on which the server is running. |
8 |
-p port Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections. |
9 |
-U username User name to connect as. |
10 |
-w Never issue a password prompt. |
11 |
-W Force createdb to prompt for a password before connecting to a database. |
Open the order immediate and go to the catalog where PostgreSQL is introduced. Go to the container catalog and execute the accompanying order to make an information base.
createdb -h localhost -p 5432 -U postgres testdb
password *****
The above provided order will provoke you for secret phrase of the PostgreSQL administrator client, which is postgres, naturally. Consequently, give a secret phrase and continue to make your new information base
When a data set is made utilizing both of the previously mentioned techniques, you can check it in the rundown of information bases utilizing \l, i.e., oblique punctuation line el order as follows −
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | C | C |
(4 rows)
postgres-#