{"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 S=Object.create;var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var w=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),x=(n,e)=>{for(var i in e)c(n,i,{get:e[i],enumerable:!0})},d=(n,e,i,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of f(e))!b.call(n,o)&&o!==i&&c(n,o,{get:()=>e[o],enumerable:!(s=m(e,o))||s.enumerable});return n};var y=(n,e,i)=>(i=n!=null?S(L(n)):{},d(e||!n||!n.__esModule?c(i,\"default\",{value:n,enumerable:!0}):i,n)),P=n=>d(c({},\"__esModule\",{value:!0}),n);var p=w((q,h)=>{h.exports=_jsx_runtime});var k={};x(k,{default:()=>g,frontmatter:()=>T});var t=y(p()),T={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(n){let e={code:\"code\",h1:\"h1\",h2:\"h2\",li:\"li\",p:\"p\",strong:\"strong\",ul:\"ul\",...n.components},{CodeSnippet:i,DocsPreviewDocument:s,DocsPreviewSection:o,DocsSdkCodeTabs:a,DocsTable:l}=e;return i||r(\"CodeSnippet\",!0),s||r(\"DocsPreviewDocument\",!0),o||r(\"DocsPreviewSection\",!0),a||r(\"DocsSdkCodeTabs\",!0),l||r(\"DocsTable\",!0),(0,t.jsxs)(s,{anchors:\"connect-a-postgres-client authentication sql-dialect quick-start connection-examples tls-negotiation\",children:[(0,t.jsxs)(o,{sectionId:\"connect-a-postgres-client\",sectionTitle:\"Connect a Postgres client\",anchors:\"\",ancestors:\"\",index:\"0\",children:[(0,t.jsx)(e.h1,{id:\"connect-a-postgres-client\",children:\"Connect a Postgres client\"}),`\n`,(0,t.jsx)(l,{columns:[\"Hostname\",\"Port\"],data:[{Hostname:\"`postgres.altertable.ai`\",Port:\"443 (TLS/SSL)\"}]}),`\n`,(0,t.jsx)(e.p,{children:\"The Postgres adapter lets you connect to Altertable through the PostgreSQL wire protocol. It works with BI tools and SQL clients that already speak Postgres.\"}),`\n`,(0,t.jsx)(e.p,{children:\"This adapter is ideal for:\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"BI tools\"}),\" like Hex, Looker, Tableau, Power BI, and Metabase\"]}),`\n`,(0,t.jsxs)(e.li,{children:[(0,t.jsx)(e.strong,{children:\"SQL clients\"}),\" such as DBeaver and pgAdmin\"]}),`\n`]}),`\n`]}),(0,t.jsxs)(o,{sectionId:\"authentication\",sectionTitle:\"Authentication\",anchors:\"\",ancestors:\"\",index:\"1\",children:[(0,t.jsx)(e.h2,{id:\"authentication\",children:\"Authentication\"}),`\n`,(0,t.jsx)(e.p,{children:\"Use your lakehouse username and lakehouse password with TLS enabled.\"}),`\n`]}),(0,t.jsxs)(o,{sectionId:\"sql-dialect\",sectionTitle:\"SQL Dialect\",anchors:\"\",ancestors:\"\",index:\"2\",children:[(0,t.jsx)(e.h2,{id:\"sql-dialect\",children:\"SQL Dialect\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"While the connection uses the Postgres protocol, queries are executed using \",(0,t.jsx)(e.strong,{children:\"DuckDB SQL dialect\"}),\". This means that Postgres-specific functions (e.g., \",(0,t.jsx)(e.code,{children:\"string_agg\"}),\", \",(0,t.jsx)(e.code,{children:\"generate_series\"}),\") may not work.\"]}),`\n`]}),(0,t.jsxs)(o,{sectionId:\"quick-start\",sectionTitle:\"Quick Start\",anchors:\"\",ancestors:\"\",index:\"3\",children:[(0,t.jsx)(e.h2,{id:\"quick-start\",children:\"Quick Start\"}),`\n`,(0,t.jsx)(a,{category:\"sql\",languageIds:[\"postgres\"]}),`\n`]}),(0,t.jsxs)(o,{sectionId:\"connection-examples\",sectionTitle:\"Connection examples\",anchors:\"\",ancestors:\"\",index:\"4\",children:[(0,t.jsx)(e.h2,{id:\"connection-examples\",children:\"Connection examples\"}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.strong,{children:\"psql\"})}),`\n`,(0,t.jsx)(i,{language:\"bash\",children:\"PGSSLMODE=require psql -h postgres.altertable.ai -p 443 -U {{LAKEHOUSE_USERNAME}} your_database\"}),`\n`,(0,t.jsx)(e.p,{children:(0,t.jsx)(e.strong,{children:\"Python (psycopg2)\"})}),`\n`,(0,t.jsx)(i,{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,t.jsxs)(o,{sectionId:\"tls-negotiation\",sectionTitle:\"TLS negotiation\",anchors:\"\",ancestors:\"\",index:\"5\",children:[(0,t.jsx)(e.h2,{id:\"tls-negotiation\",children:\"TLS negotiation\"}),`\n`,(0,t.jsx)(e.p,{children:\"The Postgres adapter supports standard PostgreSQL SSL negotiation on port 443.\"}),`\n`,(0,t.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,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsxs)(e.li,{children:[\"Preferred: bypass TLS inspection for \",(0,t.jsx)(e.code,{children:\"postgres.altertable.ai\"}),\".\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"For clients using libpq 17 or newer, add \",(0,t.jsx)(e.code,{children:\"sslnegotiation=direct\"}),\" alongside \",(0,t.jsx)(e.code,{children:\"sslmode=require\"}),\".\"]}),`\n`,(0,t.jsxs)(e.li,{children:[\"Clients without TLS-direct support, including Node \",(0,t.jsx)(e.code,{children:\"pg\"}),\", require the network bypass.\"]}),`\n`]})]})]})}function g(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,{...n,children:(0,t.jsx)(u,{...n})}):u(n)}function r(n,e){throw new Error(\"Expected \"+(e?\"component\":\"object\")+\" `\"+n+\"` to be defined: you likely forgot to import, pass, or provide it.\")}return P(k);})();\n;return Component;"},"_id":"docs/lakehouse/clients/postgres.mdx","_raw":{"sourceFilePath":"docs/lakehouse/clients/postgres.mdx","sourceFileName":"postgres.mdx","sourceFileDir":"docs/lakehouse/clients","contentType":"mdx","flattenedPath":"docs/lakehouse/clients/postgres"},"type":"Docs","path":"/lakehouse/clients/postgres","level":3,"parent":"lakehouse/clients"}