Reputation: 111
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;
Upvotes: 1
Views: 5354
Reputation: 361
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";
Upvotes: -1
Reputation: 324475
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.
Upvotes: 2