【问题标题】:psql - unable to execute the command - permission denied errorpsql - 无法执行命令 - 权限被拒绝错误
【发布时间】:2020-05-06 12:06:20
【问题描述】:

当尝试使用 psql 运行 SQL 脚本时,出现权限被拒绝错误。

接下来的步骤 -

  1. 打开了正常的 Bash 交互式 shell
  2. 运行如下命令
sudo -u postgres -s /bin/bash
  1. 尝试运行以下 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:07 ?? 0:00.00 postgres:记录器
502 283 129 0 上午 8:07 ?? 0:00.01 postgres:检查指针
502 284 129 0 上午 8:07 ?? 0:00.04 postgres:后台编写器
502 285 129 0 上午 8:07 ?? 0:00.02 postgres: walwriter
502 286 129 0 上午 8:07 ?? 0:00.04 postgres:自动真空启动器
502 287 129 0 上午 8:07 ?? 0:00.18 postgres:统计收集器
502 288 129 0 上午 8:07 ?? 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:29 ?? 0:00.02 postgres: postgres postgres ::1(49607) 空闲 502 949 129 0 上午 8:29 ?? 0:00.04 postgres: postgres pega ::1(49623) 空闲 501 957 826 0 8:30 AM ttys000 0:00.00 grep -i postgres

【问题讨论】:

    标签: postgresql psql


    【解决方案1】:

    首先:检查文件本身的权限: 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

    【讨论】:

    • 感谢 alfheim - 我修改了权限.. 现在我收到以下错误。 psql:错误:无法连接到服务器:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接?我提供的命令 - psql -d pega -a -f /Users/rr/Documents/pega/pega8db.pgsql
    • 好的,看起来你的机器上没有运行 postgres。你能运行:ps -ef | grep -i postgres 看看你是否有 postrgesql 实例正在运行?另外 - 你的操作系统是什么?马科斯?
    • 我刚刚运行了查询 - 请在此处找到描述中附加的结果..
    猜你喜欢
    • 2023-02-08
    • 2018-07-03
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多