postgresql 更改用户的默认架构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44429178/
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-10-21 02:34:55  来源:igfitidea点击:

Change default schema for user

sqlpostgresqlpostgresql-9.5

提问by Oto Shavadze

create schema bla;

-- then create table table_name into this schema

Then I want change default schema for user (user is postgres)

然后我想更改用户的默认架构(用户是postgres

I do: ALTER ROLE postgres SET search_path TO bla;(Query returned successfully with no result).

我这样做:( ALTER ROLE postgres SET search_path TO bla;查询成功返回,没有结果)。

When I try SELECT * FROM table_namegives error relation "table_name" does not exist

当我尝试SELECT * FROM table_name给出错误时relation "table_name" does not exist

Though SELECT * FROM bla.table_nameworks fine.

虽然SELECT * FROM bla.table_name工作正常。

What is wrong in my attempt to change default schema for user?

我尝试更改用户的默认架构有什么问题?

回答by Vao Tsun

I think you need to relogin for that. With ALTER USER ... SETyou change

我认为您需要为此重新登录。随ALTER USER ... SET你而变

Session defaults for run-time configuration variables

运行时配置变量的会话默认值

Also from ALTER ROLE SETmanual:

也来自ALTER ROLE SET手册

Role-specific variable settings take effect only at login;

特定于角色的变量设置仅在登录时生效;

But don't apply changes to current session. If you want immediate change use:

但不要将更改应用于当前会话。如果您想立即更改使用:

SET search_path TO bla;

It will change path on session level

它将在会话级别更改路径