To dump a PostgreSQL database located at a specific IP address and restore it to a new database, you can follow these steps:
1. Dumping the database:
- Open a terminal or command prompt on your local machine.
- Use the `pg_dump` command-line tool to create a dump of the remote database. Replace `<remote_host>` with the IP address of the remote server and `<database_name>` with the name of the database you want to dump.
pg_dump -h <remote_host> -U <username> -d <database_name> -F c -f <dump_file_name>
Example:
pg_dump -h 192.168.1.100 -U myusername -d mydatabase -F c -f mydatabase.dump
This command will create a binary dump file named `mydatabase.dump` containing the data and schema of the remote database.
2. Copy the dump file to your local machine:
- Use a file transfer method (e.g., SCP, SFTP) to copy the dump file (`mydatabase.dump`) from the remote server to your local machine.
3. Restoring the database:
- Create a new, empty database on your local PostgreSQL server where you want to restore the dumped data.
- Open a terminal or command prompt on your local machine.
- Use the `pg_restore` command-line tool to restore the database from the dump file. Replace `<new_database_name>` with the name of the new database you created in the previous step.
pg_restore -U <username> -d <new_database_name> -F c <dump_file_name>
Example:
pg_restore -U myusername -d newdatabase -F c mydatabase.dump
This command will restore the database from the dump file (`mydatabase.dump`) into the new database (`newdatabase`) on your local machine.
Make sure you have the necessary permissions and access credentials to connect to the remote database and create databases on your local PostgreSQL server. Adjust the commands according to your specific setup and requirements.