AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-214611

Freemium's questions

Martin Hope
Freemium
Asked: 2020-08-26 09:07:50 +0800 CST

如何启动 PostgreSQL 12.4 [OSX]

  • 2

我不是来自 PostgreSQL 背景,我想将它用于我目前正在从事的项目,因为它是我正在使用的推荐数据库。

我使用 PgAdmin 4 来可视化数据库,我对该应用程序上“关闭服务器”的字面理解是它关闭了数据库,但事实并非如此。所以我想学习如何在项目开始时启动/停止/重新启动服务器,这样我就可以更好地在以后管理它。



tl;dr:在 OSX 上,不使用自制软件并使用默认设置/目录结构,启动 DB 的正确方法/命令是什么?


我的尝试和错误的开始......

在许多网站上大量阅读之后,我找到了停止服务器的方法,一种对我个人有用的方法——不使用 Homebrew 和 OSX

停止数据库

$ sudo -u postgres pg_ctl -D /Library/PostgreSQL/12/data/ stop

could not identify current directory: Permission denied
waiting for server to shut down.... done
server stopped

极好的!
数据库停止了。该网站无法正常工作,但除外。

正在尝试开始...

现在,自然地尝试重新启动它

$ sudo -u postgres pg_ctl -D /Library/PostgreSQL/12/data/ start

产量...

could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "postgres" is needed by pg_ctl but was not found in the
same directory as "pg_ctl".
Check your installation.

哦哦...

所以pg_ctl不在同一个目录中......也许我需要在命令中指定它的路径

$ sudo -u postgres /Library/PostgreSQL/12/bin/pg_ctl -D /Library/PostgreSQL/12/data/ start
could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "postgres" is needed by pg_ctl but was not found in the
same directory as "pg_ctl".
Check your installation.

尝试#1

尝试别的东西,省略-D因为我可能过于复杂的事情......

$ sudo -u postgres pg_ctl start
could not identify current directory: Permission denied
pg_ctl: no database directory specified and environment variable PGDATA unset

PGDATA没有设置...我在我的用户上设置了它,所以我猜它不是为postgres用户设置的。那就试试吧

$ sudo -u postgres export PGDATA="/Library/PostgreSQL/12/data/"
sudo: export: command not found

好吧,不是那样的。那么然后呢?!

进一步阅读,我看到一些使用initdb(归功于此 Q 中的最终更新),而不是start我想我会试一试。似乎没有其他任何工作,所以让我们尝试一下

$ sudo -u postgres /Library/PostgreSQL/12/bin/pg_ctl -D /Library/PostgreSQL/12/data/ initdb
could not identify current directory: Permission denied
could not identify current directory: Permission denied
could not identify current directory: Permission denied
The program "initdb" is needed by pg_ctl but was not found in the
same directory as "pg_ctl".
Check your installation.

尝试#2

也许重新排列命令一点点......

$ sudo su postgres pg_ctl initdb -D /Library/PostgreSQL/12/data/
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
/Library/PostgreSQL/12/bin/pg_ctl: /Library/PostgreSQL/12/bin/pg_ctl: cannot execute binary file

反复出现的主题,这一切是什么“无法访问目录”?我正在运行 sudo 和 postgres 用户,就像我读过的所有内容中的其他人一样!为什么它在我的情况下不起作用?...

尝试#3

$ ls -la /Library/PostgreSQL/12/data/
ls: : Permission denied

有道理...我记得以前尝试访问该 /data 目录,但仅限于 postgres 用户。
所以让我尝试做我迄今为止尝试过的事情并尝试ls作为 postgres

$ sudo -u postgres ls -la /Library/PostgreSQL/12/data/
total 112
[...]

这是什么疯子?!它有效,我可以访问,但我无法运行启动数据库所需的任何命令!sudo 可以访问所有内容;postgres 可以访问该目录...

尝试#4

让我们检查一些其他的东西。

sudo -u postgres which pg_ctl
/Library/PostgreSQL/12/bin/pg_ctl

所以 postgres 有pg_ctl,但不能运行它。

也许让我们尝试作为我的用户帐户,忘记 postgres 用户

$ pg_ctl initdb --pgdata=/Library/PostgreSQL/12/data/
The files belonging to this database system will be owned by user "Freemium".
**This user must also own the server process.**

The database cluster will be initialized with locale "en_GB.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

initdb: error: could not access directory "/Library/PostgreSQL/12/data": Permission denied
pg_ctl: database system initialization failed

所以它不能是我的用户帐户,我什至不想拥有该进程,这就是 postgres 用户的用途。

尝试#5

让我们尝试使用 root - 在这一点上,为什么不呢。

$ sudo pg_ctl initdb --pgdata=/Library/PostgreSQL/12/data/
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

不,即使是root也不想要它。在这两种情况下,它都暗示它必须是 postgres 用户。那么为什么 tf 不起作用???

尝试#6

此时我只是想知道如果我运行原始stop命令会发生什么

$ sudo -u postgres pg_ctl -D /Library/PostgreSQL/12/data/ stop
could not identify current directory: Permission denied

嗯...再次使用当前目录权限...

经过所有这些尝试,如何简单地start使用 PostgreSQL 服务器?



postgresql mac-os-x
  • 1 个回答
  • 1773 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve