1

I have installed postgresql 14 on a Windows 10 machine. But, I'm getting this message:

C:\Program Files\PostgreSQL\14\bin > pg_ctl.exe start -D "C:\postgres" pg_ctl: directory "C:/postgres" is not a database cluster directory 

The installation log file at %temp%\install-postgresql.log shows this text at the very end:

Error running C:\WINDOWS\System32\cscript //NoLogo "C:\Program Files\PostgreSQL\14/installer/server/initcluster.vbs" "NT AUTHORITY\NetworkService" "postgres" "****" "C:\Users\nephewtom\AppData\Local\Temp/postgresql_installer_80ce3934c2" "C:\Program Files\PostgreSQL\14" "C:\Program Files\PostgreSQL\14\data" 5432 "DEFAULT" 0: Program ended with an error exit code Problem running post-install step. Installation may not complete correctly The database cluster initialisation failed. Setting variable whoami from C:\WINDOWS\System32\whoami Script exit code: 0

I suspect it may be due to a permissions issue.

Checking the troubleshoot guide here, it suggests to use cscript.exe, but that failed.

8
  • If the installer failed to run initdb, run it manually. You may also want to run pg_ctl register with the appropriate options to create a Windows service. Commented Mar 13, 2022 at 14:59
  • Yes, that made it, thank you very much @LaurenzAlbe ! Commented Mar 14, 2022 at 12:17
  • By the way, when creating a Windows service : .\pg_ctl.exe register -D c:\PostgreSQL\14\data -N postgresql -U nephewtom -P nephewtom -S auto -e postgresql pg_ctl: could not register service "postgresql": error code 1057 Commented Mar 14, 2022 at 12:49
  • Perhaps you don't have the required permissions, or there is already a service with that name. Commented Mar 14, 2022 at 14:11
  • Maybe you could try a binary install - if that can suit your needs? Commented Mar 28, 2022 at 23:36

2 Answers 2

3

@LaurenzAlbe comment made it.
He deserves all the credit, but I am posting the answer with commands output in case somebody has the same issue and it could help.

First, running initdb.exe :

C:\Program Files\PostgreSQL\14\bin> .\initdb.exe -D c:/PostgreSQL/14/data The files belonging to this database system will be owned by user "nephewtom". This user must also own the server process. The database cluster will be initialized with locale "English_United States.1252". The default database encoding has accordingly been set to "WIN1252". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory c:/PostgreSQL/14/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 ... Europe/Paris creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: ".\pg_ctl" -D "c:\PostgreSQL\14\data\\" -l logfile start 

Then starting PostgreSQL with pg_ctl.exe :

C:\Program Files\PostgreSQL\14\bin> .\pg_ctl.exe start -D c:\PostgreSQL\14\data waiting for server to start.... 2022-03-14 13:13:34.114 CET [1972] LOG: starting PostgreSQL 14.2, compiled by Visual C++ build 1914, 64-bit 2022-03-14 13:13:34.126 CET [1972] LOG: listening on IPv6 address "::1", port 5432 2022-03-14 13:13:34.126 CET [1972] LOG: listening on IPv4 address "127.0.0.1", port 5432 2022-03-14 13:13:34.219 CET [26212] LOG: database system was shut down at 2022-03-14 13:13:01 CET 2022-03-14 13:13:34.485 CET [1972] LOG: database system is ready to accept connections done server started 
0

Not sure what went wrong with your installation.
But I am pretty sure that "C:\postgres" is not the directory of your configuration files. That would be: "C:\Program Files\PostgreSQL\14\data".
(Should be the same as %postgresql_dir%\data.) So:

pg_ctl.exe start -D "C:\Program Files\PostgreSQL\14\data" 
1
  • I had already tried that and got the same error. Commented Mar 14, 2022 at 11:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.