Linux command
createdb 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Create a database with the default name (current user)
createdb
Create a database with a specific name
createdb [dbname]
Create a database with a specific owner
createdb -O [owner] [dbname]
Create a database with a specific encoding
createdb -E [UTF8] [dbname]
Create a clean database from template0
createdb -T [template0] [dbname]
Create a database on a remote server
createdb -h [hostname] -p [5432] -U [user] [dbname]
Show the SQL command being executed
createdb -e [dbname]
说明
createdb creates a new PostgreSQL database. It is a convenience wrapper around the SQL CREATE DATABASE command, providing a command-line interface that is often more convenient than invoking psql directly. The database name defaults to the current system user name if not specified. An optional description (comment) can be provided as the second argument.
参数
- -D _tablespace_, --tablespace _tablespace_
- Default tablespace for the database.
- -E _encoding_, --encoding _encoding_
- Character encoding for the database.
- -l _locale_, --locale _locale_
- Locale for the database.
- -O _owner_, --owner _owner_
- Database owner user.
- -T _template_, --template _template_
- Template database to copy from (default template1).
- -e, --echo
- Echo the SQL commands that createdb sends to the server.
- --icu-locale _locale_
- ICU locale for the database.
- --icu-rules _rules_
- ICU collation rules for the database.
- --locale-provider _provider_
- Locale provider (libc or icu).
- --strategy _strategy_
- Database creation strategy (wal_log or file_copy).
- -V, --version
- Print the createdb version and exit.
- -h _host_, --host _host_
- Server hostname or socket directory.
- -p _port_, --port _port_
- Server port number.
- -U _user_, --username _user_
- User name to connect as.
- -w, --no-password
- Never prompt for password.
- -W, --password
- Force password prompt.
- --maintenance-db _db_
- Database to connect to when creating the new database. Defaults to postgres, or template1 if postgres does not exist.
FAQ
What is the createdb command used for?
createdb creates a new PostgreSQL database. It is a convenience wrapper around the SQL CREATE DATABASE command, providing a command-line interface that is often more convenient than invoking psql directly. The database name defaults to the current system user name if not specified. An optional description (comment) can be provided as the second argument.
How do I run a basic createdb example?
Run `createdb` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -D _tablespace_, --tablespace _tablespace_ do in createdb?
Default tablespace for the database.