forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitebfe2db
committed
Prevent drop of tablespaces used by partitioned relations
When a tablespace is used in a partitioned relation (per commitsca41030 in pg12 for tables and33e6c34 in pg11 for indexes),it is possible to drop the tablespace, potentially causing variousproblems. One such was reported in bug #16577, where a rewriting ALTERTABLE causes a server crash.Protect against this by using pg_shdepend to keep track of tablespaceswhen used for relations that don't keep physical files; we now abort atablespace if we see that the tablespace is referenced from anypartitioned relations.Backpatch this to 11, where this problem has been latent all along. Wedon't try to create pg_shdepend entries for existing partitionedindexes/tables, but any ones that are modified going forward will beprotected.Note slight behavior change: when trying to drop a tablespace thatcontains both regular tables as well as partitioned ones, you'dpreviously get ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE and now you'llget ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST. Arguably, the latter is morecorrect.It is possible to add protecting pg_shdepend entries for existingtables/indexes, by doing ALTER TABLE ONLY some_partitioned_table SET TABLESPACE pg_default; ALTER TABLE ONLY some_partitioned_table SET TABLESPACE original_tablespace;for each partitioned table/index that is not in the database defaulttablespace. Because these partitioned objects do not have storage, nofile needs to be actually moved, so it shouldn't take more time thanwhat's required to acquire locks.This query can be used to search for such relations:SELECT ... FROM pg_class WHERE relkind IN ('p', 'I') AND reltablespace <> 0Reported-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://postgr.es/m/16577-881633a9f9894fd5@postgresql.orgAuthor: Álvaro Herrera <alvherre@alvh.no-ip.org>Reviewed-by: Michael Paquier <michael@paquier.xyz>1 parent424d7a9 commitebfe2db
File tree
8 files changed
+117
-10
lines changed- doc/src/sgml
- src
- backend
- catalog
- commands
- include/catalog
- test/regress
- input
- output
8 files changed
+117
-10
lines changedLines changed: 12 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6849 | 6849 |
| |
6850 | 6850 |
| |
6851 | 6851 |
| |
| 6852 | + | |
| 6853 | + | |
| 6854 | + | |
| 6855 | + | |
| 6856 | + | |
| 6857 | + | |
| 6858 | + | |
| 6859 | + | |
| 6860 | + | |
| 6861 | + | |
6852 | 6862 |
| |
6853 | 6863 |
| |
6854 | 6864 |
| |
6855 |
| - | |
| 6865 | + | |
| 6866 | + | |
6856 | 6867 |
| |
6857 | 6868 |
| |
6858 | 6869 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
440 | 440 |
| |
441 | 441 |
| |
442 | 442 |
| |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
443 | 452 |
| |
444 | 453 |
| |
445 | 454 |
| |
|
Lines changed: 59 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
59 | 59 |
| |
60 | 60 |
| |
61 | 61 |
| |
| 62 | + | |
62 | 63 |
| |
63 | 64 |
| |
64 | 65 |
| |
| |||
186 | 187 |
| |
187 | 188 |
| |
188 | 189 |
| |
189 |
| - | |
| 190 | + | |
| 191 | + | |
190 | 192 |
| |
191 | 193 |
| |
192 | 194 |
| |
193 | 195 |
| |
| 196 | + | |
| 197 | + | |
194 | 198 |
| |
195 | 199 |
| |
196 | 200 |
| |
| |||
344 | 348 |
| |
345 | 349 |
| |
346 | 350 |
| |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
347 | 403 |
| |
348 | 404 |
| |
349 | 405 |
| |
| |||
1121 | 1177 |
| |
1122 | 1178 |
| |
1123 | 1179 |
| |
1124 |
| - | |
1125 |
| - | |
1126 |
| - | |
1127 |
| - | |
1128 |
| - | |
1129 |
| - | |
1130 |
| - | |
1131 | 1180 |
| |
1132 | 1181 |
| |
1133 | 1182 |
| |
| |||
1141 | 1190 |
| |
1142 | 1191 |
| |
1143 | 1192 |
| |
1144 |
| - | |
1145 | 1193 |
| |
1146 | 1194 |
| |
1147 | 1195 |
| |
| |||
1201 | 1249 |
| |
1202 | 1250 |
| |
1203 | 1251 |
| |
| 1252 | + | |
| 1253 | + | |
1204 | 1254 |
| |
1205 | 1255 |
| |
1206 | 1256 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
13340 | 13340 |
| |
13341 | 13341 |
| |
13342 | 13342 |
| |
| 13343 | + | |
| 13344 | + | |
| 13345 | + | |
| 13346 | + | |
13343 | 13347 |
| |
13344 | 13348 |
| |
13345 | 13349 |
| |
|
Lines changed: 12 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
420 | 420 |
| |
421 | 421 |
| |
422 | 422 |
| |
| 423 | + | |
| 424 | + | |
423 | 425 |
| |
424 | 426 |
| |
425 | 427 |
| |
| |||
468 | 470 |
| |
469 | 471 |
| |
470 | 472 |
| |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
471 | 483 |
| |
472 | 484 |
| |
473 | 485 |
| |
|
Lines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
67 | 67 |
| |
68 | 68 |
| |
69 | 69 |
| |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
70 | 76 |
| |
71 | 77 |
| |
72 | 78 |
| |
| |||
76 | 82 |
| |
77 | 83 |
| |
78 | 84 |
| |
| 85 | + | |
79 | 86 |
| |
80 | 87 |
| |
81 | 88 |
| |
| |||
253 | 260 |
| |
254 | 261 |
| |
255 | 262 |
| |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
256 | 269 |
| |
257 | 270 |
| |
258 | 271 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
249 | 249 |
| |
250 | 250 |
| |
251 | 251 |
| |
| 252 | + | |
| 253 | + | |
| 254 | + | |
252 | 255 |
| |
253 | 256 |
| |
254 | 257 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
712 | 712 |
| |
713 | 713 |
| |
714 | 714 |
| |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
715 | 720 |
| |
716 | 721 |
| |
717 | 722 |
| |
|
0 commit comments
Comments
(0)