0
votes

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

1 Answers

0
votes

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