postgresql 远程连接的命令?
2个问题呵:
1 postgesql 远程连接的命令?
在linux下面远程连接服务器端的postgresql,本地已经安装了postgresql;现在假设:
远程的服务器的ip为dstip,端口为dstPort,远程的用户名为user,密码为psd,远程的数据库为mydb
请问该如何写这个命令?另外需要些什么设置?
2 用户c语言实现远程连接的代码?
我在postgreSQL的.../src/test/examples里面找到了一个代码,是连接本地的postgreSQL的,但是远程的不知道该怎么连接。
.../src/test/examples/testlibpq3.c
main(int argc, char **argv)
{
const char *conninfo;
PGconn *conn;
PGresult *res;
const char *paramValues[1];
int paramLengths[1];
int paramFormats[1];
uint32_t binaryIntVal;
/*
* If the user supplies a parameter on the command line, use it as the
* conninfo string; otherwise default to setting dbname=postgres and using
* environment variables or defaults for all other connection parameters.
*/
if (argc > 1)
conninfo = argv[1];
else
conninfo = "dbname = postgres";//?????这个参数改如何填写?如果加上远程ip的话?
/* Make a connection to the database */
conn = PQconnectdb(conninfo);
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
exit_nicely(conn);
}
........
}