In Object Explorer, expand Databases, right-click the database to rename, and then select Rename. If the database was your default database, see Reset your default database after rename. Refresh the database list in Object Explorer.
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
Which version of postgresql? From the 8.1 Documentation:
ALTER DATABASE name RENAME TO newname;
Only the database owner or a superuser can rename a database; non-superuser owners must also have the CREATEDB privilege. The current database cannot be renamed. (Connect to a different database if you need to do that.)
You might need priviliges to renmae db. Only db owner or super user can do that, owner also needs a createdb priv.
Also the database you're connected to cannot be renamed, you need to connect to a different one
You cannot rename a database you are connected to. Make sure you are disconnected before changing the dbname. In PGAdmin, you can just right-click on the database itself, go to properties, and rename it from there. As others have pointed out, you may also try the command : ALTER DATABASE (DB NAME) RENAME TO (NEW DB NAME);
Disconnect database (Ctrl + F2
in DataGrip)
And then:
$ psql -U postgres
postgres=# ALTER DATABASE db_a RENAME TO db_b;
GL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With