user16662077
user16662077

Reputation:

Error in run sql file in postgres | No such file or directory

Problem

when in tried run sql file in psql shell...

give "No such file or directory" error!

$ ls
config.sql  config.yaml

$ sudo -i -u postgres psql

postgres=# \i config.sql

config.sql: No such file or directory

thanks for your reply!

Quick solution:

-i => goes to user's home directory!

as result ./config.sql address is incorrect!

just use

$ psql -U <user_name>

postgres=# \i config.sql

Upvotes: 2

Views: 3222

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247625

man sudo tells you:

-i, --login

Run the shell specified by the target user's password database entry as a login shell. This means that login-specific resource files such as .profile, .bash_profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution via the shell's -c option.

In particular, that will set your current working directory to the home directory of user postgres.

If you want to avoid that, don't use '-i'.

Upvotes: 1

Related Questions