{"title":"Connect a Postgres client","description":"Connect to Altertable with the Postgres wire protocol so SQL clients and BI tools can query governed lakehouse data.","order":810,"askSuggestions":["Why does my connection time out before authentication?","Why does a Postgres function fail through the adapter?","How do I connect with psql?"],"navigation":true,"routeId":"queryDataPostgres","body":{"code":"var Component=(()=>{var g=Object.create;var s=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var b=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),q=(t,e)=>{for(var r in e)s(t,r,{get:e[r],enumerable:!0})},l=(t,e,r,i)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of S(e))!y.call(t,o)&&o!==r&&s(t,o,{get:()=>e[o],enumerable:!(i=f(e,o))||i.enumerable});return t};var P=(t,e,r)=>(r=t!=null?g(m(t)):{},l(e||!t||!t.__esModule?s(r,\"default\",{value:t,enumerable:!0}):r,t)),w=t=>l(s({},\"__esModule\",{value:!0}),t);var h=b((k,d)=>{d.exports=_jsx_runtime});var x={};q(x,{default:()=>p,frontmatter:()=>L});var n=P(h()),L={title:\"Connect a Postgres client\",routeId:\"queryDataPostgres\",description:\"Connect to Altertable with the Postgres wire protocol so SQL clients and BI tools can query governed lakehouse data.\",order:810,askSuggestions:[\"Why does my connection time out before authentication?\",\"Why does a Postgres function fail through the adapter?\",\"How do I connect with psql?\"]};function u(t){let e={a:\"a\",code:\"code\",h1:\"h1\",h2:\"h2\",h3:\"h3\",li:\"li\",p:\"p\",pre:\"pre\",strong:\"strong\",ul:\"ul\",...t.components},{CodeSnippet:r,DocsPreviewDocument:i,DocsPreviewSection:o,DocsSdkCodeTabs:a}=e;return r||c(\"CodeSnippet\",!0),i||c(\"DocsPreviewDocument\",!0),o||c(\"DocsPreviewSection\",!0),a||c(\"DocsSdkCodeTabs\",!0),(0,n.jsxs)(i,{anchors:\"connect-a-postgres-client prerequisites connect run-your-first-query troubleshooting unrecognized-postgresql-function tls-negotiation\",children:[(0,n.jsxs)(o,{sectionId:\"connect-a-postgres-client\",sectionTitle:\"Connect a Postgres client\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,n.jsx)(e.h1,{id:\"connect-a-postgres-client\",children:\"Connect a Postgres client\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Use PostgreSQL syntax to query Altertable from psql, DBeaver, pgAdmin, or a BI tool. For client-specific setup, see \",(0,n.jsx)(e.a,{href:\"/docs/integrations/hex\",children:\"Hex\"}),\" or \",(0,n.jsx)(e.a,{href:\"/docs/integrations/metabase\",children:\"Metabase\"}),\".\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"prerequisites\",sectionTitle:\"Prerequisites\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,n.jsx)(e.h2,{id:\"prerequisites\",children:\"Prerequisites\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"You need a PostgreSQL-compatible client, an Altertable catalog name, and \",(0,n.jsx)(e.a,{href:\"/docs/administration/lakehouse-credentials\",children:\"lakehouse credentials\"}),\" for the target environment.\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"connect\",sectionTitle:\"Connect\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,n.jsx)(e.h2,{id:\"connect\",children:\"Connect\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Set the host to \",(0,n.jsx)(e.code,{children:\"postgres.altertable.ai\"}),\", the port to \",(0,n.jsx)(e.code,{children:\"443\"}),\", and the database to your catalog name. Enable TLS and authenticate with your lakehouse username and password.\"]}),`\n`,(0,n.jsx)(e.p,{children:(0,n.jsx)(e.strong,{children:\"psql\"})}),`\n`,(0,n.jsx)(r,{language:\"bash\",children:\"PGSSLMODE=require psql -h postgres.altertable.ai -p 443 -U {{LAKEHOUSE_USERNAME}} your_database\"}),`\n`,(0,n.jsx)(e.p,{children:(0,n.jsx)(e.strong,{children:\"Python (psycopg2)\"})}),`\n`,(0,n.jsx)(r,{language:\"python\",children:`import psycopg2\n\nconn = psycopg2.connect(\nhost=\"postgres.altertable.ai\",\nport=443,\ndatabase=\"your_database\",\nuser=\"{{LAKEHOUSE_USERNAME}}\",\npassword=\"{{LAKEHOUSE_PASSWORD}}\",\nsslmode=\"require\"\n)`}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"run-your-first-query\",sectionTitle:\"Run your first query\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,n.jsx)(e.h2,{id:\"run-your-first-query\",children:\"Run your first query\"}),`\n`,(0,n.jsx)(e.p,{children:\"Run this in the connected client:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-sql\",children:`SELECT 1 AS ok;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The result should contain one row with an \",(0,n.jsx)(e.code,{children:\"ok\"}),\" column equal to \",(0,n.jsx)(e.code,{children:\"1\"}),\".\"]}),`\n`,(0,n.jsx)(a,{category:\"sql\",languageIds:[\"postgres\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"troubleshooting\",sectionTitle:\"Troubleshooting\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,n.jsx)(e.h2,{id:\"troubleshooting\",children:\"Troubleshooting\"}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"unrecognized-postgresql-function\",sectionTitle:\"Unrecognized PostgreSQL function\",anchors:\"\",ancestors:\"troubleshooting\",index:\"5\",children:[(0,n.jsx)(e.h3,{id:\"unrecognized-postgresql-function\",children:\"Unrecognized PostgreSQL function\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"The adapter translates PostgreSQL queries for the lakehouse. If a function call fails, check the function name and argument types. If the same call works in PostgreSQL, include the query and error message when \",(0,n.jsx)(e.a,{href:\"/contact-us\",children:\"contacting support\"}),\".\"]}),`\n`]}),(0,n.jsxs)(o,{sectionId:\"tls-negotiation\",sectionTitle:\"TLS negotiation\",anchors:\"\",ancestors:\"troubleshooting\",index:\"6\",children:[(0,n.jsx)(e.h3,{id:\"tls-negotiation\",children:\"TLS negotiation\"}),`\n`,(0,n.jsx)(e.p,{children:\"The Postgres adapter supports standard PostgreSQL SSL negotiation on port 443.\"}),`\n`,(0,n.jsx)(e.p,{children:\"If a connection times out before authentication, check whether your network performs TLS inspection on port 443. Some configurations, including Cloudflare Gateway TLS inspection, may reject PostgreSQL's plaintext SSLRequest preamble.\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"Preferred: bypass TLS inspection for \",(0,n.jsx)(e.code,{children:\"postgres.altertable.ai\"}),\".\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"For clients using libpq 17 or newer, add \",(0,n.jsx)(e.code,{children:\"sslnegotiation=direct\"}),\" alongside \",(0,n.jsx)(e.code,{children:\"sslmode=require\"}),\".\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Clients without TLS-direct support, including Node \",(0,n.jsx)(e.code,{children:\"pg\"}),\", require the network bypass.\"]}),`\n`]})]})]})}function p(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,{...t,children:(0,n.jsx)(u,{...t})}):u(t)}function c(t,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+t+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return w(x);})();\n;return Component;"},"_id":"docs/lakehouse/query/postgres.mdx","_raw":{"sourceFilePath":"docs/lakehouse/query/postgres.mdx","sourceFileName":"postgres.mdx","sourceFileDir":"docs/lakehouse/query","contentType":"mdx","flattenedPath":"docs/lakehouse/query/postgres"},"type":"Docs","path":"/lakehouse/query/postgres","level":3,"parent":"lakehouse/query"}