Postgresql – rename database in psql

postgresql

Could anybody help me to rename database in postgresql from the Linux shell

ALTER DATABASE name RENAME TO newname

The above statement doesn't execute

Best Solution

This may be a stupidly obvious question. Are you running psql as the postgres user?

e.g.

$ sudo -u postgres psql
# alter database FOO rename to BAR;
# \q