How to create a PostgreSQL database

Source: Internet
Author: User
Tags locale unix domain socket

PostgreSQL provides two ways to create a new database: The first is the SQL command that uses the CREATE database. The second is a command-line executable file that uses Createdb.

The first is to create a database by using the creation databases.

Syntax format:

The basic syntax for the CREATE database statement is as follows:

CREATE DATABASE dbname; where dbname is the name of the database to be created.

To illustrate:

Here is a simple example that will create TestDB in PostgreSQL mode:

Description: We enter CREATE DATABASE TestDB; The system also returns the Create database, which indicates that the system created the TestDB successfully, where \h represents a view of the database in the system.

The second type: Use the Createdb command:

The PostgreSQL command line executable Createdb is a wrapper for SQL command create database. The only difference between this command and the SQL command create database is that the former can be run directly on the command line, and it allows comments to be added to the database, all in one command.

Grammar:

The CREATEDB syntax is as follows:createdb [option...] [dbname [description]]

Parameters

The following table lists the parameters and their descriptions.

Parameter name

Describe

dbname

The name of the database to create.

Description

Specifies the comment to associate with the newly created database.

Options

This createdb accepts command-line arguments.

Options

The following table lists the command line parameters Createdb receive:

Options

Describe

-D tablespace

Specifies the default table space for the database.

-E

Duplicate createdb generated and sent to the server command.

-E encoding

Specifies the character encoding scheme to use in this database.

-L Locale

Specifies the locale that is used in the database.

-T Template

Specifies the template database to establish this database.

--help

Displays command line arguments dropdb help and exits.

-H Host

Specifies the host name of the machine on which the server is running.

-P Port

The server that specifies the TCP port or local UNIX domain socket file name extension listens for connections.

-u username

The user name of the connection.

-W

Never issued a password hint.

-W

Force createdb the password hint before connecting to the database.

Open a command prompt, and then 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 postgress TestDB

Password ******

The above command prompts Postgres for the default PostgreSQL Admin user's password in order to provide the password and continue to create a new database.

---restore content ends---

How to create a PostgreSQL database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.