PostgreSQLリモート・データベース接続
867 ワード
postgresqlが許可されているIPを正しく設定していないため、データベース・サーバにリモートで接続するときに接続できないことが多い.
AマシンインストールPostgreSQL、デフォルトポート5432 BマシンがリモートでAマシンに接続するPostgreSQLサービスを実現したい. 1.AマシンがWindowsファイアウォールを起動した場合、「例外」に「ポートの追加」に5432ポートを追加します. 2.postgresql.confでの修正 listen_addresses = '*' port = 5432 3.pg_hba.confに追加 host all all 192.168.1.2/32 trust BマシンでphpPgAdminでAマシン192.168.1.1に接続してみる
AマシンインストールPostgreSQL、デフォルトポート5432 BマシンがリモートでAマシンに接続するPostgreSQLサービスを実現したい. 1.AマシンがWindowsファイアウォールを起動した場合、「例外」に「ポートの追加」に5432ポートを追加します. 2.postgresql.confでの修正 listen_addresses = '*' port = 5432 3.pg_hba.confに追加 host all all 192.168.1.2/32 trust BマシンでphpPgAdminでAマシン192.168.1.1に接続してみる
const char* connInfo = "host=* dbname=postgres user=postgres password=root port=5432 connect_timeout=5";
PGconn *conn = PQconnectStart(connInfo);
//pgui_exec();
ConnStatusType connStatus = PQstatus(conn);
if (connStatus != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",
PQerrorMessage(conn));
//exit_nicely(conn);
}