We were to set up a new Enterprise Geodatabase, but wanted to create it on the same postgresql server as our internally managed data lake. The creation process failed with a pretty mysterious error: "Error: The Geodatabase system table could not be created. GDB_Items : Error (-4)" that we had a lot of trouble running down. In the end it turned out to be an incompatibility between the Enterprise Geodatabase creation wizard and the volume of data in our data lake. Specifically, here is what I found:
The Enterprise Geodatabase creation process adds a bunch of new types to the database, which are tracked in the pg_types table. Those types are assigned an OID, which is a shared sequential key used in a bunch of places throughout the postgres catalog. In most postgres installs those OID values are pretty low (10s / 100s of thousands). However, in our database which has a few terabytes of pretty complex data in it, those OID values are in the billions, specifically about 2.8 billion.
Here is a csv example of the types added in our database:
oid,typname
2825153047,st_state_data_type
2825153222,st_geometry_set
2825153221,_st_geometry_set
2825153050,_st_state_data_type
The issue is that during the creation process at one point ArcMap casts that OID value to an integer. Not a bigint, just a normal int. When that happens it doesn't return the proper type, because 2.8B is too large to be cast to an integer (caps out at 2.1B) so it can't return the right value. This causes the process to error out because it thinks the type creation has failed.
Ideally this could be resolved by ESRI casting those values as bigint instead of int, or just not casting those values at all. In our case there doesn't seem to be a way to work around it, but if anyone has an idea it would be appreciated!