Oid is a hidden column of the system. Direct modification is not acceptable.
MySQL = # update pg_class set OID = 99999 where OID = 73728;
Error: cannot assign to system column "oid"
Line 1: Update pg_class set OID = 99999 where OID = 73728;
But we can delete it.
MySQL = # Delete from pg_class where OID = 73728;
Delete 1
There is a copy command in PostgreSQL, which has a parameter with oids, which can be used to import the oId together. With this feature, we can achieve the oId modification function.
1. Create a new file and put the data into it. The new OID has been modified.
[MySQL @ pttest4 cxf] $ cat 2.dat
73740 | test | 2200 | 73729 | 10 | 0 | 73740 | 0 | 0 | 0 | 0 | f | r | 1 | 0 | 0 | 0 | 0 | 0 | 0 | f | 814 |/n
2. Use the Copy command to import data
Copy pg_class from '/home/MySQL/cxf/2. dat 'null as E' // n' CSV delimiter' | 'oids;
3. modify corresponding OID data in other tables
Update pg_attribute set attrelid = '000000' where attrelid = '000000 ';
Update pg_depend set refobjid = '000000' where refobjid = '000000 ';
Update pg_type set typrelid = '000000' where typrelid = '000000 ';
PS: if other data dictionaries are involved, they should be modified together.
4. the query shows that the oId has been changed.
MySQL = # select * from test;
Error: cocould not open relation 1663/16386/73740: no such file or directory
MySQL = # select oid from pg_class where relname = 'test ';
Oid
-------
73740
(1 row)
5. Rename the data file as a new oid.
[MySQL @ pttest4 16386] $ MV 73728 73740
Check the database again. The original data can still be accessed.
MySQL = # select * from test;
A
---
1
(1 row)
Now, the oId is successfully modified.
Other problems caused by OID modification. Because the oId of the current system is 73735, and after the oId (73740) We changed, the oId will be reused when we create a table, which may cause OID disorder. As follows:
MySQL = # create table helloworld (B varchar (1 ));
Create Table
MySQL = # select oid from pg_class where relname = 'helloworld ';
Oid
-------
73735
(1 row)
MySQL = # create table helloworld1 (B varchar (1 ));
Create Table
MySQL = # create table helloworld2 (B varchar (1 ));
Create Table
MySQL = # create table helloworld3 (B varchar (1 ));
Create Table
MySQL = # select oid from pg_class where relname like 'helloworld % ';
Oid
-------
73735
73737
73739
73741
(4 rows)
MySQL = # select * From pg_type where OID = '000000 ';
Typname | typnamespace | typowner | typlen | percent | typtype | percent | typelem | typinput | percent | typreceive | typsend | typanalyze | typalign | typstorage | percent | typbasetype | percent | typndims | typdefaultbin | typdefault
Accept + accept + ---------- + -------- + ---------- + --------- + accept + ------------ + ---------- + ------------ + ----------- ---------- + --------------- + ------------
Helloworld2 | 2200 | 10 |-1 | f | c | T |, | 73739 | 0 | record_in | record_out | record_recv | record_send |-| d | x | f | 0 |-1 | 0 |
(1 row)
We can see that the new pg_type OID uses 73740.
To avoid this problem, we can use pg_resetxlog to reset the oId.
For example, pg_resetxlog-O 80000 ~ /PostgreSQL/data/
In this way, when the sub-table is created, the oId starts to weigh 80000 to avoid the problem.