使用命令行args运行postgresql .sql文件 [英] Run a postgresql .sql file using command line args
问题描述
我有一些.sql文件与成千上万的INSERT语句,并需要在我的PostgreSQL数据库上运行这些插入,以便将它们添加到表。文件很大,无法打开它们,并将INSERT语句复制到编辑器窗口中并在那里运行。我在网上找到你可以使用以下通过导航到您的postgresql安装的bin文件夹:
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 that large that it is impossible to open them and copy the INSERT statements into an editor window and run them there. I found on the net that you can use the following by navigating to the bin folder of your postgresql install:
psql -d myDataBase -a -f myInsertFile
在我的情况下
psql -d HIGHWAYS -a -f CLUSTER_1000M.sql
我随后要求我的用户密码,但我不能输入任何内容,当我输入我得到这个错误:
I am then asked for a password for my user but I cannot enter anything and when I hit enter I get this error:
psql: FATAL: password authentication failed for user "myUsername"
为什么不让我输入密码。有一个方法,这是因为它是至关重要的,我可以运行这些脚本。
Why won't it let me enter a password. Is there a way round this as it is critical that I can run these scripts.
编辑:
我遇到这个问题,我的pg_hba.conf文件具有以下结构:
I got around this issue by adding a new entry in my pg_hba.conf file with the following structure:
# IPv6 local connections:
host myDbName myUserName ::1/128 trust
pg_hba.conf文件通常可以在Postgresql安装的'data' 。
The pg_hba.conf file can usually be found in the 'data' folder of your Postgresql install.
推荐答案
您有四种选择提供密码:
You have four choices to supply a password:
- 设置PGPASSWORD环境变量。有关详情,请参阅手册:
http://www.postgresql.org/docs/current /static/libpq-envars.html - 使用.pgpass文件存储密码。有关详情,请参阅手册:
http://www.postgresql.org/docs/current /static/libpq-pgpass.html - 对该特定用户使用信任身份验证: http://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-TRUST
- 自Postgres 9.1起,您还可以使用连接字符串:
https://www.postgresql.org /docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
- set the PGPASSWORD environment variable. For details see the manual:
http://www.postgresql.org/docs/current/static/libpq-envars.html - use a .pgpass file to store the password. For details see the manual:
http://www.postgresql.org/docs/current/static/libpq-pgpass.html - use "trust authentication" for that specific user: http://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-TRUST
- Since Postgres 9.1 you can also use a connection string:
https://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
这篇关于使用命令行args运行postgresql .sql文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!