Postgresql database import and export, postgresql Import and Export
Export a remote database
1. Export the threshold table structure and data to the file threshold. SQL from the database monitor on the remote database IP Address:
pg_dump -t threshold -h 135.32.94.142 monitor -U monitor -p 5432 -f threshold.sql
-T specifies the name of the table to be exported;
-H: Specifies the database address;
-U indicates the database user;
-P specifies the access port;
-F specifies the file to be exported;
2. Export all table structures and data from the database monitor on the remote database IP address to the File monitor. SQL:
pg_dump -h 135.32.94.142 monitor -U monitor -p 5432 -f monitor.sql
3. From the database monitor on the remote database IP address, only all the table structures are exported to the File monitor. SQL:
pg_dump -s -h 135.32.94.142 monitor -U monitor -p 5432 -f monitor.sql
-S: only export the table structure
Note: Generally, the database data volume is relatively large. If you remotely export all the table structures and data, it will be very slow. It is a wise choice to export only the table structure. Then you can export the structure and data of a single important data table. Import database 1. Import the table structure and data from the local file threshold. SQL to the database monitor on the remote IP Address:
psql -h 135.32.9.99 -d monitor -U monitor -f threshold.sql
-H: Specifies the database address;
-D specifies the database;
-U indicates the user;
-F specifies the file to be imported (here is the file exported in step 1 );
Note: The files here are the files exported from the remote database.
2. Import to local database:
psql -h 0.0.0.0 -p 5432 -d monitor -U monitor -f monitor.sql
-P: Specifies the Database Service port, which is changed based on local conditions. The default value is port 5432.