简体   繁体   English

如何运行“postgres”命令(单用户)

[英]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”之类的地方,或者您可以使用locatefind来找到它。

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.

相关问题 如何从postgres的单用户模式退出? - How to exit from postgres' single-user mode? 是否可以在postgres中以单用户模式创建扩展? - Do create extension work in single-user mode in postgres? 为什么带有heredocs和多行查询的单用户会抛出postgres+docker的语法错误? - Why does single-user with heredocs and multiline queries throw syntax errors for postgres+docker? 如何在 Linux *不*对 Postgres 用户进行 Sudo-ing 时运行 PostgreSQL 的“dropdb”命令? - How Can I Run PostgreSQL's “dropdb” Command on Linux *Without* Sudo-ing to the Postgres User? 无法使用新创建的用户运行 Postgres createdb 命令 - Can't Use Newly Created User to Run Postgres createdb Command 如何使用单个 docker 命令删除和重新创建 postgres 数据库? - How to delete and recreate a postgres database using a single docker command? Postgres:如何使用单个命令更新表中的多个记录 - Postgres: How to update multiple records in a table with a single command 如何运行postgres命令:无法识别当前目录 - How to run a postgres command: could not identify current directory Docker - 如何在 postgres 容器中运行 psql 命令? - Docker - How can run the psql command in the postgres container? 如何在 postgres-node 中运行等于 psql "\copy" 命令的查询? - How to run a query in postgres-node equal to psql "\copy" command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM