initdb:错误:无法创建目录“ ./PostgreSQL”:权限被拒绝

时间:2020-07-04 12:48:38

标签: django database postgresql pgadmin-4

这是我第一次在Windows 8.1上设置数据库(PostgreSQL 12)

从该领域的许多相关问题中寻找解决方案已经花费了4天的时间,但未能成功找到答案(无论是我听不懂还是在我的情况下他们没有用)。

因此,在这里,我将逐步说明每个阶段我做了什么以及遇到什么错误(它们可能不会互相影响,但我会提及所有错误):

当我以管理员身份安装PostgreSQL时,在过程结束时出现以下错误:“无法将SQL模块加载到数据库集群中”,我重新安装了两次,但每次都弹出。在这里,在这篇文章中,我发现有人遇到相同的问题,但是不幸的是,我在技术上不了解解决方案:在PostgreSQL安装期间无法将sql模块加载到数据库集群中。因此,我只是跳过了它,一切似乎都还好。

然后,在高级系统设置中设置PATH->环境变量(在用户变量和系统变量框中),如下所示:“; C:\ Program Files \ PostgreSQL \ 12 \ bin; C:\ Program Files \ PostgreSQL \ 12 \ lib“

此步骤之后,我使用ctrl + R打开一个终端并输入cmd.exe,然后输入以下代码:

> cd C:\Program Files\PostgreSQL\12\bin
> initdb -U postgres -A password -E utf8 -W -D .\PostgreSQL\12\data

我在这里收到此消息:

The files belonging to this database system will be owned by user "pc".
This user must also own the server process.

The database cluster will be initialized with locale "English_United States.1252".
The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password:
Enter it again:

输入密码后,出现此错误:

    The files belonging to this database system will be owned by user "pc".
This user must also own the server process.

The database cluster will be initialized with locale "English_United 
States.1252".
The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password:
Enter it again:

creating directory /PostgreSQL/12/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... windows
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Tehran
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D ^"^\PostgreSQL^\12^\data^" -l logfile start

但是在输入建议的代码时(无论使用日志文件还是其他文件名),我总是收到此消息:

waiting for server to start....Access is denied.
 stopped waiting
pg_ctl: could not start server
Examine the log output.

另一方面,当我尝试使用pgAdmin4浏览器界面时,当我右键单击服务器->创建->在弹出窗口中的服务器时,我填写了以下字段:

在“常规”选项卡上,将“名称”框填充为“ dbserver”,将“用户名”设置为“ postgres”,然后在“连接”选项卡上,将“主机”设置为“ localhost”,将“密码”设置为之前的设置

这是我得到的错误:

Unable to connect to server: could not connect to server: Connection refused (0x0000274D/10061) Is 
the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not 
connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" 
(127.0.0.1) and accepting TCP/IP connections on port 5432?

有人可以帮我解决这个问题吗?

谢谢

1 个答案:

答案 0 :(得分:0)

因此,我找到了答案,并且想分享。我打开了postgres.conf文件,并注释了logging_collector,log_directory和log_destination。我保存了文件。

然后在终端中,输入如下所示的建议代码:

pg_ctl -D ^"^\PostgreSQL^\12^\data^" start

服务器启动。

现在在pgAdmin4浏览器中,问题也消失了。

相关问题