【PostgreSQL】从零开始:(七)PostgreSQL-Initdb命令初始化数据库

news/2024/7/9 23:27:08 标签: 数据库, postgresql

概述

initdb是PostgreSQL初始化数据库的工具,用来生成PostgreSQL的Data目录结构

使用initdb 创建数据库集群时,会自动初始化区域设置支持。 initdb 默认情况下将使用其执行环境的区域设置来初始化数据库集群,因此,如果您的系统已设置为在数据库集群中使用您想要的区域设置,那么您不需要其他任何东西去做。如果您想使用不同的区域设置(或者您不确定系统设置为哪个区域设置),您可以通过指定 initdb 使用哪个区域设置4>选项。例如:--locale

命令

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
      --icu-locale=LOCALE   set ICU locale ID for new databases
      --icu-rules=RULES     set additional ICU collation rules for new databases
  -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
      --locale-provider={libc|icu}
                            set default locale provider for new databases
      --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:
  -c, --set NAME=VALUE      override default setting for server parameter
  -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 database files to disk, then exit

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.

Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>
[postgres@postgre-sql ~]$ 

参数

参数中文解释
-A, --auth=METHOD

这个选项为本地用户指定在pg_hba.conf中使用的默认认证方法(hostlocal行)。initdb将使用指定的认证方法为非复制连接以及复制连接填充pg_hba.conf项。

为了安装方便,md5是默认值。

--auth-host=METHOD这个选项为通过 TCP/IP 连接的本地用户指定在pg_hba.conf中使用的认证方法(host行)。
--auth-local=METHOD这个选项为通过 Unix 域套接字连接的本地用户指定在pg_hba.conf中使用的认证方法(local行)。
-D, --pgdata=DATADIR这个选项指定数据库集簇应该存放的目录。这是initdb要求的唯一信息,但是你可以通过设定PGDATA环境变量来避免书写它,这很方便因为之后数据库服务器使用同一个变量来找到数据库目录。
-E, --encoding=ENCODING选择模板数据库的编码。这也将是后来创建的任何数据库的默认编码,除非你覆盖它。默认值来自于区域,或者如果该值不起作用则为SQL_ASCII
-g, --allow-group-access允许与集簇拥有者同组的用户读取initdb创建的所有集簇文件。 Windows会忽略此选项,因为它不支持POSIX样式的组权限。
--icu-locale=LOCALE设置ICU区域设置ID
--icu-rules=RULES设置其他ICU排序规则
-k, --data-checksum在数据页面上使用校验码来帮助检测 I/O 系统造成的损坏。启用校验码将会引起显著的性能损失。如果被设置,在所有数据库中会为所有对象计算校验码。 所有的检验故障均会在pg_stat_database视图中被报告。
--locale=LOCALE数据库集簇设置默认区域。如果这个选项没有被指定,该区域将从initdb所运行的环境中继承。
--lc-collate=设置字符串排序顺序
--lc-ctype=设置字符分类(什么是字母?它的大写字母等效项?)
--lc-messages=LOCALE设置消息语言
--lc-monetary=设置货币金额的格式
-lc-numeric=设置数字格式
--lc-time=LOCALE设置日期和时间的格式
--no-locale等效于--locale=C
--locale-provider={libc|icu}设置默认区域设置提供程序libc或者icu
--pwfile=FILEinitdb从一个文件读取数据库超级用户的口令。该文件的第一行被当作口令。
-T, --text-search-config=CFG设置默认的文本搜索配置。但在任一数据库中使用相同的配置。--text-search-config=postgresql.conf
-U, --username=NAME选择数据库超级用户的用户名。这个的默认值是实际运行initdb的用户的名称。超级用户的名字是什么真的不重要,但是你可以选择保留常用的名字postgres,即使操作系统的用户名不同。
-W, --pwpromptinitdb提示要求为数据库超级用户给予一个口令。如果你没有计划使用口令认证,这就不重要。否则在你设置一个口令之前你就无法使用口令认证。
-X, --waldir=WALDIR这个选项指定预写式日志会被存储在哪个目录中。
--wal-segsize=SIZE

设置WAL段尺寸,以兆字节为单位。这是WAL日志中每个文件的尺寸。默认的尺寸为16兆字节。该值必须位于2的1次幂和1024次幂(兆字节)之间。这个选项只能在初始化期间设置,并且之后不能更改。

调整这个值来控制WAL日志传送或者归档可能会有用。此外,在有大量WAL的数据库中,每个目录中数量巨大的WAL文件可能会成为性能和管理问题。增加WAL文件尺寸将会降低WAL文件的数量。

-c, --set NAME=VALUE覆盖服务器参数的默认设置
-d, --debug生成调试输出
--discard-caches生成的调试输出不进行缓存,与-d, --debug配合使用
-L DIRECTORY指定输入文件(比如postgres.bki)位置
-n, --no-clean出现错误后不进行清理
-N, --no-sync默认情况下,initdb将等待所有文件被安全地写到磁盘之后再返回。这个选项会导致initdb不等待就返回,后续操作系统如果崩溃可能损坏数据目录。这个选项不适用于生产环境。
--no-instructions不要打印下一步的说明
-s, --show显示内部配置
-S, --sync-only安全地把所有数据库文件写入到磁盘并退出。这个指令不会执行任何数据库初始化操作。
-V, --version打印initdb版本并退出。
-?, --help显示有关initdb命令行参数的帮助并退出。

测试

[postgres@postgre-sql ~]$ initdb -U postgres -D /data/16.1/data2 --pwfile=<(printf "%s" "12345678ab")
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 "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

creating directory /data/16.1/data2 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
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.

Success. You can now start the database server using:

    pg_ctl -D /data/16.1/data2 -l logfile start

[postgres@postgre-sql ~]$ 


http://www.niftyadmin.cn/n/5273694.html

相关文章

C#中HttpWebRequest的用法

前言 HttpWebRequest是一个常用的类&#xff0c;用于发送和接收HTTP请求。在C#中使用HttpWebRequest可以实现各种功能&#xff0c;包括发送GET和POST请求、处理Cookie、设置请求头、添加参数等。本文将深入介绍HttpWebRequest的用法&#xff0c;并给出一些常见的示例。 目录 前…

Rabbitmq 死信取消超时订单

本文使用的版本 otp_win64_25.0rabbitmq-server-3.11.26rabbitmq插件 rabbitmq_delayed_message_exchange-3.11.1 pom.xml文件 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId> …

SpringBoot+WebSocket

SpringBootWebSocket 1.导入依赖&#xff1a; -- Spring Boot 2.x 使用 javax.websocket-- Spring Boot 3.x 使用 jakarta.websocket<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId&g…

GO语言实现视频分割

视频分割 每隔10秒分割一次&#xff0c;去掉分割视频的最后0.5秒&#xff0c;合并后删除分割视频 package mainimport ("fmt""io/ioutil""log""os""os/exec""path/filepath""strconv""strings&q…

Ubuntu 常用命令之 awk 命令用法介绍

AWK是一种处理文本文件的语言&#xff0c;是一个强大的文本分析工具。在Ubuntu系统下&#xff0c;AWK命令主要用于数据处理和生成报告。 AWK命令的参数主要有 -F&#xff1a;指定输入文件分隔符&#xff0c;FS变量就是指定输入字段分隔符-v&#xff1a;赋值一个用户定义变量-…

天猫数据分析-天猫查数据软件-11月天猫平台饮料市场品牌及店铺销量销额数据分析

今年以来&#xff0c;饮料是快消品行业中少数保持稳定增长的品类之一。 11月份&#xff0c;饮料市场同样呈现较好的增长态势。根据鲸参谋电商数据分析平台的相关数据显示&#xff0c;今年11月份&#xff0c;天猫平台上饮料市场的销量为2700万&#xff0c;环比增长约42%&#xf…

【Docker】Docker安装部署maven私服

文章目录 镜像拉取构建nexus实例登录maven私服如何查看实例初始化的admin密码呢&#xff1f;1.查看容器挂载卷2.找到nexus_nexus_data查看挂载卷详情3.查看admin账号密码4.登录并重置密码 使用nexus私服1.设置settings.xml2.设置idea pom 出现的问题小插曲 镜像拉取 docker pu…

视觉增强RTK论文(1)—— GNSS-Stereo-Inertial SLAM for Arable Farming

文章目录 摘要方法标记ORB-SLAM3GNSS-Stereo-Inertial融合实验结果代码摘要 农业任务自动化速度的加快要求现场机器人采用高精度和鲁棒的定位系统。同时定位和映射(SLAM)方法不可避免地会在探索性轨迹上积累漂移,并且主要依赖于位置重新访问和循环闭合来保持一个有界的全局…