postgresql - psql - 无法执行命令 - 权限被拒绝错误
问题描述
尝试使用 psql 运行 SQL 脚本时,出现权限被拒绝错误。
随后的步骤 -
- 打开正常的 Bash 交互式 shell
- 运行命令如下
sudo -u postgres -s /bin/bash
- 尝试运行以下 pgsql - 我提供了对 pega 文件夹的读写访问权限;将 pgsql 文件移动到 postgres 库还需要做什么。
/Library/PostgreSQL/12/bin/psql -U dbusername dbpassword </Users/rr/Documents/pega/pega8db.pgsql
得到以下错误
bash: /Users/rr/Documents/pega/pega8db.pgsql: Permission denied
Ps -ef 的结果
502 129 1 0 上午 8:07 ?? 0:00.09 /Library/PostgreSQL/12/bin/postmaster -D/Library/PostgreSQL/12/data 502 281 129 0 8:07AM ?? 0:00.00 postgres:记录器
502 283 129 0 8:07AM ?? 0:00.01 postgres:检查点
502 284 129 0 8:07AM ?? 0:00.04 postgres:后台编写器
502 285 129 0 8:07AM ?? 0:00.02 postgres: walwriter
502 286 129 0 8:07AM ?? 0:00.04 postgres: autovacuum 启动器
502 287 129 0 8:07AM ?? 0:00.18 postgres:统计收集器
502 288 129 0 8:07AM ?? 0:00.00 postgres:逻辑复制启动器
501 942 1 0 上午 8 点 29 分 ?? 0:11.47 /Library/PostgreSQL/12/pgAdmin 4.app/Contents/MacOS/pgAdmin4 502 947 129 0 8:29AM ?? 0:00.02 postgres: postgres postgres ::1(49607) 空闲 502 949 129 0 8:29AM ?? 0:00.04 postgres: postgres pega ::1(49623) idle 501 957 826 0 8:30AM ttys000 0:00.00 grep -i postgres
解决方案
首先:检查文件本身的权限:
ls -al /Users/rr/Documents/pega/pega8db.pgsql
然后您可以通过执行以下操作添加读取和执行权限:(
sudo chmod a+rx /Users/rr/Documents/pega/pega8db.pgsql
这将为每个人提供读取权限,因此如果它的多用户系统,您可能希望稍后恢复权限)。
您是否能够使用该psql
工具连接到数据库并获得 psql 提示符,或者这也失败了?我假设您的.pgsql
文件本质上是 sql 脚本,对吧(某种导出)?
尝试像这样运行:
psql -d database_name -a -f /Users/rr/Documents/pega/pega8db.pgsql
推荐阅读
- java - 在没有方法体的情况下在 Eclipse 中导出 JAR 文件
- ansible - Ansible 调试 INI 格式
- python - 如何理解联合图中的 p 值?
- python-3.x - Drf令牌认证密码重置
- alexa - 由于无效正文 ASK CLI 导致解析错误
- c# - C# - 从另一个方法停止计时器
- sql-server - 关于运行总计的 tsql 帮助
- null - 无法确定 R 数据框中的空白、空值、na 或其他任何类型
- reactjs - 通过 refs 访问 phone-react-input-2 组件时,我没有得到更新的状态
- office-js - Outlook 插件 - 需要获取打开/读取 UI 的电子邮件数据