Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

postgres extension docs: pg_graphql, wrappers, pg_stat_monitor

Oliver Rice70ec5e1036e6
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
index ba16f51d218..a33c5724c8b 100644
--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
@@ -409,6 +409,11 @@ export const database = {
url: '/guides/database/extensions/pgcron',
items: [],
},
+ {
+ name: 'pg_graphql: GraphQL support',
+ url: '/guides/database/extensions/pg_graphql',
+ items: [],
+ },
{
name: 'pg_jsonschema: JSON Schema Validation',
url: '/guides/database/extensions/pg_jsonschema',
@@ -420,7 +425,12 @@ export const database = {
items: [],
},
{
- name: 'pg_stat_statements: SQL Planning and Execution Statistics',
+ name: 'pg_stat_monitor: Extended Query Performance Monitoring',
+ url: '/guides/database/extensions/pg_stat_monitor',
+ items: [],
+ },
+ {
+ name: 'pg_stat_statements: Query Performance Monitoring,
url: '/guides/database/extensions/pg_stat_statements',
items: [],
},
@@ -445,6 +455,11 @@ export const database = {
url: '/guides/database/extensions/rum',
items: [],
},
+ {
+ name: 'wrappers: 3rd Party Integrations',
+ url: '/guides/database/extensions/rum',
+ items: [],
+ },
],
},
{
diff --git a/apps/docs/pages/guides/database/extensions/pg_graphql.mdx b/apps/docs/pages/guides/database/extensions/pg_graphql.mdx
new file mode 100644
index 00000000000..21be1da6e5b
--- /dev/null
+++ b/apps/docs/pages/guides/database/extensions/pg_graphql.mdx
@@ -0,0 +1,119 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'pg_graphql',
+ title: 'pg_graphql: Native GraphQL for PostgreSQL',
+ description: 'A GraphQL API for PostgreSQL',
+}
+
+[pg_graphql](https://supabase.github.io/pg_graphql/) is PostgreSQL extension for interacting with the database using [GraphQL](https://graphql.org) instead of SQL.
+
+The extension reflects a GraphQL schema from the existing SQL schema and exposes it through a SQL function, `graphql.resolve(...)`. This enables any programming language that can connect to PostgreSQL to query the database via GraphQL with no additional servers, processes, or libraries.
+
+The `pg_graphql` resolve method is designed to interop with [PostgREST](https://postgrest.org/en/stable/index.html), the tool that underpins the Supabase API, such that the `graphql.resolve` function can be called via RPC to safely and performantly expose the GraphQL API over HTTP/s.
+
+For more information about how the SQL schema is reflected into a GraphQL schema, see the [pg_graphql API docs](https://supabase.github.io/pg_graphql/api/).
+
+## Usage
+
+### Enable the extension
+
+<Tabs
+ scrollable
+ size="small"
+ type="underlined"
+ defaultActiveId="dashboard"
+>
+<TabPanel id="dashboard" label="Dashboard">
+
+1. Go to the [Database](https://app.supabase.com/project/_/database/tables) page in the Dashboard.
+2. Click on **Extensions** in the sidebar.
+3. Search for "pg_graphql" and enable the extension.
+
+</TabPanel>
+<TabPanel id="sql" label="SQL">
+
+{/* prettier-ignore */}
+```sql
+-- Enable the "pg_graphql" extension
+create extension pg_graphql;
+
+-- Disable the "pg_graphql" extension
+drop extension if exists pg_graphql;
+```
+
+Even though the SQL code is `create extension`, this is the equivalent of "enabling the extension".
+To disable an extension you can call `drop extension`.
+
+</TabPanel>
+</Tabs>
+
+## Usage
+
+Given a table
+
+{/* prettier-ignore */}
+```sql
+create table "Blog"(
+ id serial primary key,
+ name varchar(255) not null,
+ description varchar(255),
+);
+
+insert into "Blog"(name)
+values ('My Blog');
+```
+
+The reflected GraphQL schema can be queries immediately as
+
+{/* prettier-ignore */}
+```sql
+select
+ graphql.resolve($$
+ {
+ blogCollection(first: 1) {
+ edges {
+ node {
+ id,
+ name
+ }
+ }
+ }
+ }
+ $$);
+```
+
+returning the JSON
+
+{/* prettier-ignore */}
+```json
+{
+ "data": {
+ "blogCollection": {
+ "edges": [
+ {
+ "node": {
+ "id": 1
+ "name": "My Blog"
+ }
+ }
+ ]
+ }
+ }
+}
+```
+
+Note that pg_graphql fully supports schema introspection so you can connect any IDE or schema inspection tool to see the full set of fields and arguments available in the API.
+
+## API
+
+- [`graphql.resolve`](https://supabase.github.io/pg_graphql/sql_interface/): A SQL function for executing GraphQL queries.
+
+
+## Resources
+
+- Official [`pg_graphql` documentation](https://github.com/supabase/pg_graphql)
+
+export const Page = ({ children }) => <Layout meta={meta} children={children} />
+
+export default Page
diff --git a/apps/docs/pages/guides/database/extensions/pg_stat_monitor.mdx b/apps/docs/pages/guides/database/extensions/pg_stat_monitor.mdx
new file mode 100644
index 00000000000..801f9f7bb92
--- /dev/null
+++ b/apps/docs/pages/guides/database/extensions/pg_stat_monitor.mdx
@@ -0,0 +1,85 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'pg_stat_monitor',
+ title: 'pg_stat_monitor: Query Performance Monitoring',
+ description: 'Query performance monitoring for PostgreSQL',
+}
+
+[pg_stat_monitor](https://github.com/percona/pg_stat_monitor) is query performance monitoring tool that provides query execution statistics in a SQL view named `pg_stat_monitor`. It tracks a superset of statistics available in [`pg_stat_statements`](https://www.postgresql.org/docs/current/pgstatstatements.html).
+
+## Usage
+
+### Enable the extension
+
+<Tabs
+ scrollable
+ size="small"
+ type="underlined"
+ defaultActiveId="dashboard"
+>
+<TabPanel id="dashboard" label="Dashboard">
+
+1. Go to the [Database](https://app.supabase.com/project/_/database/tables) page in the Dashboard.
+2. Click on **Extensions** in the sidebar.
+3. Search for "pg_stat_monitor" and enable the extension.
+
+</TabPanel>
+<TabPanel id="sql" label="SQL">
+
+{/* prettier-ignore */}
+```sql
+-- Enable the "pg_stat_monitor" extension
+create extension pg_stat_monitor with schema extensions;
+
+-- Disable the "pg_stat_monitor" extension
+drop extension if exists pg_stat_monitor;
+```
+
+Even though the SQL code is `create extension`, this is the equivalent of "enabling the extension".
+To disable an extension you can call `drop extension`.
+
+It's good practice to create the extension within a separate schema (like `extensions`) to keep your database clean.
+
+</TabPanel>
+</Tabs>
+
+## Views
+
+{/* prettier-ignore */}
+```sql
+select * from extensions.pg_stat_monitor;
+```
+
+The following table shows a subset of available columns:
+
+| Column Type | Description |
+| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
+| bucket bigint | Data collection unit. The number shows what bucket in a chain a record belongs to |
+| bucket_start_time timestampz | The start time of the bucket |
+| userid oid (references pg_authid.oid) | OID of user who executed the statement |
+| dbid oid (references pg_database.oid) | OID of database in which the statement was executed |
+| toplevel bool | True if the query was executed as a top-level statement (always true if pg_stat_statements.track is set to top) |
+| client_ip inet | The IP address of a client that ran the query |
+| queryid bigint | Hash code to identify identical normalized queries. |
+| planid text | An internally generated ID of a query plan |
+| query_plan text | The sequence of steps used to execute a query. This parameter is only available when pgsm_enable_query_plan is enabled |
+| query text | Text of a representative statement |
+| plans bigint | Number of times the statement was planned (if pg_stat_statements.track_planning is enabled, otherwise zero) |
+| total_plan_time double precision | Total time spent planning the statement, in milliseconds (if pg_stat_statements.track_planning is enabled, otherwise zero) |
+| min_plan_time double precision | Minimum time spent planning the statement, in milliseconds (if pg_stat_statements.track_planning is enabled, otherwise zero) |
+
+A full list of statistics is available in the [pg_stat_monitor](https://docs.percona.com/pg-stat-monitor/reference.html#postgresql-15) docs.
+
+## Functions
+- [`pg_stat_monitor_reset()`](https://docs.percona.com/pg-stat-monitor/functions.html): Resets the statistics tracked by the `pg_stat_monitor` view and deletes all previous data.
+- [`pg_stat_monitor_version()`](https://docs.percona.com/pg-stat-monitor/functions.html): Displays the version of the `pg_stat_monitor` extension.
+
+
+## Resources
+
+- Official [`pg_stat_monitor` documentation](https://github.com/percona/pg_stat_monitor)
+
+export const Page = ({ children }) => <Layout meta={meta} children={children} />
+
+export default Page
diff --git a/apps/docs/pages/guides/database/extensions/pg_stat_statements.mdx b/apps/docs/pages/guides/database/extensions/pg_stat_statements.mdx
index 711878d78c0..e699a30eb8e 100644
--- a/apps/docs/pages/guides/database/extensions/pg_stat_statements.mdx
+++ b/apps/docs/pages/guides/database/extensions/pg_stat_statements.mdx
@@ -2,7 +2,7 @@ import Layout from '~/layouts/DefaultGuideLayout'
export const meta = {
id: 'pg_stat_statements',
- title: 'pg_stat_statements: SQL Planning and Execution Statistics',
+ title: 'pg_stat_statements: Query Performance Monitoring',
description:
'Track planning and execution statistics of all SQL statements executed on the database.',
}
diff --git a/apps/docs/pages/guides/database/extensions/wrappers.mdx b/apps/docs/pages/guides/database/extensions/wrappers.mdx
new file mode 100644
index 00000000000..1368d9e1ece
--- /dev/null
+++ b/apps/docs/pages/guides/database/extensions/wrappers.mdx
@@ -0,0 +1,75 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'wrappers',
+ title: 'wrappers: 3rd Party Integrations',
+ description: '3rd party integrations for PostgreSQL ',
+}
+
+[supabase/wrappers](https://supabase.github.io/wrappers/) is a PostgreSQL extension that provides integrations with external sources so you can interact with third-party data using SQL.
+
+For example, the [Stripe wrapper](https://supabase.github.io/wrappers/stripe/) connects to [Stripe's API](https://stripe.com/docs/api) and exposes each endpoint as a SQL table.
+
+{/* prettier-ignore */}
+```sql
+select
+ customer_id
+ currency
+from
+ stripe.customers;
+
+ customer_id | currency
+--------------------+-----------
+ cus_MJiBtCqOF1Bb3F | usd
+(1 row)
+```
+
+## Usage
+
+### Enable the extension
+
+<Tabs
+ scrollable
+ size="small"
+ type="underlined"
+ defaultActiveId="dashboard"
+>
+<TabPanel id="dashboard" label="Dashboard">
+
+1. Go to the [Database](https://app.supabase.com/project/_/database/tables) page in the Dashboard.
+2. Click on **Extensions** in the sidebar.
+3. Search for "wrappers" and enable the extension.
+
+</TabPanel>
+<TabPanel id="sql" label="SQL">
+
+{/* prettier-ignore */}
+```sql
+-- Enable the "wrappers" extension
+create extension wrappers with schema extensions;
+
+-- Disable the "wrappers" extension
+drop extension if exists wrappers;
+```
+
+</TabPanel>
+</Tabs>
+
+Instructions for setting up connections to each 3rd party service via SQL are avaiable at the links in the integrations section below.
+A web interface for connecting to external data is coming to Supabase Studio in 2023.
+
+## Integrations
+
+- [Firebase](https://supabase.github.io/wrappers/firebase/)
+- [Stripe](https://supabase.github.io/wrappers/stripe/)
+- Airtable - Coming Soon
+- BigQuery - Coming Soon
+- Clickhouse - Coming Soon
+
+## Resources
+
+- Official [`supabase/wrappers` documentation](https://supabase.github.io/wrappers/)
+
+export const Page = ({ children }) => <Layout meta={meta} children={children} />
+
+export default Page