Windows 10 上的 Postgresql 14:pg_ctl.exe 返回的不是數據庫集群目錄
我在 Windows 10 機器上安裝了 postgresql 14。但是,我收到了這條消息:
C:\Program Files\PostgreSQL\14\bin > pg_ctl.exe start -D "C:\postgres" pg_ctl: directory "C:/postgres" is not a database cluster directory
安裝日誌文件在
%temp%\install-postgresql.log
最後顯示此文本:錯誤執行 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: 程序以錯誤退出程式碼結束執行安裝後步驟時出現問題。安裝可能無法正確完成 數據庫集群初始化失敗。從 C:\WINDOWS\System32\whoami 設置變數 whoami 腳本退出程式碼:0
我懷疑這可能是由於權限問題。
檢查故障排除指南here,它建議使用
cscript.exe
,但失敗了。
@LaurenzAlbe 評論成功了。
他應該得到所有的讚揚,但我會發布帶有命令輸出的答案,以防有人遇到同樣的問題並且它可以提供幫助。
首先,執行
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
然後使用以下命令啟動 PostgreSQL
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
不確定您的安裝出了什麼問題。
但我很確定那
"C:\postgres"
不是您的配置文件的目錄。那將是:"C:\Program Files\PostgreSQL\14\data"
.(應該與 相同
%postgresql_dir%\data
。)所以:pg_ctl.exe start -D "C:\Program Files\PostgreSQL\14\data"