Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a postgres command: could not identify current directory

I am able to run psql by doing the following:

Davids-d david$ psql --u postgres
Password for user postgres: 
psql (9.4.18)
Type "help" for help.

postgres=# 

However, when I run the following command, I get an error:

Davids-iMac:datadocs david$ sudo -u postgres psql -f resources/postgresql/initdb.sql
could not identify current directory: Permission denied

What does this mean, and how would I resolve this? Note that I do have the following var set:

david$ echo $PGDATA
/Users/david/PostgreSQL/data/pg94
like image 974
David542 Avatar asked May 16 '26 13:05

David542


1 Answers

The issue is the sudo -u postgres.

Your shell is running as you, but you're running the command as the postgres user. It does not have permission to see the file or even be in the current directory.

We can eliminate psql from the equation by just trying to read the file as the postgres user with sudo -u postgres cat resources/postgresql/initdb.sql. You should get the same error.

There's two things you have to do...

  1. cd to a directory that the postgres user can be in.
  2. Put the file in a place the postgres user can access.

/tmp, for example.

like image 170
Schwern Avatar answered May 18 '26 21:05

Schwern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!