Run a PostgreSQL .sql file using command line arguments

前端 未结 12 2002
面向向阳花
面向向阳花 2020-11-28 00:08

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 tha

12条回答
  •  醉酒成梦
    2020-11-28 00:40

    Use this to execute *.sql files when the PostgreSQL server is located in a difference place:

    psql -h localhost -d userstoreis -U admin -p 5432 -a -q -f /home/jobs/Desktop/resources/postgresql.sql
    
    -h PostgreSQL server IP address
    -d database name
    -U user name
    -p port which PostgreSQL server is listening on
    -f path to SQL script
    -a all echo
    -q quiet
    

    Then you are prompted to enter the password of the user.

    EDIT: updated based on the comment provided by @zwacky

提交回复
热议问题