9

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

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Your first two sentences and the first point in your list have just solved my issue trying to start the database for 4 damn days. If only this question/answer came up on search engine queries for "starting postgres db" I'm sure many people wouldn't be banging their heads as I've seen a lot have the same issues in regards to starting the Postgres DB via terminal
7

Your command seems wrong, try this:

sudo psql -U postgres -f resources/postgresql/initdb.sql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.