简体   繁体   中英

pg_ctl.exe fails to start with custom postgresql.conf

I'm trying to setup a PS1 script to automated PostgreSQL installation.

  1. Stop PostgreSQL .\pg_ctl.exe -D "$PostgresInstallPath\data" stop
  2. Replace conf file Copy-Item -Path "$PSScriptRoot\postgresql.conf" -Destination "$PostgresInstallPath\data\postgresql.conf" -Force
  3. Start PostgreSQL .\pg_ctl.exe -D "$PostgresInstallPath\data" start

This always fails with my custom conf file, but always works with the default conf file. The file does not look incorrect when opening in text editor, so have no clue why it does not work.

Has anyone seen anything similar, or any thought on where I can go next to get it working?

The error log does not help, more than to refers to error on every row.

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'

Looking at the file generated by command: Get-Content.\postgresql.conf -Encoding Byte | Select-Object -First 10 Get-Content.\postgresql.conf -Encoding Byte | Select-Object -First 10 which generates a dump of the file,
you can see that the file is in UTF-16 BOM encoding:

255 254 35 0 45 0 45 0 45 0

because it starts from 255-254 characters (hex: FF-FE - the header for UTF-16 BOM in big-endian byte order).
Also it is seen that character # consists of two bytes 35+0 and all remaining - characters consist also of two bytes 45+0, so one character occupies 16 bits and this is for sure UTF-16 encoding.

PostgreSql most likely expects postgresql.conf file to be a normal ASCII file, not UTF-16 ,
so please change it's encoding to ASCII (or UTF-8) and this should fix the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM