Postgresql 14 on Windows 10: pg_ctl.exe returns is not a database cluster directory

  • 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 , it suggests to use cscript.exe, but that failed.

  • @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 "", 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  
    server started

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2