postgresql数据库--psql、pg_dump命令带密码执行sql语句

news/2024/7/9 20:41:07 标签: 数据库, postgresql, psql, pg_dump, 带密码

pg_dump:

pg_dump -a -t tbl_test "host=127.0.0.1 hostaddr=127.0.0.1 port=5432 user=postgres password=123456 dbname=postgres" > /userdir/tbl_data

-a 参数是表示只导出数据,其他的额外信息不需要,该参数也可去掉

psql:

psql --command "select * from tbl_test;" "host=127.0.0.1 hostaddr=127.0.0.1 port=5432 user=postgres password=123456 dbname=postgres"

 

当然可以使用export(linux平台)将数据库的相关配置设置到环境变量中,可以设置的变量如下(除过PGPASSWORD外,其他的没验证,不过理论上应该可以的):

export PGHOST='localhost'
export PGUSER=postgres
export PGDATABASE=postgres
export PGPASSWORD=null
export PGPORT=5432

 


http://www.niftyadmin.cn/n/1727624.html

相关文章

js Date()函数常用方法

代码: var date new Date(); var a date.getDate(); console.log("getDate:"a); var b date.getDay(); console.log("getDay:"b); var c date.getFullYear(); console.log("getFullYear:"c); var d date.getHours(); console.l…

微服务实战系列之SpringCloud Alibaba学习(六)

微服务实战系列之SpringCloud Alibaba: 微服务实战系列之SpringCloud Alibaba学习(一)微服务实战系列之SpringCloud Alibaba学习(二)微服务实战系列之SpringCloud Alibaba学习(三)微服务实战系…

shell 去掉多余空格

cat test.txt |tr -s [:space:]sed s/ */ /g test.txt 如果要改变test.txt文件本身,sed后边可加上“-i”参数

PG数据库获取时间函数

select now(); //2017-01-17 20:43:31.94601508 select date_trunc(second, now()); //2017-01-17 20:28:3308 SELECT CURRENT_TIMESTAMP(0) :: TIMESTAMP WITHOUT TIME ZONE; //2017-01-17 20:28:33

WIN7环境下通过ISS7快速搭建简易FTP服务器

WIN7环境下通过ISS7快速搭建简易FTP服务器 首先开启ISS7服务: 打开控制面板-->程序(卸载程序)-->打开或关闭Windows功能-->打开internet服务,勾选相关选项,点击右下角的确定按钮,至此ISS服务启动成功。 1.搭建不需要输…

同时查询多张表中的数据个数

select my1.a,my2.b,my3.c from (select count(*) as a from tbl_a) as my1 , (select count(*) as b from tbl_b) as my2 , (select count(*) as c from tbl_c) as my3; 同时查询两张表 select * from (select * from tbl_a) as a,(select * from tbl_b) as b;

ubuntu使用chkconfig命令来管理服务

安装命令: sudo apt-get install chkconfig (可以用sysv-rc-conf代替)在ubuntu下使用应该会出现这样的错误: /sbin/insserv: No such file or directory 解决办法:sudo ln -s /usr/lib/insserv/insserv /sbin/insserv

js 用指定符号将数组转换成字符串

字符串转数组: var str "aa,bb,cc"; var arr str.split(","); //["aa","bb","cc"] 数组转字符串: var arr ["aa","bb","cc"]; var stra arr.toString(); //&…