문제

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;

도움이 되었습니까?

해결책

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.

다른 팁

Step 1->First of all disconnect from the database that has to be renamed

Step 2-> disconnect all the clients from the database to be renamed

SELECT pg_terminate_backend(pid )
FROM pg_stat_activity
WHERE pid <> pg_backend_pid( )
    AND datname = 'db_name_to_be_renamed';

Step 3->Then rename the database

ALTER DATABASE "db_name_to_be_renamed" RENAME TO "new_db_name";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top