Run a PostgreSQL .sql file using command line arguments
I have some .sql files with thousands of INSERT statements in them and need to run these inserts on my PostgreSQL database in order to add them to a table.
The files are that large that it is impossible to open them and copy the INSERT statements into an editor window and run them there.
You can use the following by navigating to the bin folder of your PostgreSQL install:
You have four choices to supply a password:
psql -U username -d myDataBase -a -f myInsertFile
- Set the PGPASSWORD environment variable. For details see the manual:
http://www.postgresql.org/docs/current/static/libpq-envars.html
- Use a .pgpass file to store the password. For details see the manual:
http://www.postgresql.org/docs/current/static/libpq-pgpass.html
- Use "trust authentication" for that specific user: http://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-TRUST
- Since PostgreSQL 9.1 you can also use a connection string:
https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
Commenti