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);
}
........
}

解决方案 »

  1.   

    配置远程连接:
    pg_hba.conf中:
    host    all         all         127.0.0.1/32          trust
    添加:
    host    <db>        192.168.1.15 255.255.255.0        password连接串:
    conninfo  = "host="   + _host 
                    + " port="      + _port
                    + " dbname="    + _dbname
                    + " user="      + _username
                    + " password="  + _password;
      

  2.   

    都配置好了,有远程连接的命令吗?类似mysql的:
    mysql -h 192.168.0.1 -u dbuser -p
      

  3.   

    使用psql -h 192.168.0.1 -u dbuser -d dbname
      

  4.   

    c语言后台远程连接PostgreSQL的代码,有没有啊?