PageSourceSearch

https://sequelize.org/assets/js/fa1a3aa0.b8e5cfba.js

js sequelize.org collected 2026-09-24 08:29:23 UTC 18,827 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([[7025],{67398(e,t,n){n.d(t,{Ay:()=>c,RM:()=>r});var s=n(74848),o=n(28453);const r=[];function i(e){const t={a:"a",code:"code",p:"p",...(0,o.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.p,{children:"Connection Options are used to configure a connection to the database."}),"\n",(0,s.jsxs)(t.p,{children:["The simplest way to use them is at the root of the configuration object. These options can also be\nused in the ",(0,s.jsx)(t.a,{href:"/docs/v7/other-topics/read-replication",children:(0,s.jsx)(t.code,{children:"replication"})})," option to customize the connection for each replica,\nand can be modified by the ",(0,s.jsx)(t.a,{href:"/docs/v7/other-topics/hooks",children:(0,s.jsx)(t.code,{children:"beforeConnect"})})," hook on a connection-by-connection basis."]})]})}function c(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(i,{...e})}):i(e)}},89037(e,t,n){n.r(t),n.d(t,{assets:()=>h,contentTitle:()=>d,default:()=>x,frontMatter:()=>a,metadata:()=>s,toc:()=>u});const s=JSON.parse('{"id":"databases/postgres","title":"PostgreSQL","description":"See Releases to see which versions of PostgreSQL are supported.","source":"@site/docs/databases/postgres.mdx","sourceDirName":"databases","slug":"/databases/postgres","permalink":"/docs/v7/databases/postgres","draft":false,"unlisted":false,"editUrl":"https://github.com/sequelize/website/tree/main/docs/databases/postgres.mdx","tags":[],"version":"current","lastUpdatedBy":"renovate[bot]","lastUpdatedAt":1775795365000,"sidebarPosition":1,"frontMatter":{"title":"PostgreSQL","sidebar_position":1},"sidebar":"tutorialSidebar","previous":{"title":"Oracle","permalink":"/docs/v7/databases/oracle"},"next":{"title":"Snowflake","permalink":"/docs/v7/databases/snowflake"}}');var o=n(74848),r=n(28453),i=n(4865),c=n(19365),l=n(67398);const a={title:"PostgreSQL",sidebar_position:1},d="Sequelize for PostgreSQL",h={},u=[{value:"Connection Options",id:"connection-options",level:2},...l.RM,{value:"Connection via Unix Socket",id:"connection-via-unix-socket",level:3},{value:"Other PostgreSQL Options",id:"other-postgresql-options",level:2},{value:"Amazon Redshift",id:"amazon-redshift",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.header,{children:(0,o.jsx)(t.h1,{id:"sequelize-for-postgresql",children:"Sequelize for PostgreSQL"})}),"\n",(0,o.jsx)(t.admonition,{title:"Version Compatibility",type:"info",children:(0,o.jsxs)(t.p,{children:["See ",(0,o.jsx)(t.a,{href:"/releases#postgresql-support-table",children:"Releases"})," to see which versions of PostgreSQL are supported."]})}),"\n",(0,o.jsxs)(t.p,{children:["To use Sequelize with PostgreSQL, you need to install the ",(0,o.jsx)(t.code,{children:"@sequelize/postgres"})," dialect package:"]}),"\n",(0,o.jsxs)(i.A,{groupId:"npm2yarn",children:[(0,o.jsx)(c.A,{value:"npm",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"npm i @sequelize/postgres\n"})})}),(0,o.jsx)(c.A,{value:"yarn",label:"Yarn",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"yarn add @sequelize/postgres\n"})})}),(0,o.jsx)(c.A,{value:"pnpm",label:"pnpm",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"pnpm add @sequelize/postgres\n"})})}),(0,o.jsx)(c.A,{value:"bun",label:"Bun",children:(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"bun add @sequelize/postgres\n"})})})]}),"\n",(0,o.jsxs)(t.p,{children:["Then use the ",(0,o.jsx)(t.code,{children:"PostgresDialect"})," class as the dialect option in the Sequelize constructor:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",children:"import { Sequelize } from '@sequelize/core';\nimport { PostgresDialect } from '@sequelize/postgres';\n\nconst sequelize = new Sequelize({\n  dialect: PostgresDialect,\n  database: 'mydb',\n  user: 'myuser',\n  password: 'mypass',\n  host: 'localhost',\n  port: 5432,\n  ssl: true,\n  clientMinMessages: 'notice',\n});\n"})}),"\n",(0,o.jsx)(t.h2,{id:"connection-options",children:"Connection Options"}),"\n","\n",(0,o.jsx)(l.Ay,{}),"\n",(0,o.jsx)(t.p,{children:"The following options are accepted by the PostgreSQL dialect:"}),"\n",(0,o.jsxs)(t.table,{children:[(0,o.jsx)(t.thead,{children:(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.th,{children:"Option"}),(0,o.jsx)(t.th,{children:"Description"})]})}),(0,o.jsxs)(t.tbody,{children:[(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"database"})}),(0,o.jsx)(t.td,{children:"The name of the database to connect to."})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"user"})}),(0,o.jsx)(t.td,{children:"The user to authenticate as."})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"password"})}),(0,o.jsx)(t.td,{children:"The user's password."})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"host"})}),(0,o.jsx)(t.td,{children:"The host to connect to (either an IP, a domain name, or a path to a Unix socket)."})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"port"})}),(0,o.jsxs)(t.td,{children:["The port to connect to. Default is ",(0,o.jsx)(t.code,{children:"5432"}),"."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"ssl"})}),(0,o.jsxs)(t.td,{children:["The SSL configuration to use when connecting to the server. Passed directly to ",(0,o.jsx)(t.a,{href:"https://nodejs.org/docs/latest/api/tls.html#class-tlstlssocket",children:(0,o.jsx)(t.code,{children:"TLSSocket"})}),", supports all ",(0,o.jsx)(t.a,{href:"https://nodejs.org/docs/latest/api/tls.html#tlsconnectoptions-callback",children:(0,o.jsx)(t.code,{children:"tls.connect"})})," options"]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"query_timeout"})}),(0,o.jsx)(t.td,{children:"The number of milliseconds before a query call will timeout, default is no timeout."})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"connectionTimeoutMillis"})}),(0,o.jsx)(t.td,{children:"The number of milliseconds to wait for a connection, default is no timeout."})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"application_name"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-APPLICATION-NAME",children:["the ",(0,o.jsx)(t.code,{children:"application_name"})," PostgreSQL option"]})," for the connection."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"statement_timeout"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STATEMENT-TIMEOUT",children:["the ",(0,o.jsx)(t.code,{children:"statement_timeout"})," PostgreSQL option"]})," for the connection."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"idle_in_transaction_session_timeout"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT",children:["the ",(0,o.jsx)(t.code,{children:"idle_in_transaction_session_timeout"})," PostgreSQL option"]})," for the connection."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"client_encoding"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-CLIENT-ENCODING",children:["the ",(0,o.jsx)(t.code,{children:"client_encoding"})," PostgreSQL option"]})," for the connection. Default is ",(0,o.jsx)(t.code,{children:"utf8"}),"."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"lock_timeout"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-LOCK-TIMEOUT",children:["the ",(0,o.jsx)(t.code,{children:"lock_timeout"})," PostgreSQL option"]})," for the connection."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"options"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-OPTIONS",children:["the ",(0,o.jsx)(t.code,{children:"options"})," libpq option"]})," for the connection."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"keepAlive"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-KEEPALIVES",children:["the libpq ",(0,o.jsx)(t.code,{children:"keepalives"})," option"]}),". Must be a boolean."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"keepAliveInitialDelayMillis"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-KEEPALIVES-IDLE",children:["the libpq ",(0,o.jsx)(t.code,{children:"keepalives_idle"})," option"]}),", but in milliseconds (will be rounded down to the nearest second)."]})]})]})]}),"\n",(0,o.jsx)(t.admonition,{type:"info",children:(0,o.jsxs)(t.p,{children:["Sequelize uses the ",(0,o.jsx)(t.code,{children:"pg"})," package to connect to PostgreSQL.\nMost of the above options are provided as-is to the ",(0,o.jsx)(t.code,{children:"pg"})," package,\nand you can find more information about them in the ",(0,o.jsx)(t.a,{href:"https://node-postgres.com/apis/client#new-client",children:"pg documentation"}),"."]})}),"\n",(0,o.jsx)(t.h3,{id:"connection-via-unix-socket",children:"Connection via Unix Socket"}),"\n",(0,o.jsxs)(t.p,{children:["To connect to PostgreSQL using a Unix socket, you can use the ",(0,o.jsx)(t.code,{children:"host"})," option with the absolute path to the socket file:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",children:"const sequelize = new Sequelize({\n  dialect: PostgresDialect,\n  host: '/var/run/postgresql',\n});\n"})}),"\n",(0,o.jsx)(t.h2,{id:"other-postgresql-options",children:"Other PostgreSQL Options"}),"\n",(0,o.jsx)(t.p,{children:"The following options are also available for PostgreSQL:"}),"\n",(0,o.jsxs)(t.table,{children:[(0,o.jsx)(t.thead,{children:(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.th,{children:"Option"}),(0,o.jsx)(t.th,{children:"Description"})]})}),(0,o.jsxs)(t.tbody,{children:[(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"clientMinMessages"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-CLIENT-MIN-MESSAGES",children:["the ",(0,o.jsx)(t.code,{children:"client_min_messages"})," PostgreSQL option"]}
1),' for all connections. Defaults to "warning".']})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"standardConformingStrings"})}),(0,o.jsxs)(t.td,{children:["Configures ",(0,o.jsxs)(t.a,{href:"https://www.postgresql.org/docs/current/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS",children:["the ",(0,o.jsx)(t.code,{children:"standard_conforming_strings"})," PostgreSQL option"]})," for all connections. If your PostgreSQL server is configured with ",(0,o.jsx)(t.code,{children:"standard_conforming_strings = off"}),", it is extremely important to set this option to ",(0,o.jsx)(t.code,{children:"false"})," to avoid SQL injection vulnerabilities."]})]}),(0,o.jsxs)(t.tr,{children:[(0,o.jsx)(t.td,{children:(0,o.jsx)(t.code,{children:"native"})}),(0,o.jsxs)(t.td,{children:["If true, Sequelize will use the ",(0,o.jsx)(t.code,{children:"pg-native"})," package instead of the ",(0,o.jsx)(t.code,{children:"pg"})," package. ",(0,o.jsx)(t.code,{children:"pg-native"})," must be installed separately."]})]})]})]}),"\n",(0,o.jsx)(t.h2,{id:"amazon-redshift",children:"Amazon Redshift"}),"\n",(0,o.jsxs)(t.admonition,{type:"caution",children:[(0,o.jsx)(t.p,{children:"While Redshift is based on PostgreSQL, it does not support the same set of features as PostgreSQL."}),(0,o.jsx)(t.p,{children:"As we do not have access to a Redshift instance, we cannot guarantee that Sequelize will work correctly with Redshift,\nand we rely on the help of the community to keep this documentation up to date."})]}),"\n",(0,o.jsxs)(t.p,{children:["Redshift doesn't support ",(0,o.jsx)(t.code,{children:"client_min_messages"}),", you must set it to ",(0,o.jsx)(t.code,{children:"'ignore'"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-ts",children:"new Sequelize({\n  dialect: PostgresDialect,\n  // Your pg options here\n  clientMinMessages: 'ignore',\n});\n"})})]})}function x(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(p,{...e})}):p(e)}},19365(e,t,n){n.d(t,{A:()=>l});n(96540);var s=n(34164),o=n(47751);const r="tabItem_Ymn6";var i=n(74848);function c({children:e,className:t,hidden:n}){return(0,i.jsx)("div",{role:"tabpanel",className:(0,s.A)(r,t),hidden:n,children:e})}function l({children:e,className:t,value:n}){const{selectedValue:s,lazy:r}=(0,o.uc)(),l=n===s;return!l&&r?null:(0,i.jsx)(c,{className:t,hidden:!l,children:e})}},4865(e,t,n){n.d(t,{A:()=>x});n(96540);var s=n(34164),o=n(17559),r=n(47751),i=n(23104),c=n(92303);const l="tabList__CuJ",a="tabItem_LNqP";var d=n(74848);function h({className:e}){const{selectedValue:t,selectValue:n,tabValues:o,block:c}=(0,r.uc)(),l=[],{blockElementScrollPositionUntilNextRender:h}=(0,i.a_)(),u=e=>{const s=e.currentTarget,r=l.indexOf(s),i=o[r].value;i!==t&&(h(s),n(i))},p=e=>{let t=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,d.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":c},e),children:o.map(({value:e,label:n,attributes:o})=>(0,d.jsx)("li",{role:"tab",tabIndex:t===e?0:-1,"aria-selected":t===e,ref:e=>{l.push(e)},onKeyDown:p,onClick:u,...o,className:(0,s.A)("tabs__item",a,o?.className,{"tabs__item--active":t===e}),children:n??e},e))})}function u({children:e}){return(0,d.jsx)("div",{className:"margin-top--md",children:e})}function p({className:e,children:t}){return(0,d.jsxs)("div",{className:(0,s.A)(o.G.tabs.container,"tabs-container",l),children:[(0,d.jsx)(h,{className:e}),(0,d.jsx)(u,{children:t})]})}function x(e){const t=(0,c.A)(),n=(0,r.OC)(e);return(0,d.jsx)(r.O_,{value:n,children:(0,d.jsx)(p,{className:e.className,children:(0,r.vT)(e.children)})},String(t))}},47751(e,t,n){n.d(t,{OC:()=>x,O_:()=>g,uc:()=>f,vT:()=>d});var s=n(96540),o=n(56347),r=n(205),i=n(57485),c=n(70679),l=n(31682),a=n(74848);function d(e){return s.Children.toArray(e).filter(e=>"\n"!==e)}function h(e){const{values:t,children:n}=e;return(0,s.useMemo)(()=>{const e=t??function(e){return s.Children.toArray(e).flatMap(e=>{if(!e)return[];if((0,s.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return[e];
1const t="string"==typeof e.type?e.type:e.type.name;throw new Error(`Docusaurus error: Bad <Tabs> child <${t}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.\nIf you do not want to pass on a "value" prop to the direct children of <Tabs>, you can also pass an explicit <Tabs values={...}> prop.`)}).map(({props:{value:e,label:t,attributes:n,default:s}})=>({value:e,label:t,attributes:n,default:s}))}(n);return function(e){const t=(0,l.XI)(e,(e,t)=>e.value===t.value);if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map(e=>`'${e.value}'`).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e},[t,n])}function u({value:e,tabValues:t}){return t.some(t=>t.value===e)}function p({queryString:e=!1,groupId:t}){const n=(0,o.W6)(),r=function({queryString:e=!1,groupId:t}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!t)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:e,groupId:t});return[(0,i.aZ)(r),(0,s.useCallback)(e=>{if(!r)return;const t=new URLSearchParams(n.location.search);t.set(r,e),n.replace({...n.location,search:t.toString()})},[r,n])]}function x(e){const{defaultValue:t,queryString:n=!1,groupId:o}
1=e,i=h(e),[l,a]=(0,s.useState)(()=>function({defaultValue:e,tabValues:t}){if(0===t.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!u({value:e,tabValues:t}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${t.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=t.find(e=>e.default)??t[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:i})),[d,x]=p({queryString:n,groupId:o}),[j,f]=function({groupId:e}){const t=function(e){return e?`docusaurus.tab.${e}`:null}(e),[n,o]=(0,c.Dv)(t);return[n,(0,s.useCallback)(e=>{t&&o.set(e)},[t,o])]}({groupId:o}),g=(()=>{const e=d??j;return u({value:e,tabValues:i})?e:null})();(0,r.A)(()=>{g&&a(g)},[g]);return{selectedValue:l,selectValue:(0,s.useCallback)(e=>{if(!u({value:e,tabValues:i}))throw new Error(`Can't select invalid tab value=${e}`);a(e),x(e),f(e)},[x,f,i]),tabValues:i,lazy:e.lazy??!1,block:e.block??!1}}const j=(0,s.createContext)(null);function f(){const e=s.useContext(j);if(!e)throw new Error("useTabsContext() must be used within a Tabs component");return e}function g(e){return(0,a.jsx)(j.Provider,{value:e.value,children:e.children})}},28453(e,t,n){n.d(t,{R:()=>i,x:()=>c});var s=n(96540);const o={},r=s.createContext(o);function i(e){const t=s.useContext(r);return s.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.