我无法在本地服务器上连接到我自己的postgres数据库.我搜索了一些类似的问题并提出了这本手册 https://help.ubuntu.com/stable/serverguide/postgresql.html
所以:
pg_hba.conf 说:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 trust
Run Code Online (Sandbox Code Playgroud)
然后我创建一个用户并为其分配密码:
postgres=# create role asunotest;
CREATE ROLE
postgres=# alter role asunotest with encrypted password '1234';
ALTER ROLE
Run Code Online (Sandbox Code Playgroud)
但它不允许我进入:
-bash-4.2$ psql -h 127.0.0.1 -U asunotest
Password for user asunotest: 1234
psql: FATAL: role "asunotest" is not permitted to log …Run Code Online (Sandbox Code Playgroud) 我正在尝试从命令行创建数据库.我的SO是centos,postgres是9.2
sudo -u postgres psql createdb test
Password for user test:
Run Code Online (Sandbox Code Playgroud)
为什么用户问我?
我正在寻找使用 Vagrant 设置 Rails 环境,为此目的,它是通过 bash shell 方法提供的框,其中包括这一行:
sudo -u postgres createuser <superuserusername> -s with password '<superuserpassword>'
但我收到一个配置错误,
createuser: too many command-line arguments (first is "with")
你能帮我用正确的语法来创建一个带密码的超级用户吗?谢谢
数据库idd所有者是角色idd_owner.
数据库有2个数据模式:public和firma1.用户可能直接或间接地在此数据库和对象中分配了权限.用户不是任何对象的所有者.它只授予了权利.
如何删除这样的用户?
我试过了
revoke all on all tables in schema public,firma1 from "vantaa" cascade;
revoke all on all sequences in schema public,firma1 from "vantaa" cascade;
revoke all on database idd from "vantaa" cascade;
revoke all on all functions in schema public,firma1 from "vantaa" cascade;
revoke all on schema public,firma1 from "vantaa" cascade;
revoke idd_owner from "vantaa" cascade;
ALTER DEFAULT PRIVILEGES IN SCHEMA public,firma1 revoke all ON TABLES from "vantaa";
DROP ROLE if exists …Run Code Online (Sandbox Code Playgroud) 我试图删除PostgreSQL用户:
DROP USER ryan;
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
Run Code Online (Sandbox Code Playgroud)Error in query: ERROR: role "ryan" cannot be dropped because some objects depend on it DETAIL: privileges for database mydatabase
我从这些线程中寻找解决方案:
还是有同样的错误.
在我向用户"ryan"授予所有权限后,会发生这种情况:
GRANT ALL PRIVILEGES ON DATABASE mydatabase ON SCHEMA public TO ryan;
Run Code Online (Sandbox Code Playgroud) 数据库“mydb”由角色“mydb_owner”拥有。
用户“currentuser”尝试使用以下命令从此数据库中删除角色“roletodelete”
revoke all on all tables in schema public,firma1 from "roletodelete" cascade;
revoke all on all sequences in schema public,firma1 from "roletodelete" cascade;
revoke all on database mydb from "roletodelete" cascade;
revoke all on all functions in schema public,firma1 from "roletodelete" cascade;
revoke all on schema public,firma1 from "roletodelete" cascade;
revoke mydb_owner from "roletodelete" cascade;
ALTER DEFAULT PRIVILEGES IN SCHEMA public,firma1 revoke all ON TABLES from "roletodelete";
GRANT "roletodelete" TO "currentuser";
reassign owned by "roletodelete" to mydb_owner;
drop owned …Run Code Online (Sandbox Code Playgroud) 我正在使用 PostgreSQL 10.4,我发现了一个奇怪的行为。
如果我们创建一个角色并将其授予CONNECT数据库:
CREATE ROLE dummy;
GRANT CONNECT ON DATABASE test TO dummy;
Run Code Online (Sandbox Code Playgroud)
然后我们不能删除这个角色,即使它根本不拥有任何对象,这个命令:
DROP ROLE dummy;
Run Code Online (Sandbox Code Playgroud)
提高:
ERROR: role "dummy" cannot be dropped because some objects depend on it
SQL state: 2BP01
Detail: privileges for database test
Run Code Online (Sandbox Code Playgroud)
文档有点误导:
2B 类 — 依赖特权描述符仍然存在
2B000dependent_privilege_descriptors_still_exist
2BP01dependent_objects_still_exist
它说依赖对象仍然存在,但似乎没有依赖于这个特定角色的对象,它在数据库上没有任何东西。
无论如何,如果我们撤销CONNECT特权,那么角色可以被删除:
REVOKE CONNECT ON DATABASE test FROM dummy;
DROP ROLE dummy;
Run Code Online (Sandbox Code Playgroud)
我刚刚检查了 PostgreSQL 9.5 上也存在该行为。我觉得有点奇怪,我不明白为什么这个特定的特权会导致删除角色失败。
其他观察
这真的是阻塞,因为我们既不能重新分配这个对象:
REASSIGN OWNED BY dummy TO postgres;
Run Code Online (Sandbox Code Playgroud)
也不丢弃对象:
DROP OWNED …Run Code Online (Sandbox Code Playgroud) postgresql ×7
sql ×3
roles ×2
sql-revoke ×2
dependencies ×1
plpgsql ×1
privileges ×1
sql-grant ×1
ubuntu ×1
vagrant ×1