initdb 是一个 服务器实用程序,用于初始化一个新的 PostgreSQL 集群的数据目录。
initdb 始终存在于 PostgreSQL 中。
变更历史
- PostgreSQL 18
- PostgreSQL 17
- PostgreSQL 16
- PostgreSQL 15
- PostgreSQL 14
- PostgreSQL 11
- PostgreSQL 10
- PostgreSQL 9.6
- 通过仅使用一个后端进行引导后步骤来加快速度(提交 c4a8812c)
- PostgreSQL 9.4
- 现在会为不正确的区域设置抛出错误,而不是默默地回退到默认设置(提交 31a26323)
- PostgreSQL 9.3
- PostgreSQL 9.2
- 识别服务器时区并将值写入
postgresql.conf(提交 ca4af308) - 添加了选项
--auth-local和--auth-host(提交 8a02339e)
- 识别服务器时区并将值写入
- PostgreSQL 9.0
- PostgreSQL 8.3
pg_xlog目录的位置现在可以通过选项-X/--xlogdir指定;PostgreSQL 10 及更高版本:-X/--waldir(提交 c3578a68)
- PostgreSQL 8.2
- PostgreSQL 8.1
- 默认创建一个名为
postgres的数据库(提交 6f7fc0ba)
- 默认创建一个名为
- PostgreSQL 8.0
- PostgreSQL 7.1
- initdb 排序规则存储在 pg_control 中,以防止排序规则被更改
- PostgreSQL 7.0
- 添加了交互式密码提示(提交 2a1bfbce)
示例
initdb 的基本用法示例
$ initdb -D /var/lib/pgsql
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/pgsql ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... UTC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/pgsql -l logfile start
参考资料
- PostgreSQL 文档: initdb
