CockroachDB · error reference
CockroachDB: unknown function pg_total_relation_size()
UndefinedFunctionError: unknown function: pg_total_relation_size()
CockroachDB speaks the Postgres wire protocol but does not implement every pg_catalog function. Why tools that introspect Postgres fail on the size query specifically.
What the database is telling you
CockroachDB implements the Postgres wire protocol and most of pg_catalog, which is why psql and asyncpg connect happily. It does not implement every administrative function, and the relation-size family is one of the gaps — the catalog tables exist, the function does not.
Why it shows up in a migration
Introspection is where this bites, because size is usually collected in the same query as the table list. One unimplemented function in the SELECT list takes the whole query down, so a tool that could have listed every table returns nothing and reports that it cannot read the schema — a total failure caused by an optional column.
Common causes
- A Postgres introspection query using pg_total_relation_size, pg_relation_size or pg_table_size against CockroachDB.
- Size and table metadata combined into a single SELECT, so the gap is fatal rather than cosmetic.
- Dashboards and 'largest tables' queries ported straight from Postgres.
How to fix it
- 1
Separate the size column from the table list, so a missing function costs you the estimate rather than the inventory.
-- table list: works everywhere SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'; -- size: Postgres only, run separately SELECT pg_total_relation_size('public.orders'); - 2
On CockroachDB, read size from its own range statistics instead.
SHOW RANGES FROM TABLE orders;
- 3
Treat row-count and size estimates as optional metadata generally — plenty of engines will not give them cheaply.
What DBShifts does about it
The Postgres introspector runs the table list and the size lookup as separate statements, so on CockroachDB the size degrades to unavailable while the schema reads normally. This was a real failure of ours: every CockroachDB source pair errored during introspection until the queries were split.
PostgreSQL introspector
Migrating between engines?
DBShifts converts the schema, moves the data, and then proves the two sides match with a type-aware checksum per table — not just a row count. Errors like this one are handled on the way, and the ones that cannot be handled are reported rather than logged and forgotten.
Related errors
CockroachDB
CockroachDB: session_replication_role is not supported
The standard Postgres trick for loading data with foreign keys disabled does not exist on CockroachDB. What to do instead, and why the usual workaround is unnecessary here.
CockroachDB
CockroachDB: at or near "restart" syntax error on TRUNCATE
TRUNCATE ... RESTART IDENTITY CASCADE is valid Postgres and a syntax error on CockroachDB. The difference, and what to use instead.