簡體   English   中英

pg_ctl.exe 無法以自定義 postgresql.conf 啟動

[英]pg_ctl.exe fails to start with custom postgresql.conf

我正在嘗試設置一個 PS1 腳本來自動安裝 PostgreSQL。

  1. 停止 PostgreSQL .\pg_ctl.exe -D "$PostgresInstallPath\data" stop
  2. 替換conf文件Copy-Item -Path "$PSScriptRoot\postgresql.conf" -Destination "$PostgresInstallPath\data\postgresql.conf" -Force
  3. 啟動 PostgreSQL .\pg_ctl.exe -D "$PostgresInstallPath\data" start

我的自定義 conf 文件總是失敗,但總是使用默認的 conf 文件。 該文件在文本編輯器中打開時看起來並不正確,因此不知道為什么它不起作用。

有沒有人見過類似的東西,或者有什么想法我可以在 go 旁邊讓它工作嗎?

錯誤日志沒有幫助,不僅僅是指每一行的錯誤。

2020-06-20 03:43:09.133 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 1, near e
nd of line
2020-06-20 03:43:09.134 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 2, near token ""
2020-06-20 03:43:09.134 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 3, near token ""
2020-06-20 03:43:09.134 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 4, near token ""
2020-06-20 03:43:09.134 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 5, near token ""
2020-06-20 03:43:09.134 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 6, near token ""
2020-06-20 03:43:09.134 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 7, near token ""
2020-06-20 03:43:09.134 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 8, near token ""
2020-06-20 03:43:09.135 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 9, near token ""
2020-06-20 03:43:09.136 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 10, near token ""
2020-06-20 03:43:09.136 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 11, near token ""
2020-06-20 03:43:09.137 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 12, near token ""
2020-06-20 03:43:09.138 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 13, near token ""
2020-06-20 03:43:09.139 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 14, near token ""
2020-06-20 03:43:09.139 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 15, near token ""
2020-06-20 03:43:09.139 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 16, near token ""
2020-06-20 03:43:09.139 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 17, near token ""
2020-06-20 03:43:09.141 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 18, near token ""
2020-06-20 03:43:09.142 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 19, near token ""
2020-06-20 03:43:09.142 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 20, near token ""
2020-06-20 03:43:09.142 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 21, near token ""
2020-06-20 03:43:09.142 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 22, near token ""
2020-06-20 03:43:09.143 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 23, near token ""
2020-06-20 03:43:09.143 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 24, near token ""
2020-06-20 03:43:09.143 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 25, near token ""
2020-06-20 03:43:09.143 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 26, near token ""
2020-06-20 03:43:09.143 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 27, near token ""
2020-06-20 03:43:09.143 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 28, near token ""
2020-06-20 03:43:09.144 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 29, near token ""
2020-06-20 03:43:09.144 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 30, near token ""
2020-06-20 03:43:09.144 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 31, near token ""
2020-06-20 03:43:09.144 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 32, near token ""
2020-06-20 03:43:09.145 GMT [2104] LOG:  syntax error in file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" line 33, near token ""
2020-06-20 03:43:09.145 GMT [2104] FATAL:  configuration file "C:/Program Files/PostgreSQL/11/Data/postgresql.conf" contains errors

postgresql.conf:

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
listen_addresses = '*'      # what IP address(es) to listen on;
port = 5432             # (change requires restart)
max_connections = 100           # (change requires restart)
#------------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#------------------------------------------------------------------------------
dynamic_shared_memory_type = windows    # the default is the first option
#------------------------------------------------------------------------------
# WRITE-AHEAD LOG
#------------------------------------------------------------------------------
max_wal_size = 1GB
min_wal_size = 80MB
#------------------------------------------------------------------------------
# REPORTING AND LOGGING
#------------------------------------------------------------------------------
log_destination = 'stderr'      # Valid values are combinations of
logging_collector = on      # Enable capturing of stderr and csvlog
log_file_mode = 0640            # creation mode for log files,
log_timezone = 'CET'
#------------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#------------------------------------------------------------------------------
datestyle = 'iso, mdy'
timezone = 'CET'
lc_messages = 'English_United States.1252'          # locale for system error message
lc_monetary = 'English_United States.1252'          # locale for monetary formatting
lc_numeric = 'English_United States.1252'           # locale for number formatting
lc_time = 'English_United States.1252'              # locale for time formatting
default_text_search_config = 'pg_catalog.english'

查看命令生成的文件: Get-Content.\postgresql.conf -Encoding Byte | Select-Object -First 10 Get-Content.\postgresql.conf -Encoding Byte | Select-Object -First 10生成文件的轉儲,
您可以看到該文件采用UTF-16 BOM編碼:

255 254 35 0 45 0 45 0 45 0

因為它從 255-254 個字符開始(十六進制: FF-FE - UTF-16 BOM 的 header 以大端字節序排列)。
還可以看出,字符#由兩個字節 35+0 組成,所有剩余-字符也由兩個字節 45+0 組成,因此一個字符占用 16 位,這肯定是 UTF-16 編碼。

PostgreSql 最有可能期望postgresql.conf文件是普通的 ASCII 文件,而不是 UTF-16
所以請將其編碼更改為 ASCII(或 UTF-8),這應該可以解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM