createdb

创建数据库的核心实用程序

createdb 是一个用于创建数据库的核心实用程序,它本质上是 CREATE DATABASE SQL 命令的一个包装器。

createdbPostgreSQL 7.0 中被添加。

用法

截至 PostgreSQL 15createdb 不接受 -d 选项来提供 conninfo 字符串;连接参数必须单独提供或通过环境变量提供。

如果默认的 postgres 数据库不存在,请使用 --maintenance-db 指定一个用于连接的数据库名称。

PostgreSQL 8.3 起,createdb 在成功创建数据库时不再发出任何输出。

源代码

createdb 的源代码位于 src/bin/scripts/createdb.c

变更历史

示例

createdb 的基本用法示例

$ createdb -h localhost -p 5432 -U postgres testdb
$

从 template0 创建数据库

$ createdb -h localhost -p 5432 -U postgres --template=template0 testdb 

尝试创建一个已存在的数据库

$ createdb -h localhost -p 5432 -U postgres postgres
createdb: error: database creation failed: ERROR:  database "postgres" already exists

分类

核心工具

另请参阅

CREATE DATABASE, dropdb

反馈

提交任何关于“createdb”的评论、建议或更正,请点击这里