how do i import postgresql database from a local folder or host directory

4.6k views Asked by At

I have a .sql file on both my local computer and another one FTP to my host.. There is not tool in phppgdmin to import the file. What is the easiest to import the data?

i have dedicated hosting, and puTTy terminal.

1

There are 1 answers

2
MatheusOl On BEST ANSWER

If the PostgreSQL instance is accessible from your machine, you can easily do this:

psql -h your_server your_databasename -f /path/to/yourfile.sql

If it is not, you can open a SSH connection (through Putty) with port fowarding from 127.0.0.1:5432 (or whatever is your PG port) to other port (could be 5432 if you don't have a PG server running locally), and them just use psql to import the dump:

psql -h localhost -p <other port> your_databasename -f /path/to/yourfile.sql

Another solution, is to send the file to the server and import from there. To send it, you can use WinSCP, that send files through a SSH connection.

One more thing, if your file is too big, you can check the "Enable compression" checkbox at "Connection > SSH" on Putty.