Yes it's possible. However, you need to make a JSON API: the server wich serve postgresql needs to fetch results from Database, then encode it in json with json_encode() method and return it with echo.
Then, you need to make an HTTP request from your shared hosting using CURL, here's an example:
function GetContent($url) {
$curl = curl_init();
$ua = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl ,CURLOPT_USERAGENT, $ua);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
Then, call the function:
$sql = json_decode(GetContent('http://urlofyourserver/testJSON.php'));
You can now get the result in the $sql variable :)
Oh and don't forget, make a password request using $_GET requests on your server wich serves postgresql, otherwise everyone will be able to access to data if they found your server URL.
e.g: http://urlofyourserver/testJSON.php?secret=xxx
You can also pass the query as a get parameter, but It can be risked if your password is cracked.
Postgresql server sample
$realPass = "blablah";
if(isset($_GET['secret'])) {
$pass = $_GET['secret'];
if($pass === $realPass) {
header('Content-type: application/json');
// do query here and return it as $test var
echo json_encode($test);
}
}
file_get_contents()is considered a bad practice and a security liability, and I'm pretty sure his free host has it disabled.