Postgresql: Scripting psql execution with password

后端 未结 16 2425
谎友^
谎友^ 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条回答
  •  -上瘾入骨i
    2020-11-28 19:17

    This might be an old question, but there's an alternate method you can use that no one has mentioned. It's possible to specify the password directly in the connection URI. The documentation can be found here, alternatively here.

    You can provide your username and password directly in the connection URI provided to psql:

    # postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
    psql postgresql://username:password@localhost:5432/mydb
    

提交回复
热议问题