繁体   English   中英

postgres,psql和bat文件

[英]postgres, psql and a bat file

我正在转转,所以需要一些帮助。

我希望能够通过bat文件对作为计划任务的数据库运行.sql。 但是,当我手动运行bat文件时,系统提示您输入密码。 我输入密码,然后被告知...。

"psql: FATAL: password authentication failed for user "(my windows login)"
'-h' is not recognised as an internal or external command, 
operable program or batch file. 

此刻,我的蝙蝠读到...

@echo off
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe"
-h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause

首先,我需要添加什么命令来填充密码请求

我如何处理其余的语句以使其加载.sql

谢谢

通过将此行添加到配置文件( pg_hba.conf ),可以告诉postgres允许本地连接而无需身份验证

local      <database>  <user>  trust

http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html

所有需要放入批处理文件中的一行(似乎您有两行):

@echo off
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe" -h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause

为了避免出现密码提示,请在调用psql之前设置环境变量PGPASSWORD:

@echo off
setlocal
set PGPASSWORD=my_very_secret_password
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe" -h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause
endlocal

可以使用setlocal / endlocal命令来确保在执行批处理文件后清除该变量。

为了避免在批处理文件中使用明文密码,您可以创建一个包含密码的pgpass.conf文件。 有关详细信息,请参见手册: http : //www.postgresql.org/docs/current/static/libpq-pgpass.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM