postgresql - PostgreSQL 13 :: 错误:表'mydb'的权限被拒绝
问题描述
下面我正在创建数据库mydb
并填充它。请注意,我执行的最后一步是为postgres
. 这只是为了避免在前面的步骤中出现密码提示。
我按照其他StackOverflow
帖子中的步骤进行操作,即发出GRANT ALL
s on和TABLES
,但仍然面临以下问题。SEQUENCES
FUNCTIONS
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
该脚本没有失败,但我也无法访问mydb
as user01
:
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=>
边栏:我确实注意到它的所有者,并且希望它some_table
是。也许这可能是问题的一部分。postgres
user01
我错过了什么?
先感谢您。
编辑:请注意,我也尝试在语句psql --dbname=mydb --username=postgres -f /tmp/mydb.sql
之前运行。GRANT ALL
解决方案
您正在授予数据库 postgres 中公共模式中的表、序列和函数的权限,而不是 mydb。默认情况下,psql 将连接到与当前用户同名的数据库,在本例中为 postgres。-d mydb
确保通过添加到 psql 命令来运行 mydb中的命令。
推荐阅读
- android - android studio 3.6 中的 Gradle 同步失败
- c - 如何编写一个以 RGB 缓冲区为输入的 gstreamer 插件?
- composer-php - Seld\JsonLint\ParsingException "/root/.composer/auth.json" 安装后不包含有效的 JSON
- c++ - C++ 中带有 Clion 的简单程序“在 '&&' 标记之前需要 `,' 或 `...'”
- jasmine - 量角器 - 茉莉花类型错误:无法读取未定义的属性“结果”
- netlogo - 在海龟的完整有向加权图中删除多个链接
- python - 使用 Selenium/Python 在 Datepicker 中更改日期
- php - 从具有不同时区的表中获取当前日期记录
- arrays - Swift - Tableview 无法通过搜索查询正确更新
- java - 我的输出只显示数组对象中的最后一个输入