DEV Community

Unique PostgreSQL-compatible Distributed SQL database

While many other distributed SQL databases claim PostgreSQL compatibility by using the same wire protocol and similar syntax, YugabyteDB stands out by actually using the same code and libraries as PostgreSQL.

To ensure consistent behavior, as in PostgreSQL, it's necessary to use PostgreSQL rather than re-implement its features from scratch. For example, different programming languages may have subtle variations in interpreting complex evaluations, like regular expressions, and differences in handling arithmetic operations on data types. While none of these behaviors are inherently right or wrong, if your application is designed for PostgreSQL, you'd prefer to have the same behavior on a PostgreSQL-compatible database to avoid wrong results. The most reliable way to achieve this is by using the same code.

Here is a simple example. PostgreSQL response to select 42 * (1/2) may be surprising, but it is zero because 1/2 is converted to an int:

postgres=>  select 42 * (1/2);
 ?column?
----------
        0
(1 row)
Enter fullscreen mode Exit fullscreen mode

YugabyteDB returns the same result because it has the same C code. Many other databases return 21 as a float. A PostgreSQL-compatible database must return the same as PostgreSQL, or the application developed, tested, and operating for years on PostgreSQL may corrupt data in corner cases.

In terms of features, just implementing basic functionality and listing them as 'supported' is not enough. Applications built on PostgreSQL use all features, including their various options. YugabyteDB is based on PostgreSQL 11, with some merges from higher versions. PostgreSQL 15 features will soon be available, and the future versions will include newer PostgreSQL evolutions. The upgrade of YugabyteDB is rolling, with zero downtime, and this will apply to the versions that raise the PostgreSQL compatibility. The features do not only include SQL commands but also the PostgreSQL catalog views because many tools, such as ORMs, query them.

YugabyteDB uses the PostgreSQL catalog. Like with PostgreSQL, you can see the queries on catalog that are run by psql when running it with -E or \set ECHO_HIDDEN on:

yugabyte=# \set ECHO_HIDDEN on

yugabyte=# \d demo

********* QUERY **********
SELECT c.oid,
  n.nspname,
  c.relname
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname OPERATOR(pg_catalog.~) '^(demo)$'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 2, 3;
**************************

********* QUERY **********
SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, c.relhasoids, c.relispartition, '', c.reltablespace, CASE WH
EN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, c.relpersistence, c.relreplident
FROM pg_catalog.pg_class c
 LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)
WHERE c.oid = '17299';
**************************
...
Enter fullscreen mode Exit fullscreen mode

PostgreSQL compatibility | YugabyteDB Docs

Summary of YugabyteDB's PostgreSQL compatibility

favicon docs.yugabyte.com

Top comments (0)