initdb参数说明:
-A, --auth=METHOD 为本地用户指定pg_hba.conf文件中的认证方法,可以为md5、trust、password等,为了安装方便,默认的值是trust,但是除非你信任数据库实例所在服务器上的所有本地用户;
--auth-host=METHOD 指定通过TCP/IP连接的本地用户在pg_hba.conf中使用的认证方法;
--auth-local=METHOD指定通过UNIX Socket连接的本地用户在pg_hba.conf文件中的认证方法;
[-D, --pgdata=]DATADIR 将要初始化的数据目录;其他选项都可以省略,只有这个选项是必需的;
-E, --encoding=ENCODING设置数据库的默认编码,实际它是设置了template1的编码,因为其他新创建的数据库都是以template1为模板克隆的。
--locale=LOCALE 设置区域
--lc-collate=, --lc-ctype=, --lc-messages=LOCALE
--lc-monetary=, --lc-numeric=, --lc-time=LOCALE 为指定的分类设置区域
--no-locale 等价于 --locale=C
--pwfile=FILE 从一个文件读取第一行作为数据库超级用户的口令。
-T, --text-search-config=CFG 设置默认的文本搜索配置。
-U, --username=NAME 设置数据库超级用户的用户名,默认是postgres。
-W, --pwprompt 在initdb的过程中为数据库超级用户设置一个密码。
-X, --waldir=WALDIR 指定预写日志(WAL)的存储目录。
不要在将要初始化的数据目录中手动创建任何文件,如果数据目录中已经有文件,会有如下错误提示:
initdb: directory "/pgdata/10/data" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/pgdata/10/data" or run initdb
with an argument other than "/pgdata/10/data".
更多参数:
[postgres@pghost1~]$/usr/pgsql-14/bin/initdb --help
initdb initializes a PostgreSQL database cluster.
Usage:
initdb [OPTION]... [DATADIR]
Options:
-A, --auth=METHOD default authentication method for local connections
--auth-host=METHOD default authentication method for local TCP/IP connections
--auth-local=METHOD default authentication method for local-socket connections
[-D, --pgdata=]DATADIR location for this database cluster
-E, --encoding=ENCODING set default encoding for new databases
-g, --allow-group-access allow group read/execute on data directory
-k, --data-checksums use data page checksums
--locale=LOCALE set default locale for new databases
--lc-collate=, --lc-ctype=, --lc-messages=LOCALE
--lc-monetary=, --lc-numeric=, --lc-time=LOCALE
set default locale in the respective category for
new databases (default taken from environment)
--no-locale equivalent to --locale=C
--pwfile=FILE read password for the new superuser from file
-T, --text-search-config=CFG
default text search configuration
-U, --username=NAME database superuser name
-W, --pwprompt prompt for a password for the new superuser
-X, --waldir=WALDIR location for the write-ahead log directory
--wal-segsize=SIZE size of WAL segments, in megabytes
Less commonly used options:
-d, --debug generate lots of debugging output
--discard-caches set debug_discard_caches=1
-L DIRECTORY where to find the input files
-n, --no-clean do not clean up after errors
-N, --no-sync do not wait for changes to be written safely to disk
--no-instructions do not print instructions for next steps
-s, --show show internal settings
-S, --sync-only only sync data directory
Other options:
-V, --version output version information, then exit
-?, --help show this help, then exit
If the data directory is not specified, the environment variable PGDATA
is used.