[英]How to run the 'postgres' command (single-user)
I have postgres
installed on an ubuntu machine, and I am able to enter into the command line via something along the lines of:我在 ubuntu 机器上安装了postgres
,我可以通过以下方式进入命令行:
$ sudo -u postgres psql
psql (10.15 (Ubuntu 10.15-0ubuntu0.18.04.1))
Type "help" for help.
postgres=#
And I can start/stop the server by doing something like:我可以通过执行以下操作来启动/停止服务器:
$ sudo service postgresql
Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ..]
Those both seem fine.这两个看起来都不错。 However, I would like to run postgres in single-user mode to do a couple tests.但是,我想在单用户模式下运行 postgres 来做几个测试。 On the postgres
page it gives a few examples, such as:在postgres
页面上,它提供了一些示例,例如:
To start a single-user mode server, use a command like要启动单用户模式服务器,请使用类似的命令
postgres --single -D /usr/local/pgsql/data other-options my_database
However, if I use the 'postgres' command, I just get an error saying I don't have that command:但是,如果我使用“postgres”命令,我只会收到一条错误消息,说我没有该命令:
$ postgres
Command 'postgres' not found, did you mean:
What do I need to install to run the 'postgres' command in order to enter single-user mode?为了进入单用户模式,我需要安装什么来运行“postgres”命令?
It is already installed, it is just not in your PATH, as it is not anticipated you would use it manually.它已经安装,只是不在您的 PATH 中,因为预计您不会手动使用它。
It is probably somewhere like "/usr/lib/postgresql/10/bin/postgres", or you can use locate
or find
to find it.它可能在“/usr/lib/postgresql/10/bin/postgres”之类的地方,或者您可以使用locate
或find
来找到它。
as you have not export
the binary path that's why it's can't find your binary of postgres.因为你没有export
二进制路径,所以它找不到你的 postgres 二进制文件。
use this command:使用这个命令:
/usr/lib/postgresql/10/bin/postgres --single -D /usr/local/pgsql/data other-options my_database
or,或者,
you can export the path in bash
可以导出bash
中的路径
first open the bashrc with this command: nano ~/.bashrc
首先使用以下命令打开 bashrc: nano ~/.bashrc
add this line in the end: PATH="/usr/lib/postgresql/10/bin/:$PATH"
最后添加这一行: PATH="/usr/lib/postgresql/10/bin/:$PATH"
run this command source ~/.bashrc
运行此命令source ~/.bashrc
the just use postgres --single -D /usr/local/pgsql/data other-options my_database
只需使用postgres --single -D /usr/local/pgsql/data other-options my_database
you can also find where your binary is with this command: find /usr/lib -iname 'postgres'
您还可以使用以下命令找到二进制文件的位置: find /usr/lib -iname 'postgres'
Ubuntu has conf files spread over several places so: Ubuntu 的 conf 文件分布在多个地方,因此:
/usr/lib/postgresql/13/bin/postgres --single -D /var/lib/postgresql/13/main -c "config_file=/etc/postgresql/13/main/postgresql.conf" /usr/lib/postgresql/13/bin/postgres --single -D /var/lib/postgresql/13/main -c "config_file=/etc/postgresql/13/main/postgresql.conf"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.