INFORMATICS

The Best

Przełącznik języka

Zaproś mnie na KAWE

Jeżeli podoba Ci się strona i chcesz wspomóc projekt!

Postaw mi kawę na buycoffee.to

This Site

Płatnik

CMS

Hardware

Uncategorised

Emulators

Powershell

Storage Array

DNS

Antivirus program

Licznik

3.png0.png4.png2.png1.png9.png3.png
Today1090
Yesterday1207
This week7075
This month17094
Total3042193

Visitor Info

  • IP: 18.226.248.88
  • Browser: Unknown
  • Browser Version:
  • Operating System: Unknown

Who Is Online

1
Online

piątek, 22 listopad 2024 20:50

PostgreSQL - CREATE Database

Gwiazdka nieaktywnaGwiazdka nieaktywnaGwiazdka nieaktywnaGwiazdka nieaktywnaGwiazdka nieaktywna
 

PostgreSQL - CREATE Database

PostgreSQL provides two ways of creating a new database −

  • Using CREATE DATABASE, an SQL command.
  • Using createdb a command-line executable.

Using CREATE DATABASE

This command will create a database from PostgreSQL shell prompt, but you should have appropriate privilege to create a database.

Example

The following is a simple example, which will create testdb in your PostgreSQL schema

postgres=# CREATE DATABASE testdb;
postgres-# 

Using createdb Command

PostgreSQL command line executable createdb is a wrapper around the SQL command CREATE DATABASE. The only difference between this command and SQL command CREATE DATABASE is that the former can be directly run from the command line and it allows a comment to be added into the database, all in one command.

Syntax

The syntax for createdb is as shown below −

createdb [option...] [dbname [description]]

Parameters

The table given below lists the parameters with their descriptions.

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 following table lists the command line arguments createdb accepts −

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 command prompt and go to the directory where PostgreSQL is installed. Go to the bin directory and execute the following command to create a database.

createdb -h localhost -p 5432 -U postgres testdb

Search