I am using postgres database with PostGIS and PGAdmin. I have many .sql files with different sizes like 300MB, 280MB etc to be inserted into database. What is the best way to do it i.e through java code or some psql commands. I am very new to java and postgres database also. Please give me some suggestion.
4 Answers
Use the psql command line tool:
psql -f file_with_sql.sql
This command executes all commands line-by-line (except when the file contains BEGIN…END blocks. In this case, commands in blocks execute in a transaction). To wrap all commands in a transaction use the --single-transaction switch:
psql --single-transaction -f file_with_sql.sql
For more options:
psql --help
1 Comment
Just put it on the command line after psql:
psql example.sql
psql will take the file and run each line to the server.
If the server is not running on your computer, you will need to specify the hostname to the computer and a username to log into the server with:
psql -h server.postgres.com -U username example.sql
To send multiple files, just list them all:
psql example1.sql example2.sql example3.sql