The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
docs: add guide for using supabase inspect db
Long Hoang31ba007c5bd6
diff --git a/apps/docs/pages/guides/database/inspect.mdx b/apps/docs/pages/guides/database/inspect.mdxnew file mode 100644index 00000000000..6ae06848231--- /dev/null+++ b/apps/docs/pages/guides/database/inspect.mdx@@ -0,0 +1,162 @@+import Layout from '~/layouts/DefaultGuideLayout'++export const meta = {+ id: 'json',+ title: 'Inspect your Postgres database',+ description: 'Inspecting your Postgres database for common issues around disk, query performance, index, locks, and more using the terminal.',+}++## Inspect from the terminal++The Supabase CLI comes with a range of tools to help inspect your Postgres instances for potential issues. Most tools are compatible with any Postgres databases regardless if they are a Supabase project or not.++### Installing the Supabase CLI++<Tabs+ scrollable+ size="small"+ type="underlined"+ defaultActiveId="npm"+>+<TabPanel id="npm" label="npm">++Install the CLI as dev dependency via [npm](https://www.npmjs.com/package/supabase):++```sh+npm install supabase --save-dev+```++Run the CLI by prefixing each command with `npx` (only applicable when installing through `npm`):++```sh+npx supabase <command>+```++</TabPanel>+<TabPanel id="macos" label="macOS">++Install the CLI with [Homebrew](https://brew.sh):++```sh+brew install supabase/tap/supabase+```++</TabPanel>+<TabPanel id="windows" label="Windows">++Install the CLI with [Scoop](https://scoop.sh):++```powershell+scoop bucket add supabase https://github.com/supabase/scoop-bucket.git+scoop install supabase+```++</TabPanel>+<TabPanel id="linux" label="Linux">++The CLI is available through [Homebrew](https://brew.sh) and Linux packages.++#### Homebrew++```sh+brew install supabase/tap/supabase+```++#### Linux packages++Linux packages are provided in [Releases](https://github.com/supabase/cli/releases).+To install, download the `.apk`/`.deb`/`.rpm` file depending on your package manager+and run one of the following:++- `sudo apk add --allow-untrusted <...>.apk`+- `sudo dpkg -i <...>.deb`+- `sudo rpm -i <...>.rpm`++</TabPanel>+</Tabs>++### The `inspect db` command++The inspection tools for your Postgres database are under then `inspect db` command. You can get a full list of available commands by running `supabase inspect db help`.++```+$ supabase inspect db help+Tools to inspect your Supabase database++Usage:+ supabase inspect db [command]++Available Commands:+ bloat Estimates space allocated to a relation that is full of dead tuples+ blocking Show queries that are holding locks and the queries that are waiting for them to be released+ cache-hit Show cache hit rates for tables and indices++...+```++### Connect to any Postgres database++Most inspection commands are Postgres agnostic. You can run inspection routines on any Postgres database even if it is not a Supabase project by providing a connection string via `--db-url`.++For example you can connect to your local Postgres instance:++```+supabase --db-url postgresql://postgres:postgres@localhost:5432/postgres db bloat+```++### Connect to a Supabase instance++Working with Supabase, you can link the Supabase CLI with your project:++```+supabase link --project-ref <project-id>+```++Then the CLI will automatically connect to your Supabase project whenever you are in the project folder and you no longer need to provide `—db-url`.++## Inspection Commands++Below are the db inspection commands provided, grouped by different use cases.++<Admonition type="note">++Some commands might require pg_stats to be enabled or a specific Postgres version to be used.++</Admonition>++### Disk Storage++These commands are handy if you are running low on disk storage:++- bloat - estimates the amount of wasted space+- vacuum-stats - gives information on waste collection routines+- table-record-counts - estimates the number of records per table+- table-sizes - shows the sizes of tables+- index-sizes - shows the sizes of individual index+- table-index-sizes - shows the sizes of indexes for each table++### Query Performance++The commands below are useful if your Postgres database consumes a lot of resources like CPU, RAM or Disk IO. You can also use them to investigate slow queries.++- cache-hit - shows how efficient your cache usage is overall+- unused-indexes - shows indexes with low index scans+- index-usage - shows information about the efficiency of indexes+- seq-scans - show number of sequential scans recorded against all tables+- long-running-queries - shows long running queries that are executing right now+- outliers - shows queries with high execution time but low call count and queries with high proportion of execution time spent on synchronous I/O++### Locks++- locks - shows queries which have taken out an exclusive lock on a relation+- blocking - shows queries that are waiting for locks to be released++### Connections++- role-connections - shows number of active connections for all database roles (Supabase-specific command)+- replication-slots - shows information about replication slots on the database+++export const Page = ({ children }) => <Layout meta={meta} children={children} />++export default Page