Skip to content

Commit

Permalink
Added pg_catalog doc
Browse files Browse the repository at this point in the history
Added warning to crdb_internal page
  • Loading branch information
ericharmeling committed Feb 10, 2021
1 parent 93d6821 commit bb64665
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 120 deletions.
6 changes: 6 additions & 0 deletions _includes/sidebar-data-v20.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,12 @@
"urls": [
"/${VERSION}/information-schema.html"
]
},
{
"title": "<code>pg_catalog</code>",
"urls": [
"/${VERSION}/pg-catalog.html"
]
}
]
},
Expand Down
29 changes: 26 additions & 3 deletions _includes/sidebar-data-v20.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2230,9 +2230,32 @@
]
},
{
"title": "Information Schema",
"urls": [
"/${VERSION}/information-schema.html"
"title": "Virtual Schemas",
"items": [
{
"title": "Overview",
"urls": [
"/${VERSION}/virtual-schemas.html"
]
},
{
"title": "<code>crdb_internal</code>",
"urls": [
"/${VERSION}/crdb-internal.html"
]
},
{
"title": "<code>information_schema</code>",
"urls": [
"/${VERSION}/information-schema.html"
]
},
{
"title": "<code>pg_catalog</code>",
"urls": [
"/${VERSION}/pg-catalog.html"
]
}
]
},
{
Expand Down
63 changes: 7 additions & 56 deletions v20.1/crdb-internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ toc: true
CockroachDB provides a [virtual schema](virtual-schemas.html) called `crdb_internal` that contains information about CockroachDB internals related to a specific cluster. `crdb_internal` tables are read-only.

{{site.data.alerts.callout_info}}
The `crdb_internal` views typically represent objects that the current user has privilege to access. To ensure you can view all the objects in a database, access it as the `root` user.
The `crdb_internal` views typically represent objects that the current user has privilege to access. To ensure you can view all the objects in a database, access it as a user with [`admin` privileges](authorization.html#admin-role).
{{site.data.alerts.end}}

{{site.data.alerts.callout_danger}}
We do not recommend using `crdb_internal` tables in production environments for the following reasons:
- The contents of `crdb_internal` schema are unstable, and subject to change in new releases of CockroachDB.
- There are memory and latency costs associated with each table in `crdb_internal`. Accessing the tables in the schema can impact cluster stability and performance.
{{site.data.alerts.end}}

## Data exposed by `crdb_internal`
Expand All @@ -31,61 +37,6 @@ Unless specified otherwise, queries to `crdb_internal` assume the [current datab
(62 rows)
~~~

## Tables in `crdb_internal`

`crdb_internal` tables reflect the internals of CockroachDB. As such, the number of tables, and the contents of the tables, in `crdb_internal` can change across CockroachDB versions.

For stability guidance, we have assigned each table one of following levels of stability:

- **Public and programmable** tables are suitable for scripting, testing, and other programmatic purposes

- **Public and non-programmable** tables are suitable for end-user consumption, but are subject to change across major versions and should not be used for programmatic purposes.

- **Reserved** tables are intended for use by CockroachDB developers and are subject to change across minor versions. We do not recommend using reserved tables.

In CockroachDB {{ page.release_info.version }}, `crdb_internal` includes the following tables:

Table | Description | Stability
-------|-------|-----
`backward_dependencies` | Contains information about backward dependencies. | Reserved
`builtin_functions` | Contains information about supported [functions](functions-and-operators.html). | Reserved (use `pg_catalog.pg_proc`)
`cluster_queries` | Contains information about queries running on your cluster. | Public and programmable
`cluster_sessions` | Contains information about cluster sessions, including current and past queries. | See `node_sessions`
`cluster_settings` | Contains information about [cluster settings](cluster-settings.html). | Public and programmable
`cluster_transactions` | Contains information about the transactions running on your cluster. | Public and programmable
`create_statements` | Contains information about tables and indexes in your database. | The following columns of this table are public and programmable:<br/>`database_name`, `schema_name`, `descriptor_id`, `descriptor_type`, `descriptor_name`, `create_statement`, `alter_statements`, `validate_statements`<br/>All other columns are reserved.
`feature_usage` | Contains information about feature usage on your cluster. | Public and non-programmable
`forward_dependencies` | Contains information about forward dependencies. | Reserved
`gossip_alerts` | Contains information about gossip alerts. | Reserved
`gossip_liveness` | Contains information about your cluster's gossip liveness. | The following columns of this table are public and programmable:<br/>`node_id`, `draining`, `decommissioning`, `updated_at`<br/>All other columns are reserved.
`feature_usage` | Contains information about feature usage on your cluster.
`gossip_network` | Contains information about your cluster's gossip network. | Reserved
`gossip_nodes` | Contains information about nodes in your cluster's gossip network. | The following columns of this table are public and programmable:<br/>`node_id`, `is_live`, `ranges`, `leases`<br/>All other columns are reserved.
`index_columns` | Contains information about indexed columns in your cluster. | Public and programmable
`jobs` | Contains information about [jobs](show-jobs.html) running on your cluster. | The following columns of this table are public and programmable:<br/>`job_id`, `job_type`, `description`, `statement`, `user_name`, `status`, `created`, `started`, `finished`, `fraction_completed`, `error`<br/>All other columns are reserved.
`kv_node_status` | Contains information about node status at the [key-value layer](architecture/storage-layer.html). | The following columns of this table are public and programmable:<br/>`node_id`, `network`, `address`, `attrs`, `locality`, `server_version`, `tag`, `platform`, `distribution`, `type`, `started_at`<br/>All other columns are reserved.
`kv_store_status` | Contains information about the key-value store for your cluster. | The following columns of this table are public and programmable:<br/>`node_id`, `store_id`, `attrs`, `capacity`, `available`, `used`, `logical_bytes`, `range_count`, `lease_count`<br/>All other columns are reserved.
`leases` | Contains information about [leases](architecture/replication-layer.html#leases) in your cluster. | Reserved
`node_build_info` | Contains information about nodes in your cluster. | Public and programmable
`node_metrics` | Contains metrics for nodes in your cluster. | Reserved
`node_queries` | Contains information about queries running on nodes in your cluster. | Public and programmable
`node_runtime_info` | Contains runtime information about nodes in your cluster. | Public and programmable
`node_sessions` | Contains information about sessions to nodes in your cluster. | The following columns of this table are public and programmable:<br/>`node_id`, `session_id`, `user_name`, `client_address`, `application_name`, `active_queries`,`last_active_query`, `session_start`<br/>All other columns are reserved.
`node_statement_statistics` | Contains statement statistics for nodes in your cluster. | Public and programmable
`node_transactions` | Contains information about the transactions running on nodes in your cluster. | Public and programmable
`node_txn_stats` | Contains transaction statistics for nodes in your cluster. | Public and programmable
`partitions` | Contains information about [partitions](partitioning.html) in your cluster. | Reserved
`predefined_comments` | Contains predefined comments about your cluster. | Reserved
`ranges` | Contains information about ranges in your cluster. | The following columns of this table are public and programmable:<br/>`range_id`, `start_key`, `end_key`, `database_name`, `table_name`, `index_name`, `replicas`, `lease_holder`<br/>The following columns are public and *non*-programmable:<br/>`start_pretty`, `end_pretty`<br/>All other columns are reserved.
`ranges_no_leases` | Contains information about ranges in your cluster, without leases. | See `ranges`
`schema_changes` | Contains information about schema changes in your cluster. | Reserved
`session_trace` | Contains session trace information for your cluster. | Reserved
`session_variables` | Contains information about [session variables](set-vars.html) in your cluster. | Public and programmable
`table_columns` | Contains information about table columns in your cluster. | Public and programmable
`table_indexes` | Contains information about table indexes in your cluster. | Public and programmable
`tables` | Contains information about tables in your cluster. | The following columns of this table are public and programmable:<br/>`table_id`, `name`, `database_name`, `schema_name`<br/>All other columns are reserved.
`zones` | Contains information about [zone configurations](configure-replication-zones.html) in your cluster. | The following columns of this table are public and programmable:<br/>`zone_id`, `zone_name`, `config_sql`<br/>All other columns are reserved. |

## See also

- [`SHOW`](show-vars.html)
Expand Down
69 changes: 69 additions & 0 deletions v20.1/pg-catalog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: pg_catalog
summary: The pg_catalog schema contains read-only views that you can use for introspection into your database's tables, columns, indexes, and views.
toc: true
---

For PostgreSQL compatibility, CockroachDB provides a [virtual schema](virtual-schemas.html) called `pg_catalog`. The read-only tables in the `pg_catalog` schema roughly correspond to the [system catalogs in PostgreSQL](https://www.postgresql.org/docs/10/catalogs-overview.html).

{{site.data.alerts.callout_info}}
To ensure that you can view all of the tables in `pg_catalog`, query the tables as a user with [`admin` privileges](authorization.html#admin-role).
{{site.data.alerts.end}}

## Data exposed by `pg_catalog`

As stated above, the tables in `pg_catalog` roughly correspond to the PostgreSQL system catalogs. However, not all PostgreSQL system catalogs have a corresponding table in `pg_catalog`, and not all `pg_catalog` tables correspond to a PostgreSQL system catalog.

To see the list of tables in `pg_catalog`, use the following [`SHOW TABLES`](show-tables.html) statement:

{% include copy-clipboard.html %}
~~~ sql
> SHOW TABLES FROM SCHEMA pg_catalog;
~~~

~~~
schema_name | table_name | type | owner | estimated_row_count
--------------+-------------------------+-------+-------+----------------------
pg_catalog | pg_aggregate | table | NULL | NULL
pg_catalog | pg_am | table | NULL | NULL
pg_catalog | pg_attrdef | table | NULL | NULL
pg_catalog | pg_attribute | table | NULL | NULL
...
~~~

{{site.data.alerts.callout_info}}
Unless specified otherwise, queries to `pg_catalog` assume the [current database](sql-name-resolution.html#current-database).
{{site.data.alerts.end}}

The `pg_catalog` tables with no corresponding PostgreSQL system catalog offer additional information about the objects in a database.

For example, if the current database is set as [`movr`](movr.html), to return the `pg_catalog` table with additional information about indexes in `movr` database, you can query the `pg_catalog.pg_indexes` table:

{% include copy-clipboard.html %}
~~~ sql
> SELECT * FROM movr.pg_catalog.pg_indexes;
~~~

~~~
crdb_oid | schemaname | tablename | indexname | tablespace | indexdef
-------------+------------+----------------------------+-----------------------------------------------+------------+---------------------------------------------------------------------------------------------------------------------------------
2055313241 | public | users | primary | NULL | CREATE UNIQUE INDEX "primary" ON movr.public.users USING btree (city ASC, id ASC)
1795576970 | public | vehicles | primary | NULL | CREATE UNIQUE INDEX "primary" ON movr.public.vehicles USING btree (city ASC, id ASC)
1795576969 | public | vehicles | vehicles_auto_index_fk_city_ref_users | NULL | CREATE INDEX vehicles_auto_index_fk_city_ref_users ON movr.public.vehicles USING btree (city ASC, owner_id ASC)
450499963 | public | rides | primary | NULL | CREATE UNIQUE INDEX "primary" ON movr.public.rides USING btree (city ASC, id ASC)
450499960 | public | rides | rides_auto_index_fk_city_ref_users | NULL | CREATE INDEX rides_auto_index_fk_city_ref_users ON movr.public.rides USING btree (city ASC, rider_id ASC)
450499961 | public | rides | rides_auto_index_fk_vehicle_city_ref_vehicles | NULL | CREATE INDEX rides_auto_index_fk_vehicle_city_ref_vehicles ON movr.public.rides USING btree (vehicle_city ASC, vehicle_id ASC)
2315049508 | public | vehicle_location_histories | primary | NULL | CREATE UNIQUE INDEX "primary" ON movr.public.vehicle_location_histories USING btree (city ASC, ride_id ASC, "timestamp" ASC)
969972501 | public | promo_codes | primary | NULL | CREATE UNIQUE INDEX "primary" ON movr.public.promo_codes USING btree (code ASC)
710236230 | public | user_promo_codes | primary | NULL | CREATE UNIQUE INDEX "primary" ON movr.public.user_promo_codes USING btree (city ASC, user_id ASC, code ASC)
(9 rows)
~~~

## See also

- [`SHOW`](show-vars.html)
- [`SHOW DATABASES`](show-databases.html)
- [`SHOW SCHEMAS`](show-schemas.html)
- [`SHOW TABLES`](show-tables.html)
- [SQL Name Resolution](sql-name-resolution.html)
- [Virtual Schemas](virtual-schemas.html)
2 changes: 1 addition & 1 deletion v20.1/virtual-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In addition to the `public` schema, CockroachDB supports a fixed set of virtual

The following virtual schemas are included with CockroachDB:

- `pg_catalog`, provided for compatibility with PostgreSQL.
- [`pg_catalog`](pg-catalog.html), provided for compatibility with PostgreSQL.
- [`information_schema`](information-schema.html), provided for compatibility with the SQL standard.
- [`crdb_internal`](crdb-internal.html), provided for introspection into CockroachDB internals.

Expand Down
Loading

0 comments on commit bb64665

Please sign in to comment.