← 返回命令列表

Linux command

initdb 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Initialize PostgreSQL database cluster

initdb -D [/var/lib/postgresql/data]

Initialize with specific encoding

initdb -D [/var/lib/postgresql/data] -E UTF8

Initialize with specific locale

initdb -D [/var/lib/postgresql/data] --locale=[en_US.UTF-8]

Initialize with authentication

initdb -D [/var/lib/postgresql/data] -A [scram-sha-256] -W

Initialize with specific user

initdb -D [/var/lib/postgresql/data] -U [postgres]

说明

initdb creates a new PostgreSQL database cluster. A cluster is a collection of databases managed by a single PostgreSQL server instance, stored in a data directory. This command must be run before starting PostgreSQL for the first time. It creates the template databases, configuration files, and directory structure.

参数

-D, --pgdata _dir_
Data directory location.
-E, --encoding _encoding_
Default database encoding.
--locale _locale_
Default locale.
-U, --username _user_
Database superuser name.
-W, --pwprompt
Prompt for superuser password.
-A, --auth _method_
Authentication method.
--auth-local _method_
Local connection auth method.
--auth-host _method_
Host connection auth method.
-k, --data-checksums
Enable data checksums.
--wal-segsize _size_
WAL segment size.

FAQ

What is the initdb command used for?

initdb creates a new PostgreSQL database cluster. A cluster is a collection of databases managed by a single PostgreSQL server instance, stored in a data directory. This command must be run before starting PostgreSQL for the first time. It creates the template databases, configuration files, and directory structure.

How do I run a basic initdb example?

Run `initdb -D [/var/lib/postgresql/data]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -D, --pgdata _dir_ do in initdb?

Data directory location.