postgresql 远程连接的命令?

Squallxye 2010-06-04 06:08:45
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);
}
........
}
...全文
1270 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
iihero 2010-06-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 squallxye 的回复:]

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

按照我在1楼的回复里修改你的连接串就完了。
Squallxye 2010-06-07
  • 打赏
  • 举报
回复
c语言后台远程连接PostgreSQL的代码,有没有啊?
iihero 2010-06-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 squallxye 的回复:]

都配置好了,有远程连接的命令吗?类似mysql的:
mysql -h 192.168.0.1 -u dbuser -p
[/Quote]
使用psql -h 192.168.0.1 -u dbuser -d dbname
Squallxye 2010-06-06
  • 打赏
  • 举报
回复
为何没有人关注了,自己顶
Squallxye 2010-06-05
  • 打赏
  • 举报
回复
都配置好了,有远程连接的命令吗?类似mysql的:
mysql -h 192.168.0.1 -u dbuser -p
iihero 2010-06-04
  • 打赏
  • 举报
回复
配置远程连接:
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;

56,686

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧