import { useParams, useTelemetryProps } from 'common' import Link from 'next/link' import { useRouter } from 'next/router' import { useState } from 'react' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, IconAlertTriangle, IconExternalLink, Input, Tabs, } from 'ui' import Panel from 'components/ui/Panel' import ShimmeringLoader from 'components/ui/ShimmeringLoader' import { useProjectSettingsQuery } from 'data/config/project-settings-query' import { useResourceWarningsQuery } from 'data/usage/resource-warnings-query' import { useSelectedOrganization } from 'hooks' import { pluckObjectFields } from 'lib/helpers' import Telemetry from 'lib/telemetry' import ConfirmDisableReadOnlyModeModal from './ConfirmDisableReadOnlyModal' import ResetDbPassword from './ResetDbPassword' import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query' const DatabaseSettings = () => { const router = useRouter() const { ref: projectRef } = useParams() const telemetryProps = useTelemetryProps() const organization = useSelectedOrganization() const selectedOrganization = useSelectedOrganization() const [showConfirmationModal, setShowConfirmationModal] = useState(false) const { data, isLoading, isError } = useProjectSettingsQuery({ projectRef }) const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug }) const { data: resourceWarnings } = useResourceWarningsQuery() const isReadOnlyMode = (resourceWarnings ?? [])?.find((warning) => warning.project === projectRef) ?.is_readonly_mode_enabled ?? false if (isError) { return (

Error loading database settings

) } if (isLoading) { return (

Database Settings

Connection info } className="!m-0" > {Array.from({ length: 5 }).map((_, i) => (
))}
Connection string } className="!m-0" >
) } const { project } = data const DB_FIELDS = ['db_host', 'db_name', 'db_port', 'db_user', 'inserted_at'] const connectionInfo = pluckObjectFields(project, DB_FIELDS) const handleCopy = (labelValue?: string) => Telemetry.sendEvent( { category: 'settings', action: 'copy_connection_string', label: labelValue ? labelValue : '', }, telemetryProps, router ) const uriConnString = `postgresql://${connectionInfo.db_user}:[YOUR-PASSWORD]@` + `${connectionInfo.db_host}:${connectionInfo.db_port.toString()}` + `/${connectionInfo.db_name}` const golangConnString = `user=${connectionInfo.db_user} password=[YOUR-PASSWORD] ` + `host=${connectionInfo.db_host} port=${connectionInfo.db_port.toString()}` + ` dbname=${connectionInfo.db_name}` const psqlConnString = `psql -h ${connectionInfo.db_host} -p ` + `${connectionInfo.db_port.toString()} -d ${connectionInfo.db_name} ` + `-U ${connectionInfo.db_user}` return ( <>

Database Settings

{isReadOnlyMode && ( Project is in read-only mode and database is no longer accepting write requests You have reached 95% of your project's disk space, and read-only mode has been enabled to preserve your database's stability and prevent your project from exceeding its current billing plan. To resolve this, you may:
  • Temporarily disable read-only mode to free up space and reduce your database size
  • {subscription?.plan.id === 'free' ? (
  • Upgrade to the Pro plan {' '} to increase your database size limit to 8GB.
  • ) : subscription?.plan.id === 'pro' && subscription?.usage_billing_enabled ? (
  • Disable your Spend Cap {' '} to allow your project to auto-scale and expand beyond the 8GB database size limit
  • ) : null}
)} Connection info } className="!m-0" > { handleCopy('Host') }} />
Connection string } className="!m-0" > { handleCopy('PSQL') }} /> { handleCopy('URI') }} /> { handleCopy('Golang') }} /> { handleCopy('JDBC') }} /> { handleCopy('.NET') }} /> { handleCopy('Nodejs') }} /> { handleCopy('PHP') }} /> { handleCopy('Python') }} />
setShowConfirmationModal(false)} /> ) } export default DatabaseSettings