1

I am setting up a website and am having some trouble restoring a database .dump file. I am using centos7, selinux, postgresql 9.4, and apache2.

This is my pg_hba.conf file.

enter image description here

This is the command I am trying to move the dump:

psql --single-transaction -U postgres db_name < dump_location

When I do this, I get the error:

Permission denied.

Am I missing something or is there someway I should alter my settings? Let me know if you need more information.

Thank you!

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73
bluepanda
  • 382
  • 2
  • 13
  • You should post the entire error message as it was output by psql. – Mike Shultz Jul 10 '15 at 22:37
  • What Linux user are you logged in as when running that command? Can you get a psql prompt if you just give `psql -U postgres db_name` by itself? – harmic Jul 10 '15 at 23:40
  • @Harmic I can get a psql prompt if I just give psql -U postgres db_name by itself. I am logged in as the postgres user when I am logged on – bluepanda Jul 11 '15 at 18:21
  • @Mike This is what the full message looks like: bash-4.2$ psql --single-transaction db_name < file.dump bash: file.dump: Permission denied – bluepanda Jul 11 '15 at 18:23
  • Then it looks like @Craig is right on this one, you do not have permissions to that file or the current directory you are in. This is not a psql problem but a linux filesystem permissions problem.. – Mike Shultz Jul 11 '15 at 19:28

2 Answers2

1

The operating system user you are running your shell as does not have permission to read the path dump_location.

Note that this is not necessarily the operating system user you run psql as. In a statement like:

sudo -u postgres psql mydb < /some/path

then /some/path is read as the current user, before sudo, not as user postgres, because it's the shell that performs the input redirection, not psql.

If, in the above example, you wanted to read the file as user postgres you would:

sudo -u postgres psql -f /some/path mydb

That instructs psql to open and read /some/path when it's started.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • When I check for permissions with ls -lZ file.dump, I get the following: -rw-r--r--. Doesn't this mean all other users have read permissions? – bluepanda Jul 13 '15 at 15:25
  • I seem to have answered my own question: the directory in which the file.dump is stored has the following permission: drwx------. I will try changing it with chmod. – bluepanda Jul 13 '15 at 15:28
0

Just make sure that you are using correct database user and you have at least read permission on the dump file.

"psql -d -U postgres -f "

will work.

Vipul Shukla
  • 165
  • 4