1

我正在尝试设置一个 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 文件。该文件在文本编辑器中打开时看起来并不正确,因此不知道为什么它不起作用。

有没有人看到过类似的东西,或者对我下一步可以去哪里让它工作有任何想法?

错误日志没有帮助,不仅仅是指每一行的错误。

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'
4

1 回答 1

-1

查看由 command: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 的大端字节顺序的标头)。
还可以看出,字符#由两个字节 35+0 组成,所有剩余的-字符也由两个字节 45+0 组成,因此一个字符占用 16 位,这肯定是 UTF-16 编码。

PostgreSql 很可能期望postgresql.conf文件是普通的 ASCII 文件,而不是 UTF-16
所以请将其编码更改为 ASCII(或 UTF-8),这应该可以解决问题。

于 2020-06-20T10:26:42.847 回答