Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute .sql files in postgres database

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.

like image 692
sasikala Avatar asked Nov 26 '15 17:11

sasikala


1 Answers

Use psql command line tool:

psql -f file_with_sql.sql 

This command executes all commands line-by-line (except when file contains BEGIN…END blocks. In this case commands in blocks executes in transaction). To wrap all commands in transaction use --single-transaction switch:

psql --single-transaction -f file_with_sql.sql 

For more options:

psql --help 
like image 186
Tomasz Jakub Rup Avatar answered Oct 26 '22 17:10

Tomasz Jakub Rup