Question

According to PostgreSQL documentation you can rename a database by:

ALTER DATABASE name RENAME TO newname

When I type:

ALTER DATABASE popbio-v4.1.1-VB-2014-04-prod-03 RENAME TO popbio-v4.1.1-VB-2014-04-prod-04

There is no error and nothing changes. Maybe it is because there are two databases with the same name but with different users, and PostgreSQL does not know which user's database I am trying to rename?

How do I specify to PostgreSQL which user's database I am trying to rename? Or is this even the problem?

Was it helpful?

Solution

Please try:

ALTER DATABASE "popbio-v4.1.1-VB-2014-04-prod-03" RENAME TO "popbio-v4.1.1-VB-2014-04-prod-04";

this should work. At least it did locally:

postgres=# create database "popbio-v4.1.1-VB-2014-04-prod-03";
CREATE DATABASE
postgres-# \l
...  
 popbio-v4.1.1-VB-2014-04-prod-03 | postgres      | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | 
...
postgres=# ALTER DATABASE "popbio-v4.1.1-VB-2014-04-prod-03" RENAME TO "popbio-v4.1.1-VB-2014-04-prod-04";
ALTER DATABASE
postgres=# \l
...
 popbio-v4.1.1-VB-2014-04-prod-04 | postgres      | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | 
... 

Also on PostgreSQL you don't have user databases. Users can only have rights on special databases or can own them. Of course you cannot do this as a normal user without any gratings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top