postgresql 在 psql 中重命名数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/593905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:12:35  来源:igfitidea点击:

rename database in psql

postgresql

提问by

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

有人可以帮我从 Linux shell 重命名 postgresql 中的数据库吗

ALTER DATABASE name RENAME TO newname

The above statement doesn't execute

上面的语句不执行

回答by GaZ

Which version of postgresql? From the 8.1 Documentation:

哪个版本的postgresql?从8.1 文档

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.)

ALTER DATABASE name 重命名为新名称;

只有数据库所有者或超级用户才能重命名数据库;非超级用户所有者还必须具有 CREATEDB 权限。无法重命名当前数据库。(如果需要,请连接到不同的数据库。)

回答by user6856

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

这可能是一个愚蠢而明显的问题。您是否以 postgres 用户身份运行 psql?

e.g.

例如

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

回答by CountZero

You might need priviliges to renmae db. Only db owner or super user can do that, owner also needs a createdb priv.

您可能需要 renmae db 的权限。只有数据库所有者或超级用户可以这样做,所有者还需要一个 createdb priv。

Also the database you're connected to cannot be renamed, you need to connect to a different one

此外,您连接的数据库无法重命名,您需要连接到其他数据库

回答by Max Alexander Hanna

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);

您无法重命名所连接的数据库。在更改 dbname 之前,请确保您已断开连接。在 PGAdmin 中,您只需右键单击数据库本身,转到属性,然后从那里重命名即可。正如其他人指出的那样,您也可以尝试以下命令:ALTER DATABASE (DB NAME) RENAME TO (NEW DB NAME);

回答by NISHANTH SURESH

Below given are the steps for renaming the database in postgresql.

下面给出了在 postgresql 中重命名数据库的步骤。

1) Right click on database and choose refresh.
2) Right click again and choose properties option.
3) Under the properties tab, you can change the name with the one that you desire.

1) 右键单击​​数据库并选择刷新。
2) 再次右键单击并选择属性选项。
3) 在属性选项卡下,您可以使用您想要的名称更改名称。