run psql query in bash

只谈情不闲聊 提交于 2019-12-13 07:43:21

问题


I am new in bash and psql, I want to write a bash code that login a server the connect to psql database do a select query and then return the output. the set up I have as follow.

server named dbs, it has psql install and running. database name = dname, user= tester passwrod = 1234 in the database there is table called node_info it has 3 colons ip, mac, connection_time. I want to run following query select ip, connection_time from node_info where ip=10.10.10.2;

Any tips how to write a shell script to do this remotely?


回答1:


If you have properly set your "pg_hba.conf" configuration file to achieve remote connections, you may try the following:

psql -U tester -h remoteip -p remoteport -d dname -W -c "select ip, connection_time from node_info where ip='10.10.10.2'"


来源:https://stackoverflow.com/questions/28688765/run-psql-query-in-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!