Postgresql – Cannot rename database (the user in –username is the owner)

postgresqlpsql

I connect with psql and list my databases:

                                          List of databases
           Name            |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
---------------------------+----------+----------+-------------+-------------+-----------------------
 accyem_20150422           | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 accyem_template           | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 clinicama_template        | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 intercontinental_template | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 pijalarga                 | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 postgres                  | postgres | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 sbu_template              | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 sf_20150505               | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 sf_20150527               | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 sf_template               | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 tarpuq_template           | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 
 template0                 | postgres | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | =c/postgres          +
                           |          |          |             |             | postgres=CTc/postgres
 template1                 | postgres | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | =c/postgres          +
                           |          |          |             |             | postgres=CTc/postgres
 yucha                     | openerp  | UTF8     | es_EC.UTF-8 | es_EC.UTF-8 | 

I am interested on sf_template database.

I want to run the following command:

PGPASSWORD=mypassword  psql --username=openerp --dbname=sf_template --no-password --command="alter database sf_template rename to sf_template_20150605111128"

But get the following error:

ERROR: current database cannot be renamed

As I see in the returned results, the user I log in with is the owner of the database. Why can't I rename the database?

Best Answer

You cannot rename a database you're connected to. I did not know that point or even considered it.