Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print current working directory in psql console?

I am trying to restore a schema on a remote server using the psql console in pgAdmin and an sql dump file. I receive the following error:

user=> \i file.sql
file.sql: No such file or directory

I can't seem to print the directory listings due to lacking superuser privileges.

Is there a way to identify or print the current working directory in psql console? What is the default directory?

like image 734
Don P Avatar asked Jul 13 '17 21:07

Don P


People also ask

What is the psql command to show all the relations in a database?

Type the command \l in the psql command-line interface to display a list of all the databases on your Postgres server.

How do I change the current working directory in PSQL?

Typing in the command \! pwd will print the current working directory in psql. To change working directory use command \cd <path>; replace <path> with desired path. Eg. Running command \cd /run/mount will change the current working directory to /run/mount.

How to print the current working directory in Windows 10 PSQL?

Everyone assumes that because you are using postgres that you must be running Linux. Well, postgres is now becoming a very popular DBMS on Windows 10. In Windows 10, in a psql command prompt type "! dir" to print the current working directory. To change directories in the Windows 10 psql client, "\cd /users/yourlogin".

How do I print the current working directory in CMD?

To print the current working directory in CMD, run the cd command without specifying the path or parameters. As an alternative, you can use the chdir command to print the current directory. The cd command is short for change directory, and it is the command we use to navigate in the command prompt.

Why does PSQL only print the result of the last SQL?

Also, psql only prints the result of the last SQL command in the string. This is different from the behavior when the same string is read from a file or fed to psql 's standard input, because then psql sends each SQL command separately. Because of this behavior, putting more than one SQL command in a single -c string often has unexpected results.


2 Answers

Typing in the command \! pwd will print the current working directory in psql. To change working directory use command \cd <path>; replace <path> with desired path. Eg. Running command \cd /run/mount will change the current working directory to /run/mount. Try changing the your working directory to that containing the file which you want to run and then use \i meta command as you did earlier. It will definitely work.

like image 87
vipulsinghthakur Avatar answered Oct 05 '22 00:10

vipulsinghthakur


I am shocked that no one answered the question directly in over 2 years. Everyone assumes that because you are using postgres that you must be running Linux. Well, postgres is now becoming a very popular DBMS on Windows 10.

In Windows 10, in a psql command prompt type "! dir" to print the current working directory.

To change directories in the Windows 10 psql client, "\cd /users/yourlogin".

The psql client is a unix shell running on Windows, so it is a mix of unix and dos syntax commands.

like image 39
Rich Lysakowski PhD Avatar answered Oct 04 '22 22:10

Rich Lysakowski PhD