ToB企服应用市场:ToB评测及商务社交产业平台

标题: PostgreSQL自带的下令行工具21- initdb [打印本页]

作者: 莱莱    时间: 2024-8-9 15:34
标题: PostgreSQL自带的下令行工具21- initdb
PostgreSQL自带的下令行工具21- initdb

  1. 基础信息
  2. OS版本:Red Hat Enterprise Linux Server release 7.9 (Maipo)
  3. DB版本:16.2
  4. pg软件目录:/home/pg16/soft
  5. pg数据目录:/home/pg16/data
  6. 端口:5777
复制代码
initdb 是 PostgreSQL 中的一个工具,用于创建一个新的 PostgreSQL 数据库集群。数据库集群是一组数据库和一些与这些数据库相干的初始化信息,包括设置文件(如 postgresql.conf 和 pg_hba.conf)以及事件日记等。实际上,initdb 主要负责初始化数据库体系的文件体系情况。
通过help检察帮助文档。
  1. [pg16@test ~]$ initdb --help
  2. initdb initializes a PostgreSQL database cluster.
  3. Usage:
  4.   initdb [OPTION]... [DATADIR]
  5. Options:
  6.   -A, --auth=METHOD         default authentication method for local connections
  7.       --auth-host=METHOD    default authentication method for local TCP/IP connections
  8.       --auth-local=METHOD   default authentication method for local-socket connections
  9. [-D, --pgdata=]DATADIR     location for this database cluster
  10.   -E, --encoding=ENCODING   set default encoding for new databases
  11.   -g, --allow-group-access  allow group read/execute on data directory
  12.       --icu-locale=LOCALE   set ICU locale ID for new databases
  13.       --icu-rules=RULES     set additional ICU collation rules for new databases
  14.   -k, --data-checksums      use data page checksums
  15.       --locale=LOCALE       set default locale for new databases
  16.       --lc-collate=, --lc-ctype=, --lc-messages=LOCALE
  17.       --lc-monetary=, --lc-numeric=, --lc-time=LOCALE
  18.                             set default locale in the respective category for
  19.                             new databases (default taken from environment)
  20.       --no-locale           equivalent to --locale=C
  21.       --locale-provider={libc|icu}
  22.                             set default locale provider for new databases
  23.       --pwfile=FILE         read password for the new superuser from file
  24.   -T, --text-search-config=CFG
  25.                             default text search configuration
  26.   -U, --username=NAME       database superuser name
  27.   -W, --pwprompt            prompt for a password for the new superuser
  28.   -X, --waldir=WALDIR       location for the write-ahead log directory
  29.       --wal-segsize=SIZE    size of WAL segments, in megabytes
  30. Less commonly used options:
  31.   -c, --set NAME=VALUE      override default setting for server parameter
  32.   -d, --debug               generate lots of debugging output
  33.       --discard-caches      set debug_discard_caches=1
  34.   -L DIRECTORY              where to find the input files
  35.   -n, --no-clean            do not clean up after errors
  36.   -N, --no-sync             do not wait for changes to be written safely to disk
  37.       --no-instructions     do not print instructions for next steps
  38.   -s, --show                show internal settings
  39.   -S, --sync-only           only sync database files to disk, then exit
  40. Other options:
  41.   -V, --version             output version information, then exit
  42.   -?, --help                show this help, then exit
  43. If the data directory is not specified, the environment variable PGDATA
  44. is used.
  45. Report bugs to <pgsql-bugs@lists.postgresql.org>.
  46. PostgreSQL home page: <https://www.postgresql.org/>
复制代码
基本使用

initdb 的基本用法涉及指定要创建新数据库集群的目录。以下是一个简朴的下令行示例:
  1. initdb -D /path/to/data_directory
复制代码
这里的 -D /path/to/data_directory 指定了新数据库集群的数据目录。如果不使用 -D 选项,则 initdb 会使用情况变量 PGDATA 指定的目录,如果 PGDATA 也没有设置,initdb 就会报错。
如之前的初始化过程
  1. [pg16@test ~]$ initdb -D /home/pg16/data -U postgres -k
  2. The files belonging to this database system will be owned by user "pg16".
  3. This user must also own the server process.
  4. The database cluster will be initialized with locale "en_US.UTF-8".
  5. The default database encoding has accordingly been set to "UTF8".
  6. The default text search configuration will be set to "english".
  7. Data page checksums are enabled.
  8. creating directory /home/pg16/data ... ok
  9. creating subdirectories ... ok
  10. selecting dynamic shared memory implementation ... posix
  11. selecting default max_connections ... 100
  12. selecting default shared_buffers ... 128MB
  13. selecting default time zone ... America/Los_Angeles
  14. creating configuration files ... ok
  15. running bootstrap script ... ok
  16. performing post-bootstrap initialization ... ok
  17. syncing data to disk ... ok
  18. initdb: warning: enabling "trust" authentication for local connections
  19. initdb: hint: 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.
  20. Success. You can now start the database server using:
  21.     pg_ctl -D /home/pg16/data -l logfile start
复制代码
主要选项


留意事项


initdb 是 PostgreSQL 安装和设置过程中的关键步调,正确使用它对于确保数据库集群正确、安全地运行至关紧张。
服膺:心存敬畏,行有所止。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4