* CheckRelationTableSpaceMove * Check if relation can be moved to new tablespace. * * NOTE: The caller must hold AccessExclusiveLock on the relation. * * Returns true if the relation can be moved to the new tablespace; raises * an error if it is not possible to do the move; returns false if the move * would have no effect. */
| 3929 | * would have no effect. |
| 3930 | */ |
| 3931 | bool |
| 3932 | CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId) |
| 3933 | { |
| 3934 | Oid oldTableSpaceId; |
| 3935 | |
| 3936 | /* |
| 3937 | * No work if no change in tablespace. Note that MyDatabaseTableSpace is |
| 3938 | * stored as 0. |
| 3939 | */ |
| 3940 | oldTableSpaceId = rel->rd_rel->reltablespace; |
| 3941 | if (newTableSpaceId == oldTableSpaceId || |
| 3942 | (newTableSpaceId == MyDatabaseTableSpace && oldTableSpaceId == 0)) |
| 3943 | return false; |
| 3944 | |
| 3945 | /* |
| 3946 | * We cannot support moving mapped relations into different tablespaces. |
| 3947 | * (In particular this eliminates all shared catalogs.) |
| 3948 | */ |
| 3949 | if (RelationIsMapped(rel)) |
| 3950 | ereport(ERROR, |
| 3951 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 3952 | errmsg("cannot move system relation \"%s\"", |
| 3953 | RelationGetRelationName(rel)))); |
| 3954 | |
| 3955 | /* Cannot move a non-shared relation into pg_global */ |
| 3956 | if (newTableSpaceId == GLOBALTABLESPACE_OID) |
| 3957 | ereport(ERROR, |
| 3958 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 3959 | errmsg("only shared relations can be placed in pg_global tablespace"))); |
| 3960 | |
| 3961 | /* |
| 3962 | * Do not allow moving temp tables of other backends ... their local |
| 3963 | * buffer manager is not going to cope. |
| 3964 | */ |
| 3965 | if (RELATION_IS_OTHER_TEMP(rel)) |
| 3966 | ereport(ERROR, |
| 3967 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 3968 | errmsg("cannot move temporary tables of other sessions"))); |
| 3969 | |
| 3970 | return true; |
| 3971 | } |
| 3972 | |
| 3973 | /* |
| 3974 | * SetRelationTableSpace |
no test coverage detected