【发布时间】:2021-04-08 22:59:14
【问题描述】:
下面我正在创建数据库mydb 并填充它。请注意,我执行的最后一步是为postgres 设置密码。这只是为了避免在前面的步骤中提示密码。
我按照其他StackOverflow 帖子中的步骤操作,即在TABLES、SEQUENCES 和FUNCTIONS 上发布GRANT ALLs,但我仍然面临以下问题。
mydb.sh:
su - postgres <<xEOFx
set +H
psql -c "CREATE DATABASE mydb"
psql -c "CREATE USER user01 WITH ENCRYPTED PASSWORD 'SomePassword'"
psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public to user01"
psql -c "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public to user01"
psql -c "GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public to user01"
psql --dbname=mydb --username=postgres -f /tmp/mydb.sql
psql -c "GRANT ALL PRIVILEGES ON DATABASE mydb TO user01"
psql -c "ALTER USER postgres WITH PASSWORD 'AnotherPassword'"
exit
xEOFx
脚本没有失败,但我也无法以user01 的身份访问mydb:
jdoe$ psql --username=user01 --dbname=mydb
Password for user user01:
psql (13.2)
Type "help" for help.
mydb=> \c
You are now connected to database "mydb" as user "user01".
mydb=> \dt
List of relations
Schema | Name | Type | Owner
--------+---------------+-------+----------
public | some_table | table | postgres
(1 rows)
mydb=> select * from some_table;
ERROR: permission denied for table some_table
mydb=>
SIDEBAR:我确实注意到some_table 的所有者是postgres,并且希望它是user01。也许这可能是问题的一部分。
我错过了什么?
提前谢谢你。
编辑:请注意,我也尝试在 GRANT ALL 语句之前运行 psql --dbname=mydb --username=postgres -f /tmp/mydb.sql。
【问题讨论】:
标签: postgresql psql ddl