Search code examples
command-linerenamepostgresql-9.1alter

rename postgresql database from command line


I run this command from a bat-file:

start/wait/d "C:\Program Files\PostgreSQL\9.1\bin\" psql.exe --port 5432 --username postgres --dbname alter_db --file ./batch/rename_database.sql

And I get this log-error:

CEST ERROR: syntax error at or near

"ALTER" at character 1 CEST STATEMENT: ALTER DATABASE postgres RENAME TO postgres_old;

rename_database.sql has the following content: ALTER DATABASE postgres RENAME TO postgres_old;


Solution

  • I'd say your file ./batch/rename_database.sql was created with a unicode byte-order mark. psql doesn't like this. Remove the BOM and try again.

    I quote the linked article:

    The UTF-8 representation of the BOM is the byte sequence 0xEF,0xBB,0xBF. A text editor or web browser interpreting the text as ISO-8859-1 or CP1252 will display the characters  for this.