1.问题描述
当我使用psql命令创建数据表时,发生以下问题:
user@ubuntu:~/sharedir$ ./Interface.py
psql -d postgres -U postgres -W 1234 -f /home/user/sharedir/createtable.sql
psql: warning: extra command-line argument "1234" ignored
Password for user postgres:
程序向我提示需输入系统用户user的登录密码,在我输入密码'user'后程序才得以执行成功,执行结果如下:
CREATE TABLE
CREATE TABLE
CREATE TABLE
由于此数据表创建功能是在python程序中实现的,不应该中途停止以等待输入密码,所以不得不完善方案。
2.方案一
在查阅stackoverflow之后,找到以下几种方案:
You have four choices regarding the password prompt:
- set the PGPASSWORD environment variable. For details see the manual:
PostgreSQL: Documentation: 14: 34.15. Environm