title: Unable to connect from BigQuery job to Cloud SQL Postgres
body: <p>I am not able to use the federated query capability from Google BigQuery to Google Cloud SQL Postgres. Google announced this <a href="https://cloud.google.com/blog/products/data-analytics/whats-happening-bigquery-adding-speed-and-flexibility-10x-streaming-quota-cloud-sql-federation-and-more" rel="nofollow noreferrer">federated query capability</a> for BigQuery recently in beta state. </p>
  
  <p>I use EXTERNAL_QUERY statement like described in documentation but am not able to connect to my Cloud SQL instance. For example with query</p>
  
  <pre><code>SELECT * FROM EXTERNAL_QUERY('my-project.europe-north1.my-connection', 'SELECT * FROM mytable;');
  </code></pre>
  
  <p>or </p>
  
  <pre><code>SELECT * FROM EXTERNAL_QUERY("my-project.europe-north1.pg1", "SELECT * FROM INFORMATION_SCHEMA.TABLES;");
  </code></pre>
  
  <p>I receive this error :</p>
  
  <pre><code>Invalid table-valued function EXTERNAL_QUERY Connection to PostgreSQL server failed: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
  </code></pre>
  
  <p>Sometimes the error is this:</p>
  
  <pre><code>Error encountered during execution. Retrying may solve the problem.
  </code></pre>
  
  <p>I have followed the instructions on page <a href="https://cloud.google.com/bigquery/docs/cloud-sql-federated-queries" rel="nofollow noreferrer">https://cloud.google.com/bigquery/docs/cloud-sql-federated-queries</a> and enabled BigQuery Connection API. Some documents use different quotations for EXTERNAL_QUERY (“ or ‘ or ‘’’) but all the variants end with same result. </p>
  
  <p>I cannot see any errors in stackdriver postgres logs. How could I correct this connectivity error? Any suggestions how to debug it further?</p>