Repository: edgedb/edgedb

Issue:
3.0-rc.1 docker image `edb.server.pgcon.errors.BackendError: column "datlastsysoid" does not exist`
Using the 3.0 release candidate docker image, the instance fails to bootstrap. I am using external postgres instance and setting  EDGEDB_SERVER_BACKEND_DSN. I just replace the image keeping everything same but v2 images all work perfectly but v3 doesn't bootstrap. I obviously test with empty postgres backend.
```
Bootstrapping EdgeDB instance on remote Postgres cluster...
2023-05-19 23:27:17 INFO 39 2023-05-20T03:27:17.008 edb.server: starting EdgeDB server 3.0-rc.1+a75e964, built on 2023-05-18T23:40Z from revision db7a0d1af (2023-05-18T02:03Z) for aarch64-unknown-linux-gnu
2023-05-19 23:27:17 INFO 39 2023-05-20T03:27:17.008 edb.server: instance name: '_unknown'
2023-05-19 23:27:23 INFO 39 2023-05-20T03:27:23.203 edb.server: Detected 97 backend connections available.
2023-05-19 23:27:23 INFO 39 2023-05-20T03:27:23.258 edb.server: Creating template database...
2023-05-19 23:27:25 INFO 39 2023-05-20T03:27:25.119 edb.server: Creating the necessary PostgreSQL extensions...
2023-05-19 23:27:25 INFO 39 2023-05-20T03:27:25.150 edb.server: Initializing the standard library...
2023-05-19 23:27:31 ---- Exception occurred: column "datlastsysoid" does not exist ----
2023-05-19 23:27:31 
2023-05-19 23:27:31 1. edb.server.pgcon.errors.BackendError: column "datlastsysoid" does not exist
2023-05-19 23:27:31 
2023-05-19 23:27:31 ---- Source Context ----
2023-05-19 23:27:31 
2023-05-19 23:27:31     query, line 13, in query
2023-05-19 23:27:31         | 
2023-05-19 23:27:31         |     SELECT
2023-05-19 23:27:31         |         oid,
2023-05-19 23:27:31         |         edgedb.get_current_database()::name as datname,
2023-05-19 23:27:31         |         datdba,
2023-05-19 23:27:31         |         encoding,
2023-05-19 23:27:31         |         datcollate,
2023-05-19 23:27:31         |         datctype,
2023-05-19 23:27:31         |         datistemplate,
2023-05-19 23:27:31         |         datallowconn,
2023-05-19 23:27:31         |         datconnlimit,
2023-05-19 23:27:31         |         datlastsysoid,
2023-05-19 23:27:31         |         datfrozenxid,
2023-05-19 23:27:31         |         datminmxid,
2023-05-19 23:27:31         |         dattablespace,
2023-05-19 23:27:31         |         datacl,
2023-05-19 23:27:31         |         tableoid, xmin, cmin, xmax, cmax, ctid
2023-05-19 23:27:31         |     FROM pg_database
2023-05-19 23:27:31         | 
2023-05-19 23:27:31         | CREATE  VIEW edgedbsql.pg_database AS
2023-05-19 23:27:31         | 
2023-05-19 23:27:31         |     SELECT
2023-05-19 23:27:31         |         oid,
2023-05-19 23:27:31         |         edgedb.get_current_database()::name as datname,
2023-05-19 23:27:31         |         datdba,
2023-05-19 23:27:31         |         encoding,
2023-05-19 23:27:31         |         datcollate,
2023-05-19 23:27:31         |         datctype,
2023-05-19 23:27:31         |         datistemplate,
2023-05-19 23:27:31         |         datallowconn,
2023-05-19 23:27:31         >         datlastsysoid,
2023-05-19 23:27:31                    ^
2023-05-19 23:27:31         |         datfrozenxid,
2023-05-19 23:27:31         |         datminmxid,
2023-05-19 23:27:31         |         dattablespace,
2023-05-19 23:27:31         |         datacl,
2023-05-19 23:27:31         |         tableoid, xmin, cmin, xmax, cmax, ctid
2023-05-19 23:27:31         |     FROM pg_database
2023-05-19 23:27:31         |     WHERE datname LIKE '%_edgedb'
2023-05-19 23:27:31         
2023-05-19 23:27:31 
2023-05-19 23:27:31 ---- Traceback ----
2023-05-19 23:27:31 
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/bin/edgedb-server.py, line 7, in <module>
2023-05-19 23:27:31         > sys.exit(main())
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 829, in __call__
2023-05-19 23:27:31         > return self.main(*args, **kwargs)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 782, in main
2023-05-19 23:27:31         > rv = self.invoke(ctx)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 1236, in invoke
2023-05-19 23:27:31         > return Command.invoke(self, ctx)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 1066, in invoke
2023-05-19 23:27:31         > return ctx.invoke(self.callback, **ctx.params)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 610, in invoke
2023-05-19 23:27:31         > return callback(*args, **kwargs)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/decorators.py, line 21, in new_func
2023-05-19 23:27:31         > return f(get_current_context(), *args, **kwargs)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 727, in main
2023-05-19 23:27:31         > server_main(**kwargs)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 707, in server_main
2023-05-19 23:27:31         > asyncio.run(run_server(server_args))
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/asyncio/runners.py, line 44, in run
2023-05-19 23:27:31         > return loop.run_until_complete(main)
2023-05-19 23:27:31     uvloop/loop.pyx, line 1517, in uvloop.loop.Loop.run_until_complete
2023-05-19 23:27:31         
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 559, in run_server
2023-05-19 23:27:31         > new_instance = await _init_cluster(cluster, args)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 145, in _init_cluster
2023-05-19 23:27:31         > new_instance = await bootstrap.ensure_bootstrapped(cluster, args)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 2126, in ensure_bootstrapped
2023-05-19 23:27:31         > await _bootstrap(ctx)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 1998, in _bootstrap
2023-05-19 23:27:31         > stdlib, config_spec, compiler = await _init_stdlib(
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 1311, in _init_stdlib
2023-05-19 23:27:31         > await metaschema.generate_support_views(
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/pgsql/metaschema.py, line 6506, in generate_support_views
2023-05-19 23:27:31         > await _execute_block(conn, block)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/pgsql/metaschema.py, line 7317, in _execute_block
2023-05-19 23:27:31         > await execute_sql_script(conn, block.to_string())
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/pgsql/metaschema.py, line 7336, in execute_sql_script
2023-05-19 23:27:31         > await conn.sql_execute(sql_text.encode("utf-8"))
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 152, in sql_execute
2023-05-19 23:27:31         > return await self._retry_conn_errors(_task)
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 144, in _retry_conn_errors
2023-05-19 23:27:31         > result = await task()
2023-05-19 23:27:31     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 151, in _task
2023-05-19 23:27:31         > await self._conn.sql_execute(sql)
2023-05-19 23:27:31     edb/server/pgcon/pgcon.pyx, line 1507, in sql_execute
2023-05-19 23:27:31         
2023-05-19 23:27:31     edb/server/pgcon/pgcon.pyx, line 1489, in _sql_execute
2023-05-19 23:27:31         
2023-05-19 23:27:31 
2023-05-19 23:27:31 edb.server.pgcon.errors.BackendError: column "datlastsysoid" does not exist
2023-05-19 23:27:32 ERROR: Could not complete instance bootstrap
```

After restarting the container, it fails to start again.
```
2023-05-20 17:06:26 Bootstrapping EdgeDB instance on remote Postgres cluster...
2023-05-20 17:06:28 INFO 39 2023-05-20T21:06:28.021 edb.server: starting EdgeDB server 3.0-rc.1+a75e964, built on 2023-05-18T23:40Z from revision db7a0d1af (2023-05-18T02:03Z) for aarch64-unknown-linux-gnu
2023-05-20 17:06:28 INFO 39 2023-05-20T21:06:28.021 edb.server: instance name: '_unknown'
2023-05-20 17:06:29 INFO 39 2023-05-20T21:06:29.109 edb.server: Detected 97 backend connections available.
2023-05-20 17:06:29 ---- Exception occurred: database instance is corrupt ----
2023-05-20 17:06:29 
2023-05-20 17:06:29 1. edb.errors.ConfigurationError: database instance is corrupt
2023-05-20 17:06:29 
2023-05-20 17:06:29 ---- Traceback ----
2023-05-20 17:06:29 
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/bin/edgedb-server.py, line 7, in <module>
2023-05-20 17:06:29         > sys.exit(main())
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 829, in __call__
2023-05-20 17:06:29         > return self.main(*args, **kwargs)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 782, in main
2023-05-20 17:06:29         > rv = self.invoke(ctx)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 1236, in invoke
2023-05-20 17:06:29         > return Command.invoke(self, ctx)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 1066, in invoke
2023-05-20 17:06:29         > return ctx.invoke(self.callback, **ctx.params)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/core.py, line 610, in invoke
2023-05-20 17:06:29         > return callback(*args, **kwargs)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/click/decorators.py, line 21, in new_func
2023-05-20 17:06:29         > return f(get_current_context(), *args, **kwargs)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 727, in main
2023-05-20 17:06:29         > server_main(**kwargs)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 707, in server_main
2023-05-20 17:06:29         > asyncio.run(run_server(server_args))
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/asyncio/runners.py, line 44, in run
2023-05-20 17:06:29         > return loop.run_until_complete(main)
2023-05-20 17:06:29     uvloop/loop.pyx, line 1517, in uvloop.loop.Loop.run_until_complete
2023-05-20 17:06:29         
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 559, in run_server
2023-05-20 17:06:29         > new_instance = await _init_cluster(cluster, args)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/main.py, line 145, in _init_cluster
2023-05-20 17:06:29         > new_instance = await bootstrap.ensure_bootstrapped(cluster, args)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 2129, in ensure_bootstrapped
2023-05-20 17:06:29         > await _start(ctx)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 1904, in _start
2023-05-20 17:06:29         > conn = await _check_catalog_compatibility(ctx)
2023-05-20 17:06:29     /usr/lib/aarch64-linux-gnu/edgedb-server-3-rc1/lib/python3.10/site-packages/edb/server/bootstrap.py, line 1801, in _check_catalog_compatibility
2023-05-20 17:06:29         > raise errors.ConfigurationError(
2023-05-20 17:06:29 
2023-05-20 17:06:29 ---- Details ----
2023-05-20 17:06:29 Details: The database instance does not appear to have been fully initialized or has been corrupted.
2023-05-20 17:06:29 
2023-05-20 17:06:29 
2023-05-20 17:06:29 edb.errors.ConfigurationError: database instance is corrupt
2023-05-20 17:06:30 ERROR: Could not complete instance bootstrap
```

- EdgeDB Version: 3.0-rc.1
- EdgeDB CLI Version: 
- OS Version: docker

Steps to Reproduce:

1. Set EDGEDB_SERVER_BACKEND_DSN and run docker image with tag `3.0-rc.1`


Discussion:
The prognosis here is incompatibility with Postgres 15. Can you check which version are you using?

Our official stance on Postgres 15 is ["not yet supported"](https://github.com/edgedb/edgedb/issues/5231), but we are planning to support it. Result of this is that I've not noticed that tests for 15 were failing in CI, so a few bugs got trough.

For now, I suggest using postgres 13 or 14, but I'll push a fix for postgres 15 that should make it into rc2 and 3.0.

Resolving patch:
diff --git a/edb/pgsql/metaschema.py b/edb/pgsql/metaschema.py
--- a/edb/pgsql/metaschema.py
+++ b/edb/pgsql/metaschema.py
@@ -5943,7 +5943,7 @@ def _generate_sql_information_schema() -> List[dbops.Command]:
             datistemplate,
             datallowconn,
             datconnlimit,
-            datlastsysoid,
+            0::oid AS datlastsysoid,
             datfrozenxid,
             datminmxid,
             dattablespace,


Test patch: