简体   繁体   中英

initdb: error: could not create directory “./PostgreSQL”: Permission denied

It is my first time setting up a database (postgresql 12) on my windows 8.1

It's been 4 days of struggling to find a solution from many related questions in this field but not successful to find the answer (whether I didn't understand them or they didn't work in my case).

So, here, I will explain, step by step, what I did and what errors I got in each phase (They may not affect each other but I mention all the errors):

When I installed PostgreSQL as an administrator, at the end of the process I got this error: "Failed to load SQL modules into the database cluster" I reinstalled twice but it seemed to pop up every time. Here, in this post, I found somebody who faced the same problem, but I didn't technically understand what is the solution, unfortunately: Failed to load sql modules into the database cluster during PostgreSQL Installation. thus, I just skipped it and everything seemed okay.

Then I set the PATH in advanced system settings-->Environment variables (in both user variables and system variables boxes) like this: ";C:\Program Files\PostgreSQL\12\bin;C:\Program Files\PostgreSQL\12\lib"

After this step, I opened a terminal using ctrl+R and entered cmd.exe then entered these codes:

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

Here I got this message:

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:

After entering my password, I got this error:

    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

But when entering the suggested code (no matter using logfile or other files names) I keep getting this message:

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

On the other hand, when I tried pgAdmin4 browser interface, when I right-clicked on servers-->create-->server in the popped up window I filled these fields:

On General tab I filled the "Name" box as "dbserver" my "Username" was set as "postgres", then on Connection tab I set "Host" to "localhost" and "Password" as what I set before.

Here is the error I got:

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?

Can somebody help me out with this problem?

Thank you

So, I found the answer, and I want to share it. I opened the postgres.conf file and comment out logging_collector, log_directory, and log_destination. I saved the file.

Then in the terminal, I typed the suggested piece of code like below:

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

And the server started.

Now in the pgAdmin4 browser, the problem is gone too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM