↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

已结束支持的版本: 7.4 / 7.3 / 7.2 / 7.1 / 7.0 / 6.5 / 6.4
历史版本。 PostgreSQL 6.4 已结束支持。 请参阅 当前版本手册.

initlocation

initlocation — 创建一个辅助的 Postgres 数据库存储区

大纲

initlocation [ --location=altdir | -D altdir ]
    [ --username=name | -u name ]
    [ altdir ]

输入

--location=altdir
-D altdir
altdir

你想让备选数据库放在你的 Unix 文件系统的什么地方?顶层目录称为 PGDATA 目录,所以你可能想把你的第一个备选位置指向 PGDATA2。

--username=name
-u name
PGUSER

谁将成为这个数据库存储区的 Unix 文件系统拥有者?Postgres 超级用户是一个 Unix 用户,他拥有存储数据库系统的所有文件,并且拥有访问它们的 postmaster 和后端进程。通常,这就是应该运行 initlocation 的用户,他因此将拥有这些目录和文件。

注意

只有 Unix 超级用户才能创建一个由不是 Postgres 超级用户的用户拥有的数据库系统。指定一个不是 Postgres 超级用户的用户可能导致数据库安全和数据完整性问题。更多信息请参阅 PostgreSQL 管理员指南。

输出

initlocation 将在指定的位置创建目录。

We are initializing the database area with username postgres (uid=500). This user will own all the files and must also own the server process. Creating Postgres database system directory altdir Creating Postgres database system directory altdir

成功完成。

We are initializing the database area with username postgres (uid=500). This user will own all the files and must also own the server process. Creating Postgres database system directory /usr/local/src/testlocation mkdir: cannot make directory `altdir': Permission denied

你没有写入指定目录区域的文件系统权限。

Valid username not given. You must specify the username for the Postgres superuser for the database system you are initializing, either with the --username option or by default to the USER environment variable.

你指定的用户名不是 Postgres 超级用户。

Can't tell what username to use. You don't have the USER environment variable set to your username and didn't specify the --username option

指定 --username 命令行选项。

描述

initlocation 创建一个新的 Postgres 辅助数据库存储区。一个辅助存储区包含一棵必需的目录树,并且这些目录上有正确的文件权限。

创建一个数据库存储区包括创建数据库数据可能存放的目录。

initlocation 有两类参数。首先,你可以指定一个环境变量(例如 PGDATA2)。这个环境变量应当为后端所知,供以后在 CREATE DATABASE/WITH LOCATION 或 createdb -D altdir 中使用。但是,后端守护进程的环境中必须有这个变量,这才能成功。其次,或许可以指定存储区顶层目录的一个显式绝对路径。但是,第二个选项只有在 Postgres 安装期间显式启用时才可用。它通常被禁用,以减轻安全和数据完整性方面的顾虑。

注意

Postgres 会把 /base/ 追加到指定的路径来创建存储区。

后端要求 WITH LOCATION 的任何全大写且不含路径分隔符的参数都是环境变量。

用法

要在一个备选位置创建数据库,使用环境变量:

% setenv PGDATA2 /opt/postgres/data

% initlocation PGDATA2
% createdb -D PGDATA2

报告文档问题

阅读 上游文档. 反馈更正前请先核对 当前版本手册.