2

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
2
  • 3
    You switched the current directory when you ran sudo -i Commented Aug 18, 2021 at 12:39
  • @a_horse_with_no_name problem solved! thanks Commented Aug 18, 2021 at 12:50

1 Answer 1

1

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'.

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

2 Comments

Where is the home directory of user postgres?
@SihatAfnan That depends on how you created the user. Try running grep postgres /etc/passwd | cut -d: -f 6.

Your Answer

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