The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Consolidates pgbouncer settings to one panel in the database settings page
Terry Sutton67cb0744d6b2
diff --git a/studio/components/interfaces/Database/Pooling/BouncerSettings.tsx b/studio/components/interfaces/Database/Pooling/BouncerSettings.tsxindex be0a2bf494c..457dd19652d 100644--- a/studio/components/interfaces/Database/Pooling/BouncerSettings.tsx+++ b/studio/components/interfaces/Database/Pooling/BouncerSettings.tsx@@ -1,15 +1,11 @@import { FC, useState, useEffect } from 'react'import { observer } from 'mobx-react-lite'-import { Input, Typography } from '@supabase/ui'-+import { Typography } from '@supabase/ui'import { useStore } from 'hooks'import { pluckObjectFields } from 'lib/helpers'import Loading from 'components/ui/Loading'-import Panel from 'components/to-be-cleaned/Panel'import PgBouncerConfig from './PgBouncerConfig'-import DownloadCertificate from './DownloadCertificate'--import Divider from 'components/ui/Divider'+import Panel from 'components/to-be-cleaned/Panel'interface Props {}@@ -45,12 +41,17 @@ const BouncerSettings: FC<Props> = ({}) => {// for older projectsif (!project.pgbouncer_enabled && project.pool_mode == null)return (- <div className="h-full flex flex-col items-center justify-center p-6 sm:w-full md:w-3/4 mx-auto text-center">- <Typography.Title level={3}>- Connection Pooling is not available for this project+ <Panel+ title={+ <Typography.Title key="panel-title" level={5} className="mb-0">+ Connection Pooling is not available for this project</Typography.Title>- <Typography.Text>Start a new project to enable this feature.</Typography.Text>- </div>+ }+ >+ <Panel.Content>+ <Typography.Text type="secondary">Please start a new project to enable this feature.</Typography.Text>+ </Panel.Content>+ </Panel>)const formModel = projectconst DB_FIELDS = ['db_host', 'db_name', 'db_port', 'db_user', 'inserted_at']@@ -63,126 +64,9 @@ const BouncerSettings: FC<Props> = ({}) => {]const bouncerInfo = pluckObjectFields(formModel, BOUNCER_FIELDS)return (- <article className="p-4 max-w-4xl">- <div className="mb-8">- <PgBouncerConfig config={bouncerInfo} projectRef={projectRef} />- </div>-- <Panel- title={[- <Typography.Title key="panel-title" level={5} className="mb-0">- Connection info- </Typography.Title>,- ]}- >- <div className="">- <Panel.Content>- <Input- label="Host"- layout="horizontal"- descriptionText="This is the url of your database"- readOnly- copy- disabled- value={connectionInfo.db_host}- />- </Panel.Content>- <Divider light />- <Panel.Content>- <Input- label="Database name"- style={{- width: '50%',- }}- readOnly- disabled- value={connectionInfo.db_name}- layout="horizontal"- />- </Panel.Content>- <Divider light />- <Panel.Content>- <Input- label="Port"- style={{- width: '50%',- }}- readOnly- disabled- value={connectionInfo.db_port}- layout="horizontal"- />- </Panel.Content>- <Divider light />- <Panel.Content>- <Input- label="User"- style={{- width: '50%',- }}- readOnly- disabled- value={connectionInfo.db_user}- layout="horizontal"- />- </Panel.Content>- <Divider light />- <Panel.Content>- <Input- label="Password"- disabled- readOnly- value={'[The password you provided when you created this project]'}- layout="horizontal"- />- </Panel.Content>- <Divider light />- <Panel.Content>- <DownloadCertificate createdAt={connectionInfo.inserted_at} />- </Panel.Content>- </div>- </Panel>- <section>- <Panel- title={[- <Typography.Title key="panel-title" level={5} className="mb-0">- Connection string- </Typography.Title>,- ]}- >- <Panel.Content className="space-y-4">- <Input- copy- readOnly- disabled- layout="vertical"- value={- `postgres://${connectionInfo.db_user}:[YOUR-PASSWORD]@` +- `${connectionInfo.db_host}:${connectionInfo.db_port}` +- `/${connectionInfo.db_name}`- }- />+ <PgBouncerConfig config={bouncerInfo} projectRef={projectRef} />- <div className="flex space-x-3">- <p className="text-sm text-scale-1100">- <p>- Learn more about connection strings{' '}- <Typography.Link href="https://supabase.com/docs/reference/postgres/connection-strings">- with Supabase- </Typography.Link>{' '}- and{' '}- <Typography.Link href="https://www.postgresql.org/docs/current/libpq-connect.html">- read the official documentation- </Typography.Link>- .- </p>- </p>- </div>- </Panel.Content>- </Panel>- </section>- </article>)}diff --git a/studio/components/interfaces/Database/Pooling/ConnectionPoolingSettings.tsx b/studio/components/interfaces/Database/Pooling/ConnectionPoolingSettings.tsxnew file mode 100644index 00000000000..70d33c3f8ea--- /dev/null+++ b/studio/components/interfaces/Database/Pooling/ConnectionPoolingSettings.tsx@@ -0,0 +1,211 @@+import { FC, useState, useEffect } from 'react'+import { observer } from 'mobx-react-lite'+import { Typography } from '@supabase/ui'+import { useStore } from 'hooks'+import { pluckObjectFields } from 'lib/helpers'+import Loading from 'components/ui/Loading'+import Panel from 'components/to-be-cleaned/Panel'+import Divider from 'components/ui/Divider'+import { AutoField } from 'uniforms-bootstrap4'+import { API_URL } from 'lib/constants'+import { patch } from 'lib/common/fetch'+import ToggleField from 'components/to-be-cleaned/forms/ToggleField'+import SchemaFormPanel from 'components/to-be-cleaned/forms/SchemaFormPanel'+import { Input } from '@supabase/ui'++interface Props {}++const BouncerSettings: FC<Props> = ({}) => {+ const { ui, app } = useStore()+ const projectRef = ui.selectedProject?.ref ?? 'default'++ const [isLoading, setIsLoading] = useState<boolean>(true)+ const [poolingConfiguration, setPoolingConfiguration] = useState<any>()++ useEffect(() => {+ fetchPoolingConfiguration()+ }, [])++ const fetchPoolingConfiguration = async () => {+ setIsLoading(true)+ const response = await app.database.getPoolingConfiguration(projectRef)+ setPoolingConfiguration(response)+ setIsLoading(false)+ }++ if (isLoading) return <Loading />+ if (poolingConfiguration.error) {+ return (+ <div className="p-4">+ <Typography.Text type="secondary">Error loading pooling configuration</Typography.Text>+ </div>+ )+ }++ const { project } = poolingConfiguration++ // for older projects+ if (!project.pgbouncer_enabled && project.pool_mode == null)+ return (+ <Panel+ title={+ <Typography.Title key="panel-title" level={5} className="mb-0">+ Connection Pooling is not available for this project+ </Typography.Title>+ }+ >+ <Panel.Content>+ <Typography.Text type="secondary">Please start a new project to enable this feature.</Typography.Text>+ </Panel.Content>+ </Panel>+ )+ const formModel = project+ const DB_FIELDS = ['db_host', 'db_name', 'db_port', 'db_user', 'inserted_at']+ const connectionInfo = pluckObjectFields(formModel, DB_FIELDS)+ const BOUNCER_FIELDS = [+ 'default_pool_size',+ 'ignore_startup_parameters',+ 'pool_mode',+ 'pgbouncer_enabled',+ ]+ const bouncerInfo = pluckObjectFields(formModel, BOUNCER_FIELDS)+ return (+ <PgbouncerConfig config={bouncerInfo} projectRef={projectRef} />+ )+}++export default observer(BouncerSettings)+++interface ConfigProps {+ projectRef: string+ config: any+}++export const PgbouncerConfig: FC<ConfigProps> = observer(({ projectRef, config }) => {+ const { ui } = useStore()++ const [updates, setUpdates] = useState<any>({+ // pgbouncer_status: config.pgbouncer_status,+ pgbouncer_enabled: config.pgbouncer_enabled,+ pool_mode: config.pool_mode || 'transaction',+ default_pool_size: config.default_pool_size || '',+ ignore_startup_parameters: config.ignore_startup_parameters || '',+ })++ const updateConfig = async (updatedConfig: any) => {+ try {+ const response = await patch(`${API_URL}/props/pooling/${projectRef}/config`, updatedConfig)+ if (response.error) {+ throw response.error+ } else {+ setUpdates({ ...response.project })+ ui.setNotification({ category: 'success', message: 'Successfully saved settings' })+ }+ } catch (error: any) {+ ui.setNotification({+ category: 'error',+ message: `Failed to update config: ${error.message}`,+ })+ }+ }++ const formSchema = {+ properties: {+ pgbouncer_enabled: {+ title: 'Enabled',+ type: 'boolean',+ help: 'Activates / deactivates Connection Pooling.',+ },+ pool_mode: {+ title: 'Pool Mode',+ type: 'string',+ options: [+ {+ label: 'Transaction',+ value: 'transaction',+ },+ {+ label: 'Session',+ value: 'session',+ },+ {+ label: 'Statement',+ value: 'statement',+ },+ ],+ },+ ignore_startup_parameters: {+ title: 'Ignore Startup Parameters',+ type: 'string',+ readOnly: true,+ help: 'Defaults are either blank or "extra_float_digits"',+ },+ },+ required: ['pool_mode'],+ type: 'object',+ }++ return (+ <>+ <SchemaFormPanel+ title="Connection Pooling Settings"+ schema={formSchema}+ model={updates}+ submitLabel="Save"+ cancelLabel="Cancel"+ onChangeModel={(model: any) => setUpdates(model)}+ onSubmit={(model: any) => updateConfig(model)}+ onReset={() => setUpdates(config)}+ >+ <div className="space-y-6 py-4">+ <ToggleField name="pgbouncer_enabled" />+ <Divider light />++ <Input+ className="input-mono"+ layout="horizontal"+ readOnly+ copy+ disabled+ value="44444444444444"+ label="Port"+ />++ <Divider light />+ {/* <AutoField name="pgbouncer_status" disabled={true} /> */}+ {updates.pgbouncer_enabled && (+ <>+ <AutoField+ name="pool_mode"+ showInlineError+ errorMessage="You must select one of the three options"+ />+ <div className="flex !mt-1" style={{ marginLeft: 'calc(33% + 0.5rem)' }}>+ <p className="text-sm text-scale-900">+ Specify when a connection can be returned to the pool. To find out the most+ suitable mode for your use case,{' '}+ <a+ className="text-green-900"+ target="_blank"+ href="https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pool"+ >+ click here+ </a>+ .+ </p>+ </div>+ <Divider light />+ {/* <AutoField+ name="default_pool_size"+ showInlineError+ errorMessage="Value must be within 1 and 20"+ /> */}+ <AutoField name="ignore_startup_parameters" />+ </>+ )}+ </div>+ </SchemaFormPanel>+ </>+ )+})\ No newline at end of filediff --git a/studio/components/interfaces/Database/Pooling/PgBouncerConfig.tsx b/studio/components/interfaces/Database/Pooling/PgBouncerConfig.tsxindex 387d8f82fe3..01e3ba0967c 100644--- a/studio/components/interfaces/Database/Pooling/PgBouncerConfig.tsx+++ b/studio/components/interfaces/Database/Pooling/PgBouncerConfig.tsx@@ -1,6 +1,5 @@import { FC, useState } from 'react'import { observer } from 'mobx-react-lite'-import { Typography } from '@supabase/ui'import Divider from 'components/ui/Divider'import { AutoField } from 'uniforms-bootstrap4'@@ -9,6 +8,7 @@ import { API_URL } from 'lib/constants'import { patch } from 'lib/common/fetch'import ToggleField from 'components/to-be-cleaned/forms/ToggleField'import SchemaFormPanel from 'components/to-be-cleaned/forms/SchemaFormPanel'+import { Input } from '@supabase/ui'interface Props {projectRef: string@@ -48,7 +48,7 @@ const PgbouncerConfig: FC<Props> = ({ projectRef, config }) => {pgbouncer_enabled: {title: 'Enabled',type: 'boolean',- help: 'Activates/ deactivates Connection Pooling.',+ help: 'Activates / deactivates Connection Pooling.',},pool_mode: {title: 'Pool Mode',@@ -81,52 +81,64 @@ const PgbouncerConfig: FC<Props> = ({ projectRef, config }) => {return (<>- <SchemaFormPanel- title="Configuration"- schema={formSchema}- model={updates}- submitLabel="Save"- cancelLabel="Cancel"- onChangeModel={(model: any) => setUpdates(model)}- onSubmit={(model: any) => updateConfig(model)}- onReset={() => setUpdates(config)}- >- <div className="space-y-6 py-4">- <ToggleField name="pgbouncer_enabled" />- <Divider light />- {/* <AutoField name="pgbouncer_status" disabled={true} /> */}- {updates.pgbouncer_enabled && (- <>- <AutoField- name="pool_mode"- showInlineError- errorMessage="You must select one of the three options"- />- <div className="flex !mt-1" style={{ marginLeft: 'calc(33% + 0.5rem)' }}>- <p className="text-sm text-scale-900">- Specify when a connection can be returned to the pool. To find out the most- suitable mode for your use case,{' '}- <a- className="text-green-900"- target="_blank"- href="https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pool"- >- click here- </a>- .- </p>- </div>- <Divider light />- {/* <AutoField- name="default_pool_size"- showInlineError- errorMessage="Value must be within 1 and 20"- /> */}- <AutoField name="ignore_startup_parameters" />- </>- )}- </div>- </SchemaFormPanel>+ <SchemaFormPanel+ title="Connection Pooling Settings"+ schema={formSchema}+ model={updates}+ submitLabel="Save"+ cancelLabel="Cancel"+ onChangeModel={(model: any) => setUpdates(model)}+ onSubmit={(model: any) => updateConfig(model)}+ onReset={() => setUpdates(config)}+ >+ <div className="space-y-6 py-4">+ <ToggleField name="pgbouncer_enabled" />+ <Divider light />++ <Input+ className="input-mono"+ layout="horizontal"+ readOnly+ copy+ disabled+ value="44444444444444"+ label="Port"+ />++ <Divider light />+ {/* <AutoField name="pgbouncer_status" disabled={true} /> */}+ {updates.pgbouncer_enabled && (+ <>+ <AutoField+ name="pool_mode"+ showInlineError+ errorMessage="You must select one of the three options"+ />+ <div className="flex !mt-1" style={{ marginLeft: 'calc(33% + 0.5rem)' }}>+ <p className="text-sm text-scale-900">+ Specify when a connection can be returned to the pool. To find out the most+ suitable mode for your use case,{' '}+ <a+ className="text-green-900"+ target="_blank"+ href="https://supabase.com/docs/guides/database/connecting-to-postgres#connection-pool"+ >+ click here+ </a>+ .+ </p>+ </div>+ <Divider light />+ {/* <AutoField+ name="default_pool_size"+ showInlineError+ errorMessage="Value must be within 1 and 20"+ /> */}+ <AutoField name="ignore_startup_parameters" />+ </>+ )}+ </div>+ </SchemaFormPanel></>)}diff --git a/studio/components/to-be-cleaned/forms/SchemaFormPanel.js b/studio/components/to-be-cleaned/forms/SchemaFormPanel.jsindex a88aa4a1cf0..23301d11ff0 100644--- a/studio/components/to-be-cleaned/forms/SchemaFormPanel.js+++ b/studio/components/to-be-cleaned/forms/SchemaFormPanel.js@@ -39,9 +39,9 @@ export default function SchemaFormPanel({<section className="section-block mb-8"><divclassName="- px-6 h-12- bg-panel-header-light dark:bg-panel-header-dark- border-b border-panel-border-light dark:border-panel-border-dark+ px-6 h-12+ bg-panel-header-light dark:bg-panel-header-dark+ border-b border-panel-border-light dark:border-panel-border-darkflex overflow-hidden items-center"><div className="flex-1 text-left">diff --git a/studio/pages/project/[ref]/settings/database.tsx b/studio/pages/project/[ref]/settings/database.tsxindex 52e6c064560..a45a2e5f6f3 100644--- a/studio/pages/project/[ref]/settings/database.tsx+++ b/studio/pages/project/[ref]/settings/database.tsx@@ -21,11 +21,17 @@ import Panel from 'components/to-be-cleaned/Panel'import { ProjectUsageMinimal } from 'components/to-be-cleaned/Usage'import DateRangePicker from 'components/to-be-cleaned/DateRangePicker'import ChartHandler from 'components/to-be-cleaned/Charts/ChartHandler'+import { BouncerSettings } from 'components/interfaces/Database'+import ConnectionPoolingSettings from 'components/interfaces/Database/Pooling/ConnectionPoolingSettings'dayjs.extend(customParseFormat)dayjs.extend(timezone)dayjs.extend(utc)++++const ProjectSettings = () => {const router = useRouter()const { ref } = router.query@@ -37,8 +43,11 @@ const ProjectSettings = () => {<SettingsLayout title="Database"><div className="content w-full h-full overflow-y-auto"><div className="w-full px-4 py-4 max-w-5xl">+ <ConnectionPoolingSettings />+ <BouncerSettings /><Usage project={project} /><GeneralSettings projectRef={ref} />+ {/* move bouncer settings back down here ->>>>>>>>>>>>> <BouncerSettings /> */}</div></div></SettingsLayout>@@ -289,6 +298,24 @@ const DownloadCertificate: FC<any> = ({ createdAt }) => {const GeneralSettings: FC<any> = ({ projectRef }) => {const { data, error }: any = useSWR(`${API_URL}/props/project/${projectRef}/settings`, get)+ const { app } = useStore()+++ useEffect(() => {+ console.log('fetchPoolingConfiguration()')+ fetchPoolingConfiguration()+ }, [])++ const fetchPoolingConfiguration = async () => {+ // setIsLoading(true)+ const response = await app.database.getPoolingConfiguration(projectRef)+ console.log('response is: ', response)+ // setPoolingConfiguration(response)+ // setIsLoading(false)+ }+++if (data?.error || error) {return (<div className="p-6 mx-auto sm:w-full md:w-3/4 text-center">@@ -307,10 +334,11 @@ const GeneralSettings: FC<any> = ({ projectRef }) => {const { project } = dataconst formModel = toJS(project)+ console.log(formModel)const DB_FIELDS = ['db_host', 'db_name', 'db_port', 'db_user', 'inserted_at']const connectionInfo = pluckObjectFields(formModel, DB_FIELDS)- const uriConnString =+const uriConnString =`postgresql://${connectionInfo.db_user}:[YOUR-PASSWORD]@` +`${connectionInfo.db_host}:${connectionInfo.db_port.toString()}` +`/${connectionInfo.db_name}`