简体   繁体   English

如何使用 bash 访问 psql?

[英]How can I do to access to psql using bash?

I am trying to do a bash file to use psql but I don't achieve...我正在尝试做一个 bash 文件来使用 psql 但我没有实现......

Here is my file:这是我的文件:

sudo su -
su - postgres
psql

But when I launch my bash file I have to type my password for the root user but then I have close my root session to see the others command executed...但是当我启动我的 bash 文件时,我必须输入我的 root 用户密码,但是我关闭了我的 root session 以查看其他命令的执行......

How can I do that to execute the following command as root:如何以 root 身份执行以下命令:

su - postgres
psql

Thank you very much !非常感谢 !

That could be combined to something like:这可以组合成类似的东西:

sudo -u postgres psql

However, this should only be done for initial set up and maintenance operations.但是,这仅应针对初始设置和维护操作进行。 Create another database account which can accessed without sudo for everyday use.为日常使用创建另一个无需 sudo 即可访问的数据库帐户。 (This might involve changing pg_hba.conf away from its original defaults). (这可能涉及将 pg_hba.conf 更改为远离其原始默认值)。

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

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