我想在 shell 中从 DB2 迁移到 Postgres。如何从 db2 更改为连接 sql 到 Postgres .
#!/bin/bash
DBUSRSTR="user ${DBUSER} using ${DBPSW}"
VAR=`db2 CONNECT TO ${DBNAME} ${DBUSRSTR}`
if [ ! $? -eq 0 ]; then
logErr ${MSG002E}
logErr ${VAR}
exit 2
fi
db2 set current schema TEST
if [ ! $? -eq 0 ]; then
logErr ${MSG002E}
exit 2
fi
logInfo "Set Current Schema:" $?
db2 truncate table TEST.table1 immediate
我只想删除 db2 命令并更改为 Postgres 命令。
您可以运行 psql 命令行并执行查询。
psql -d ${DBNAME} -U ${DBUSER} -h ${DBHOST} -c "select 1"
您无法在多个客户端调用中保持打开的 PostgreSQL 连接,但您可以使用"here 文档":
psql -U user <<EOF
SET ...
TRUNCATE ...
...
EOF
对于密码,您将使用密码文件。