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