我正在阅读一本 postgresql 书(从新手到专业版的 PostgreSQL),它说您可以通过调用作为安装一部分的 postgres 二进制文件来启动 postmaster 守护进程:
/usr/lib/postgresql/9.3/bin/postgres "-D" "/var/lib/postgresql/9.3/main" "-c" "config_file=/etc/postgresql/9.3/main/postgresql.conf"
Run Code Online (Sandbox Code Playgroud)
请注意,我们必须将数据目录和配置作为参数传递给 postgres 二进制文件。
然后这本书继续说 pg_ctl 可执行文件,当通过 apt-get 安装时,它也恰好存储在 /usr/lib/postgresql/9.3/bin 目录中,用于简化任务。但我无法让 pg_ctl 运行:
$ /usr/lib/postgresql/9.3/bin/pg_ctl -D "/var/lib/postgresql/9.3/main" start
server starting
postgres@estonia:/usr/lib/postgresql/9.3/bin$ postgres cannot access the server configuration file "/var/lib/postgresql/9.3/main/postgresql.conf": No such file or directory
Run Code Online (Sandbox Code Playgroud)
它说找不到配置文件,但是这里没有办法指定配置文件:
$ /usr/lib/postgresql/9.3/bin/pg_ctl start "-D" "/var/lib/postgresql/9.3/main" "-c" "config_file=/etc/postgresql/9.3/main/postgresql.conf"
pg_ctl: too many command-line arguments (first is "start")
Try "pg_ctl --help" for more information.
Run Code Online (Sandbox Code Playgroud)
如何让 pg_ctl 运行?
当用于启动实例时,pg_ctl
接受postgres
可执行文件的选项,通过-o
从它的联机帮助页:
Run Code Online (Sandbox Code Playgroud)-o options Specifies options to be passed directly to the postgres command. The options should usually be surrounded by single or double quotes to ensure that they are passed through as a group.
所以你在问题中的最后一个命令应该修改为:
/usr/lib/postgresql/9.3/bin/pg_ctl start \
"-D" "/var/lib/postgresql/9.3/main" \
"-o -c config_file=/etc/postgresql/9.3/main/postgresql.conf"
Run Code Online (Sandbox Code Playgroud)
我使用源版本并且从未遇到过任何问题 - 这是源发行版的安装的简短版本。
Short Version
./configure
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
Run Code Online (Sandbox Code Playgroud)
initdb
安装后初始化服务器实例(通过 rpm 或 apt-get 安装可能会为您处理此问题)。
postgres -D /usr/local/pgsql/data > logfile 2>&1 &
Run Code Online (Sandbox Code Playgroud)
或者
./bin/pg_ctl -D ./data/ -l logfile start
Run Code Online (Sandbox Code Playgroud)
应该为你启动服务器 - 我通常使用该pg_ctl
选项。(当您运行 时initdb
,您应该会看到上述命令作为如何启动服务器的提示 - 但是,您可能不必运行initdb
)。
然后您可以使用createdb
test 创建您的第一个数据库。
如果我是你,我会从执行开始
$export PATH=/usr/lib/postgresql/9.3/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
(或者更好的是,将其放入您的 .bashrc 中)。
然后尝试运行
pg_ctl -D /var/lib/postgresql/9.3/main/ -l logfile start
Run Code Online (Sandbox Code Playgroud)
进而
createdb my_test - it will be in the ...9.3/main directory.
Run Code Online (Sandbox Code Playgroud)
请注意,-D 或数据路径周围没有引号。
跑步pg_ctl --help
给出
-c, --core-files allow postgres to produce core files
Run Code Online (Sandbox Code Playgroud)
我认为 PostgreSQL 应该选择你的 postgresql.conf 而无需使用 -c - 我什至不确定这是一个正确的选项。
然后运行psql test
,您应该连接到测试数据库。
归档时间: |
|
查看次数: |
33956 次 |
最近记录: |