postgresql 创建数据库问题

postgresql 创建数据库问题,第1张

1、使用CREATE DATABASE

命令将创建一个数据库PostgreSQL的shell提示符,但你应该有适当的权限来创建数据库。默认情况下,创建新的数据库将通过克隆标准系统数据库template1。

语法:

CREATE DATABASE语句的基本语法如下:

CREATE DATABASE dbname;

其中dbname是要创建的数据库的名称。

例子:

下面是一个简单的例子,这将创建testdb 在PostgreSQL模式:

postgres=# CREATE DATABASE testdb;

postgres-#

2、使用createdb的命令

PostgreSQL命令行可执行createdb是是SQL命令CREATE DATABASE一个包装器。此命令和SQL命令CREATE DATABASE之间唯一的区别是,前者可以直接在命令行中运行,它允许的注释被添加到数据库中,全部在一个命令。

语法:

createdb语法如下所示:

createdb [option] [dbname [description]]

参数

下表列出了参数及它们的描述。

参数名称            描述

dbname    The name of a database to create  

description    Specifies a comment to be associated with the newly created database  

options    command-line arguments which createdb accepts  

选项

下表列出了命令行参数CREATEDB接收:

选项                            描述

-D tablespace         Specifies the default tablespace for the database  

-e                     Echo the commands that createdb generates and sends to the server  

-E encoding    Specifies the character encoding scheme to be used in this database  

-l locale    Specifies the locale to be used in this database  

-T template    Specifies the template database from which to build this database  

--help    Show help about dropdb command line arguments, and exit  

-h host    Specifies the host name of the machine on which the server is running  

-p port    Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections  

-U username    User name to connect as  

-w    Never issue a password prompt  

-W    Force createdb to prompt for a password before connecting to a database  

打开命令提示符,然后去是PostgreSQL安装所在的目录。进入到bin目录,执行下面的命令创建一个数据库。

createdb -h localhost -p 5432 -U postgress testdb

password

上面的命令会提示Postgres的默认的PostgreSQL管理用户的密码,以便提供密码和继续创建新的数据库。

一旦创建数据库时可以使用上述方法,可以检查它在列表中的数据库使用l即反斜线el命令如下:

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-#

分类: 电脑/网络 >> 程序设计 >> 其他编程语言

解析:

PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS), 也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统。有些特性甚至连商业数据库都不具备。这个起源于伯克利(BSD)的数据库研究计划目前已经衍生成一项国际开发项目, 并且有非常广泛的用户。

PostgreSQL 可以说是最富特色的自由数据库管理系统,甚至我们也可以说是最强大的自由软件数据库管理系统。事实上, PostgreSQL 的特性覆盖了 SQL-2/SQL-92 和 SQL-3/SQL-99,首先,它包括了可以说是目前世界上最丰富的数据类型的支持,其中有些数据类型可以说连商业数据库都不具备, 比如 IP 类型和几何类型等;其次,PostgreSQL 是全功能的自由软件数据库,很长时间以来,PostgreSQL 是唯一支持事务、子查询、多版本并行控制系统、数据完整性检查等特性的唯一的一种自由软件的数据库管理系统。直到最近才有 Inprise 的 InterBase 以及 SAP 等厂商将其原先专有软件开放为自由软件之后才打破了这个唯一。

以上就是关于postgresql 创建数据库问题全部的内容,包括:postgresql 创建数据库问题、postgresql是什么数据库请详解一下,谢谢、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9477596.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存