psql - unable to execute the command - permission denied error

試著忘記壹切 提交于 2020-06-01 06:13:45

问题


When trying to run a SQL script using psql I am getting permission denied error.

Steps followed -

  1. opened up normal Bash interactive shell
  2. Ran the command as below
sudo -u postgres -s /bin/bash
  1. tried running the below pgsql - I provided the read write access to the pega folder; what else needs to be done to move the pgsql file to postgres library.
/Library/PostgreSQL/12/bin/psql -U dbusername dbpassword </Users/rr/Documents/pega/pega8db.pgsql

got the below error

bash: /Users/rr/Documents/pega/pega8db.pgsql: Permission denied

Result from Ps -ef

502 129 1 0 8:07AM ?? 0:00.09 /Library/PostgreSQL/12/bin/postmaster -D/Library/PostgreSQL/12/data 502 281 129 0 8:07AM ?? 0:00.00 postgres: logger
502 283 129 0 8:07AM ?? 0:00.01 postgres: checkpointer
502 284 129 0 8:07AM ?? 0:00.04 postgres: background writer
502 285 129 0 8:07AM ?? 0:00.02 postgres: walwriter
502 286 129 0 8:07AM ?? 0:00.04 postgres: autovacuum launcher
502 287 129 0 8:07AM ?? 0:00.18 postgres: stats collector
502 288 129 0 8:07AM ?? 0:00.00 postgres: logical replication launcher
501 942 1 0 8:29AM ?? 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) idle 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


回答1:


First: check permissions for the file itself: ls -al /Users/rr/Documents/pega/pega8db.pgsql then you can add read & execute permissions by doing: sudo chmod a+rx /Users/rr/Documents/pega/pega8db.pgsql (this will give read to everyone, so if its multiuser system, you may want to revert perms later).

Are you able to connect to database using the psql tool and get the psql prompt, or is that failing too? I assume that your .pgsql file is essentially sql script, right (some kind of export)?

Try to run like this: psql -d database_name -a -f /Users/rr/Documents/pega/pega8db.pgsql



来源:https://stackoverflow.com/questions/61634805/psql-unable-to-execute-the-command-permission-denied-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!