Silence unknown PostgreSQL OIDs warnings
What does this MR do and why?
When Rails scans a PostgreSQL table, it may come across column types it does not recognize and log a warning the first time. As discussed in https://github.com/rails/rails/issues/40687#issuecomment-733989424, Rails only registers types available to users (https://www.postgresql.org/docs/13/datatype.html).
We can silence these warnings by registering the OIDs in question manually.
Relates to #24043 (closed)
How to set up and validate locally
Run Postgresql::ReplicationSlot.lag_too_great?
in a console.
Before
[1] pry(main)> Postgresql::ReplicationSlot.lag_too_great?
TRANSACTION (0.2ms) BEGIN /*application:console,db_config_name:main,line:/lib/gitlab/database/schema_cache_with_renamed_table.rb:25:in `columns'*/
unknown OID 28: failed to recognize type of 'xmin'. It will be treated as String.
unknown OID 3220: failed to recognize type of 'restart_lsn'. It will be treated as String.
Postgresql::ReplicationSlot Exists? (1.0ms) SELECT 1 AS one FROM "pg_replication_slots" LIMIT 1 /*application:console,db_config_name:main,line:/app/models/postgresql/replication_slot.rb:11:in `block in in_use?'*/
TRANSACTION (0.2ms) COMMIT /*application:console,db_config_name:main,line:/lib/gitlab/database.rb:292:in `commit'*/
=> false
After
[1] pry(main)> Postgresql::ReplicationSlot.lag_too_great?
TRANSACTION (0.2ms) BEGIN /*application:console,db_config_name:main,line:/lib/gitlab/database/schema_cache_with_renamed_table.rb:25:in `columns'*/
Postgresql::ReplicationSlot Exists? (1.0ms) SELECT 1 AS one FROM "pg_replication_slots" LIMIT 1 /*application:console,db_config_name:main,line:/app/models/postgresql/replication_slot.rb:11:in `block in in_use?'*/
TRANSACTION (0.2ms) COMMIT /*application:console,db_config_name:main,line:/lib/gitlab/database.rb:292:in `commit'*/
=> false
gitlabhq_development=# SELECT oid, typname FROM pg_type where oid IN (28, 1034, 194, 3220);
oid | typname
------+--------------
28 | xid
194 | pg_node_tree
1034 | _aclitem
3220 | pg_lsn
(4 rows)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Stan Hu