Postgresql: Scripting psql execution with password

后端 未结 16 2433
谎友^
谎友^ 2020-11-28 18:54

How can I call psql so that it doesn\'t prompt for a password?

This is what I have:

psql -Umyuser < myscript.sql         


        
16条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 19:04

    An alternative to using PGPASSWORD environment variable is to use conninfo string according to the documentation

    An alternative way to specify connection parameters is in a conninfo string or a URI, which is used instead of a database name. This mechanism give you very wide control over the connection.

    $ psql "host= port=5432 dbname= user= password="
    
    postgres=>
    

提交回复
热议问题