I have around 1500 hypertables with 150-200 columns and millions of rows each in a timescale database (~ 1TB size, compression disabled, currently ~20 chunks for each hypertable, v2.5). Basically, all of those hypertables contain sensor values from machines - one hypertable for each machine. Data gets read from incoming csv-files and is stored in the corresponding hypertable which is determined by the csv-filename. All the hypertables have a column "filename_id" (foreign key, ON DELETE CASCADE) which reference to an indexed ID column of a normal table "filename". This is necessary to keep track of the csv-files that have been read and stored into the database and also keep track of the filename from which each data record in a hypertable came from.
Now, if I want to delete a row in the "filename" table, which also deletes the records in the corresponding hypertable, the delete statement doesn't finish in hours or ever.
I tried creating an index on each "filename_id" column for every hypertable without much success.
Dropping the FK constraint on "filename_id" for all hypertables and deleting the records manually is not really an option, since the database runs in production and it also takes at least an hour drop, delete, and add them again.
Disabling triggers isn't possible, since hypertables do not support enabling or disabling triggers.
Is there any way to increase the performance?
The query plan of the delete statement on a small example database (0.1% data, ~250 hypertables with 150-200 columns each, 1-2 chunks per table) looks like this (removed some lines at "..." due to too many characters):
"Delete on public.filename (cost=0.28..2.50 rows=0 width=0) (actual time=0.175..0.176 rows=0 loops=1)"
" Buffers: shared hit=5"
" -> Index Scan using filename_id_idx on public.filename (cost=0.28..2.50 rows=1 width=6) (actual time=0.012..0.014 rows=1 loops=1)"
" Output: ctid"
" Index Cond: (filename.filename_id = 24666)"
" Buffers: shared hit=3"
"Planning:"
" Buffers: shared hit=10"
"Planning Time: 0.250 ms"
"Trigger RI_ConstraintTrigger_a_58218604 for constraint fk_filename: time=5.134 calls=1"
"Trigger RI_ConstraintTrigger_a_58218616 for constraint 1315_11243_fk_filename: time=7.619 calls=1"
"Trigger RI_ConstraintTrigger_a_58218642 for constraint 1316_11247_fk_filename: time=4.514 calls=1"
"Trigger RI_ConstraintTrigger_a_58218668 for constraint 1317_11251_fk_filename: time=5.351 calls=1"
"Trigger RI_ConstraintTrigger_a_58218708 for constraint fk_filename: time=3.758 calls=1"
"Trigger RI_ConstraintTrigger_a_58218720 for constraint 1318_11255_fk_filename: time=5.557 calls=1"
"Trigger RI_ConstraintTrigger_a_58218746 for constraint 1319_11259_fk_filename: time=4.424 calls=1"
"Trigger RI_ConstraintTrigger_a_58218772 for constraint 1320_11263_fk_filename: time=5.046 calls=1"
"Trigger RI_ConstraintTrigger_a_58218812 for constraint fk_filename: time=3.748 calls=1"
"Trigger RI_ConstraintTrigger_a_58218824 for constraint 1321_11267_fk_filename: time=6.224 calls=1"
"Trigger RI_ConstraintTrigger_a_58218864 for constraint fk_filename: time=0.122 calls=1"
"Trigger RI_ConstraintTrigger_a_58218876 for constraint 1322_11271_fk_filename: time=3.734 calls=1"
"Trigger RI_ConstraintTrigger_a_58218927 for constraint fk_filename: time=0.131 calls=1"
"Trigger RI_ConstraintTrigger_a_58218939 for constraint 1323_11275_fk_filename: time=0.392 calls=1"
"Trigger RI_ConstraintTrigger_a_58218979 for constraint fk_filename: time=0.104 calls=1"
"Trigger RI_ConstraintTrigger_a_58218991 for constraint 1324_11279_fk_filename: time=0.443 calls=1"
"Trigger RI_ConstraintTrigger_a_58219063 for constraint fk_filename: time=3.666 calls=1"
"Trigger RI_ConstraintTrigger_a_58219075 for constraint 1325_11283_fk_filename: time=5.813 calls=1"
"Trigger RI_ConstraintTrigger_a_58219115 for constraint fk_filename: time=3.958 calls=1"
"Trigger RI_ConstraintTrigger_a_58219127 for constraint 1326_11287_fk_filename: time=5.062 calls=1"
"Trigger RI_ConstraintTrigger_a_58219167 for constraint fk_filename: time=3.516 calls=1"
"Trigger RI_ConstraintTrigger_a_58219179 for constraint 1327_11291_fk_filename: time=7.007 calls=1"
"Trigger RI_ConstraintTrigger_a_58219219 for constraint fk_filename: time=3.806 calls=1"
"Trigger RI_ConstraintTrigger_a_58219231 for constraint 1328_11295_fk_filename: time=5.275 calls=1"
"Trigger RI_ConstraintTrigger_a_58219282 for constraint fk_filename: time=3.705 calls=1"
"Trigger RI_ConstraintTrigger_a_58219294 for constraint 1329_11299_fk_filename: time=6.859 calls=1"
"Trigger RI_ConstraintTrigger_a_58219334 for constraint fk_filename: time=3.579 calls=1"
"Trigger RI_ConstraintTrigger_a_58219346 for constraint 1330_11303_fk_filename: time=6.918 calls=1"
"Trigger RI_ConstraintTrigger_a_58219386 for constraint fk_filename: time=4.461 calls=1"
"Trigger RI_ConstraintTrigger_a_58219398 for constraint 1331_11307_fk_filename: time=6.496 calls=1"
"Trigger RI_ConstraintTrigger_a_58219438 for constraint fk_filename: time=3.815 calls=1"
"Trigger RI_ConstraintTrigger_a_58219450 for constraint 1332_11311_fk_filename: time=6.192 calls=1"
"Trigger RI_ConstraintTrigger_a_58219490 for constraint fk_filename: time=3.541 calls=1"
"Trigger RI_ConstraintTrigger_a_58219502 for constraint 1333_11315_fk_filename: time=5.046 calls=1"
"Trigger RI_ConstraintTrigger_a_58219542 for constraint fk_filename: time=3.510 calls=1"
"Trigger RI_ConstraintTrigger_a_58219554 for constraint 1334_11319_fk_filename: time=6.998 calls=1"
"Trigger RI_ConstraintTrigger_a_58219608 for constraint fk_filename: time=3.767 calls=1"
"Trigger RI_ConstraintTrigger_a_58219621 for constraint 1335_11323_fk_filename: time=5.484 calls=1"
"Trigger RI_ConstraintTrigger_a_58219661 for constraint fk_filename: time=4.211 calls=1"
"Trigger RI_ConstraintTrigger_a_58219673 for constraint 1336_11327_fk_filename: time=6.843 calls=1"
"Trigger RI_ConstraintTrigger_a_58219713 for constraint fk_filename: time=3.529 calls=1"
"Trigger RI_ConstraintTrigger_a_58219725 for constraint 1337_11331_fk_filename: time=7.456 calls=1"
"Trigger RI_ConstraintTrigger_a_58219765 for constraint fk_filename: time=3.666 calls=1"
"Trigger RI_ConstraintTrigger_a_58219777 for constraint 1338_11335_fk_filename: time=6.138 calls=1"
"Trigger RI_ConstraintTrigger_a_58219817 for constraint fk_filename: time=3.763 calls=1"
"Trigger RI_ConstraintTrigger_a_58219829 for constraint 1339_11339_fk_filename: time=5.874 calls=1"
"Trigger RI_ConstraintTrigger_a_58219869 for constraint fk_filename: time=3.593 calls=1"
"Trigger RI_ConstraintTrigger_a_58219881 for constraint 1340_11343_fk_filename: time=5.142 calls=1"
"Trigger RI_ConstraintTrigger_a_58219921 for constraint fk_filename: time=4.285 calls=1"
"Trigger RI_ConstraintTrigger_a_58219933 for constraint 1341_11347_fk_filename: time=6.046 calls=1"
"Trigger RI_ConstraintTrigger_a_58219973 for constraint fk_filename: time=3.840 calls=1"
"Trigger RI_ConstraintTrigger_a_58219985 for constraint 1342_11351_fk_filename: time=5.448 calls=1"
"Trigger RI_ConstraintTrigger_a_58220038 for constraint fk_filename: time=4.212 calls=1"
"Trigger RI_ConstraintTrigger_a_58220050 for constraint 1343_11355_fk_filename: time=5.989 calls=1"
"Trigger RI_ConstraintTrigger_a_58220090 for constraint fk_filename: time=3.915 calls=1"
"Trigger RI_ConstraintTrigger_a_58220102 for constraint 1344_11359_fk_filename: time=6.870 calls=1"
"Trigger RI_ConstraintTrigger_a_58220142 for constraint fk_filename: time=3.781 calls=1"
"Trigger RI_ConstraintTrigger_a_58220154 for constraint 1345_11363_fk_filename: time=6.303 calls=1"
"Trigger RI_ConstraintTrigger_a_58220194 for constraint fk_filename: time=3.932 calls=1"
"Trigger RI_ConstraintTrigger_a_58220206 for constraint 1346_11367_fk_filename: time=6.904 calls=1"
"Trigger RI_ConstraintTrigger_a_58220246 for constraint fk_filename: time=3.310 calls=1"
"Trigger RI_ConstraintTrigger_a_58220258 for constraint 1347_11371_fk_filename: time=6.708 calls=1"
"Trigger RI_ConstraintTrigger_a_58220308 for constraint fk_filename: time=3.699 calls=1"
"Trigger RI_ConstraintTrigger_a_58220320 for constraint 1348_11375_fk_filename: time=5.620 calls=1"
"Trigger RI_ConstraintTrigger_a_58220360 for constraint fk_filename: time=3.481 calls=1"
"Trigger RI_ConstraintTrigger_a_58220372 for constraint 1349_11379_fk_filename: time=5.363 calls=1"
"Trigger RI_ConstraintTrigger_a_58220412 for constraint fk_filename: time=3.434 calls=1"
"Trigger RI_ConstraintTrigger_a_58220424 for constraint 1350_11383_fk_filename: time=4.801 calls=1"
"Trigger RI_ConstraintTrigger_a_58220474 for constraint fk_filename: time=3.632 calls=1"
"Trigger RI_ConstraintTrigger_a_58220486 for constraint 1351_11387_fk_filename: time=6.667 calls=1"
"Trigger RI_ConstraintTrigger_a_58220526 for constraint fk_filename: time=3.664 calls=1"
"Trigger RI_ConstraintTrigger_a_58220538 for constraint 1352_11391_fk_filename: time=7.010 calls=1"
"Trigger RI_ConstraintTrigger_a_58220578 for constraint fk_filename: time=4.005 calls=1"
"Trigger RI_ConstraintTrigger_a_58220590 for constraint 1353_11395_fk_filename: time=4.918 calls=1"
"Trigger RI_ConstraintTrigger_a_58220630 for constraint fk_filename: time=3.482 calls=1"
"Trigger RI_ConstraintTrigger_a_58220642 for constraint 1354_11399_fk_filename: time=5.270 calls=1"
"Trigger RI_ConstraintTrigger_a_58220695 for constraint fk_filename: time=3.849 calls=1"
"Trigger RI_ConstraintTrigger_a_58220707 for constraint 1355_11403_fk_filename: time=5.400 calls=1"
"Trigger RI_ConstraintTrigger_a_58220748 for constraint fk_filename: time=3.474 calls=1"
"Trigger RI_ConstraintTrigger_a_58220760 for constraint 1356_11407_fk_filename: time=7.003 calls=1"
"Trigger RI_ConstraintTrigger_a_58220800 for constraint fk_filename: time=3.905 calls=1"
"Trigger RI_ConstraintTrigger_a_58220812 for constraint 1357_11411_fk_filename: time=6.710 calls=1"
"Trigger RI_ConstraintTrigger_a_58220852 for constraint fk_filename: time=3.990 calls=1"
"Trigger RI_ConstraintTrigger_a_58220864 for constraint 1358_11415_fk_filename: time=6.525 calls=1"
"Trigger RI_ConstraintTrigger_a_58220904 for constraint fk_filename: time=3.735 calls=1"
"Trigger RI_ConstraintTrigger_a_58220916 for constraint 1359_11419_fk_filename: time=5.808 calls=1"
"Trigger RI_ConstraintTrigger_a_58220967 for constraint fk_filename: time=3.842 calls=1"
"Trigger RI_ConstraintTrigger_a_58220979 for constraint 1360_11423_fk_filename: time=6.655 calls=1"
"Trigger RI_ConstraintTrigger_a_58221022 for constraint fk_filename: time=4.667 calls=1"
"Trigger RI_ConstraintTrigger_a_58221034 for constraint 1361_11427_fk_filename: time=5.479 calls=1"
"Trigger RI_ConstraintTrigger_a_58221074 for constraint fk_filename: time=3.547 calls=1"
"Trigger RI_ConstraintTrigger_a_58221086 for constraint 1362_11431_fk_filename: time=6.817 calls=1"
"Trigger RI_ConstraintTrigger_a_58221126 for constraint fk_filename: time=3.961 calls=1"
"Trigger RI_ConstraintTrigger_a_58221138 for constraint 1363_11435_fk_filename: time=6.503 calls=1"
"Trigger RI_ConstraintTrigger_a_58221178 for constraint fk_filename: time=3.757 calls=1"
"Trigger RI_ConstraintTrigger_a_58221190 for constraint 1364_11439_fk_filename: time=7.066 calls=1"
"Trigger RI_ConstraintTrigger_a_58221237 for constraint fk_filename: time=3.910 calls=1"
"Trigger RI_ConstraintTrigger_a_58221249 for constraint 1365_11443_fk_filename: time=6.597 calls=1"
"Trigger RI_ConstraintTrigger_a_58221291 for constraint fk_filename: time=4.284 calls=1"
"Trigger RI_ConstraintTrigger_a_58221303 for constraint 1366_11447_fk_filename: time=7.540 calls=1"
"Trigger RI_ConstraintTrigger_a_58221343 for constraint fk_filename: time=3.479 calls=1"
"Trigger RI_ConstraintTrigger_a_58221355 for constraint 1367_11451_fk_filename: time=5.321 calls=1"
"Trigger RI_ConstraintTrigger_a_58221395 for constraint fk_filename: time=4.172 calls=1"
"Trigger RI_ConstraintTrigger_a_58221407 for constraint 1368_11455_fk_filename: time=5.331 calls=1"
"Trigger RI_ConstraintTrigger_a_58221447 for constraint fk_filename: time=3.464 calls=1"
"Trigger RI_ConstraintTrigger_a_58221459 for constraint 1369_11459_fk_filename: time=5.503 calls=1"
"Trigger RI_ConstraintTrigger_a_58221499 for constraint fk_filename: time=3.790 calls=1"
"Trigger RI_ConstraintTrigger_a_58221511 for constraint 1370_11463_fk_filename: time=5.402 calls=1"
"Trigger RI_ConstraintTrigger_a_58221551 for constraint fk_filename: time=3.582 calls=1"
"Trigger RI_ConstraintTrigger_a_58221563 for constraint 1371_11467_fk_filename: time=7.325 calls=1"
"Trigger RI_ConstraintTrigger_a_58221603 for constraint fk_filename: time=3.486 calls=1"
"Trigger RI_ConstraintTrigger_a_58221621 for constraint 1372_11471_fk_filename: time=6.640 calls=1"
"Trigger RI_ConstraintTrigger_a_58221665 for constraint fk_filename: time=5.134 calls=1"
"Trigger RI_ConstraintTrigger_a_58221677 for constraint 1373_11475_fk_filename: time=4.919 calls=1"
"Trigger RI_ConstraintTrigger_a_58221717 for constraint fk_filename: time=3.374 calls=1"
"Trigger RI_ConstraintTrigger_a_58221729 for constraint 1374_11479_fk_filename: time=5.891 calls=1"
"Trigger RI_ConstraintTrigger_a_58221769 for constraint fk_filename: time=3.690 calls=1"
"Trigger RI_ConstraintTrigger_a_58221781 for constraint 1375_11483_fk_filename: time=6.095 calls=1"
"Trigger RI_ConstraintTrigger_a_58221834 for constraint fk_filename: time=4.093 calls=1"
"Trigger RI_ConstraintTrigger_a_58221846 for constraint 1376_11487_fk_filename: time=6.956 calls=1"
"Trigger RI_ConstraintTrigger_a_58221886 for constraint fk_filename: time=3.675 calls=1"
"Trigger RI_ConstraintTrigger_a_58221898 for constraint 1377_11491_fk_filename: time=42.609 calls=1"
"Trigger RI_ConstraintTrigger_a_58221938 for constraint fk_filename: time=24.221 calls=1"
"Trigger RI_ConstraintTrigger_a_58221950 for constraint 1378_11495_fk_filename: time=7.879 calls=1"
"Trigger RI_ConstraintTrigger_a_58221990 for constraint fk_filename: time=6.555 calls=1"
"Trigger RI_ConstraintTrigger_a_58222002 for constraint 1379_11499_fk_filename: time=7.765 calls=1"
"Trigger RI_ConstraintTrigger_a_58222042 for constraint fk_filename: time=5.678 calls=1"
"Trigger RI_ConstraintTrigger_a_58222054 for constraint 1380_11503_fk_filename: time=8.225 calls=1"
"Trigger RI_ConstraintTrigger_a_58222105 for constraint fk_filename: time=7.696 calls=1"
"Trigger RI_ConstraintTrigger_a_58222118 for constraint 1381_11507_fk_filename: time=9.930 calls=1"
"Trigger RI_ConstraintTrigger_a_58222158 for constraint fk_filename: time=5.197 calls=1"
"Trigger RI_ConstraintTrigger_a_58222170 for constraint 1382_11511_fk_filename: time=8.397 calls=1"
"Trigger RI_ConstraintTrigger_a_58222210 for constraint fk_filename: time=4.494 calls=1"
"Trigger RI_ConstraintTrigger_a_58222222 for constraint 1383_11515_fk_filename: time=8.280 calls=1"
"Trigger RI_ConstraintTrigger_a_58222262 for constraint fk_filename: time=4.100 calls=1"
"Trigger RI_ConstraintTrigger_a_58222274 for constraint 1384_11519_fk_filename: time=6.736 calls=1"
"Trigger RI_ConstraintTrigger_a_58222314 for constraint fk_filename: time=3.823 calls=1"
"Trigger RI_ConstraintTrigger_a_58222326 for constraint 1385_11523_fk_filename: time=6.443 calls=1"
"Trigger RI_ConstraintTrigger_a_58222366 for constraint fk_filename: time=4.324 calls=1"
"Trigger RI_ConstraintTrigger_a_58222378 for constraint 1386_11527_fk_filename: time=7.069 calls=1"
"Trigger RI_ConstraintTrigger_a_58222426 for constraint fk_filename: time=3.873 calls=1"
"Trigger RI_ConstraintTrigger_a_58222441 for constraint 1387_11531_fk_filename: time=5.298 calls=1"
"Trigger RI_ConstraintTrigger_a_58222495 for constraint fk_filename: time=3.607 calls=1"
"Trigger RI_ConstraintTrigger_a_58222507 for constraint 1388_11535_fk_filename: time=5.445 calls=1"
"Trigger RI_ConstraintTrigger_a_58222547 for constraint fk_filename: time=3.445 calls=1"
"Trigger RI_ConstraintTrigger_a_58222559 for constraint 1389_11539_fk_filename: time=6.043 calls=1"
"Trigger RI_ConstraintTrigger_a_58222599 for constraint fk_filename: time=3.774 calls=1"
"Trigger RI_ConstraintTrigger_a_58222611 for constraint 1390_11543_fk_filename: time=6.550 calls=1"
"Trigger RI_ConstraintTrigger_a_58222651 for constraint fk_filename: time=3.030 calls=1"
"Trigger RI_ConstraintTrigger_a_58222663 for constraint 1391_11547_fk_filename: time=6.151 calls=1"
"Trigger RI_ConstraintTrigger_a_58222703 for constraint fk_filename: time=2.958 calls=1"
"Trigger RI_ConstraintTrigger_a_58222715 for constraint 1392_11551_fk_filename: time=5.232 calls=1"
"Trigger RI_ConstraintTrigger_a_58222755 for constraint fk_filename: time=2.855 calls=1"
"Trigger RI_ConstraintTrigger_a_58222767 for constraint 1393_11555_fk_filename: time=6.605 calls=1"
"Trigger RI_ConstraintTrigger_a_58222807 for constraint fk_filename: time=3.003 calls=1"
"Trigger RI_ConstraintTrigger_a_58222820 for constraint 1394_11559_fk_filename: time=5.206 calls=1"
"Trigger RI_ConstraintTrigger_a_58222870 for constraint fk_filename: time=3.330 calls=1"
"Trigger RI_ConstraintTrigger_a_58222882 for constraint 1395_11563_fk_filename: time=5.927 calls=1"
"Trigger RI_ConstraintTrigger_a_58222922 for constraint fk_filename: time=2.889 calls=1"
"Trigger RI_ConstraintTrigger_a_58222934 for constraint 1396_11567_fk_filename: time=4.461 calls=1"
"Trigger RI_ConstraintTrigger_a_58222974 for constraint fk_filename: time=3.121 calls=1"
"Trigger RI_ConstraintTrigger_a_58222986 for constraint 1397_11571_fk_filename: time=6.212 calls=1"
"Trigger RI_ConstraintTrigger_a_58223026 for constraint fk_filename: time=3.290 calls=1"
"Trigger RI_ConstraintTrigger_a_58223041 for constraint 1398_11575_fk_filename: time=4.182 calls=1"
"Trigger RI_ConstraintTrigger_a_58223082 for constraint fk_filename: time=3.112 calls=1"
"Trigger RI_ConstraintTrigger_a_58223094 for constraint 1399_11579_fk_filename: time=4.665 calls=1"
"Trigger RI_ConstraintTrigger_a_58223134 for constraint fk_filename: time=3.981 calls=1"
"Trigger RI_ConstraintTrigger_a_58223146 for constraint 1400_11583_fk_filename: time=4.189 calls=1"
"Trigger RI_ConstraintTrigger_a_58223186 for constraint fk_filename: time=3.079 calls=1"
"Trigger RI_ConstraintTrigger_a_58223198 for constraint 1401_11587_fk_filename: time=4.541 calls=1"
"Trigger RI_ConstraintTrigger_a_58223245 for constraint fk_filename: time=2.959 calls=1"
"Trigger RI_ConstraintTrigger_a_58223257 for constraint 1402_11591_fk_filename: time=4.356 calls=1"
"Trigger RI_ConstraintTrigger_a_58223283 for constraint 1403_11595_fk_filename: time=3.154 calls=1"
"Trigger RI_ConstraintTrigger_a_58223325 for constraint fk_filename: time=4.479 calls=1"
"Trigger RI_ConstraintTrigger_a_58223337 for constraint 1404_11599_fk_filename: time=3.324 calls=1"
"Trigger RI_ConstraintTrigger_a_58223377 for constraint fk_filename: time=4.157 calls=1"
"Trigger RI_ConstraintTrigger_a_58223389 for constraint 1405_11603_fk_filename: time=3.124 calls=1"
"Trigger RI_ConstraintTrigger_a_58223429 for constraint fk_filename: time=4.307 calls=1"
"Trigger RI_ConstraintTrigger_a_58223441 for constraint 1406_11607_fk_filename: time=3.558 calls=1"
"Trigger RI_ConstraintTrigger_a_58223492 for constraint fk_filename: time=5.441 calls=1"
"Trigger RI_ConstraintTrigger_a_58223504 for constraint 1407_11611_fk_filename: time=3.754 calls=1"
"Trigger RI_ConstraintTrigger_a_58223544 for constraint fk_filename: time=6.559 calls=1"
"Trigger RI_ConstraintTrigger_a_58223556 for constraint 1408_11615_fk_filename: time=4.170 calls=1"
"Trigger RI_ConstraintTrigger_a_58223597 for constraint fk_filename: time=4.274 calls=1"
"Trigger RI_ConstraintTrigger_a_58223609 for constraint 1409_11619_fk_filename: time=3.089 calls=1"
"Trigger RI_ConstraintTrigger_a_58223649 for constraint fk_filename: time=5.058 calls=1"
"Trigger RI_ConstraintTrigger_a_58223661 for constraint 1410_11623_fk_filename: time=3.503 calls=1"
"Trigger RI_ConstraintTrigger_a_58223701 for constraint fk_filename: time=5.118 calls=1"
"Trigger RI_ConstraintTrigger_a_58223713 for constraint 1411_11627_fk_filename: time=3.357 calls=1"
"Trigger RI_ConstraintTrigger_a_58223753 for constraint fk_filename: time=5.676 calls=1"
"Trigger RI_ConstraintTrigger_a_58223765 for constraint 1412_11631_fk_filename: time=3.256 calls=1"
"Trigger RI_ConstraintTrigger_a_58223816 for constraint fk_filename: time=4.124 calls=1"
"Trigger RI_ConstraintTrigger_a_58223828 for constraint 1413_11635_fk_filename: time=3.042 calls=1"
"Trigger RI_ConstraintTrigger_a_58223873 for constraint fk_filename: time=4.542 calls=1"
"Trigger RI_ConstraintTrigger_a_58223885 for constraint 1414_11639_fk_filename: time=3.285 calls=1"
"Trigger RI_ConstraintTrigger_a_58223925 for constraint fk_filename: time=5.209 calls=1"
"Trigger RI_ConstraintTrigger_a_58223937 for constraint 1415_11643_fk_filename: time=3.122 calls=1"
"Trigger RI_ConstraintTrigger_a_58223977 for constraint fk_filename: time=5.885 calls=1"
"Trigger RI_ConstraintTrigger_a_58223989 for constraint 1416_11647_fk_filename: time=3.509 calls=1"
"Trigger RI_ConstraintTrigger_a_58224029 for constraint fk_filename: time=4.560 calls=1"
"Trigger RI_ConstraintTrigger_a_58224041 for constraint 1417_11651_fk_filename: time=3.316 calls=1"
"Trigger RI_ConstraintTrigger_a_58224081 for constraint fk_filename: time=4.583 calls=1"
"Trigger RI_ConstraintTrigger_a_58224093 for constraint 1418_11655_fk_filename: time=3.329 calls=1"
"Trigger RI_ConstraintTrigger_a_58224133 for constraint fk_filename: time=4.157 calls=1"
"Trigger RI_ConstraintTrigger_a_58224149 for constraint 1419_11659_fk_filename: time=3.167 calls=1"
"Trigger RI_ConstraintTrigger_a_58224192 for constraint fk_filename: time=4.309 calls=1"
"Trigger RI_ConstraintTrigger_a_58224204 for constraint 1420_11663_fk_filename: time=3.371 calls=1"
"Trigger RI_ConstraintTrigger_a_58224247 for constraint fk_filename: time=5.212 calls=1"
"Trigger RI_ConstraintTrigger_a_58224259 for constraint 1421_11667_fk_filename: time=3.257 calls=1"
"Trigger RI_ConstraintTrigger_a_58224299 for constraint fk_filename: time=4.430 calls=1"
"Trigger RI_ConstraintTrigger_a_58224311 for constraint 1422_11671_fk_filename: time=3.589 calls=1"
"Trigger RI_ConstraintTrigger_a_58224351 for constraint fk_filename: time=5.288 calls=1"
"Trigger RI_ConstraintTrigger_a_58224363 for constraint 1423_11675_fk_filename: time=3.152 calls=1"
"Trigger RI_ConstraintTrigger_a_58224403 for constraint fk_filename: time=5.619 calls=1"
"Trigger RI_ConstraintTrigger_a_58224415 for constraint 1424_11679_fk_filename: time=3.796 calls=1"
"Trigger RI_ConstraintTrigger_a_58224460 for constraint fk_filename: time=5.503 calls=1"
"Trigger RI_ConstraintTrigger_a_58224472 for constraint 1425_11683_fk_filename: time=3.139 calls=1"
"Trigger RI_ConstraintTrigger_a_58224512 for constraint fk_filename: time=6.265 calls=1"
"Trigger RI_ConstraintTrigger_a_58224524 for constraint 1426_11687_fk_filename: time=3.292 calls=1"
"Trigger RI_ConstraintTrigger_a_58224564 for constraint fk_filename: time=4.223 calls=1"
"Trigger RI_ConstraintTrigger_a_58224576 for constraint 1427_11691_fk_filename: time=3.112 calls=1"
"Trigger RI_ConstraintTrigger_a_58224616 for constraint fk_filename: time=6.118 calls=1"
"Trigger RI_ConstraintTrigger_a_58224628 for constraint 1428_11695_fk_filename: time=3.361 calls=1"
"Trigger RI_ConstraintTrigger_a_58224668 for constraint fk_filename: time=5.639 calls=1"
"Trigger RI_ConstraintTrigger_a_58224680 for constraint 1429_11699_fk_filename: time=3.106 calls=1"
"Trigger RI_ConstraintTrigger_a_58224720 for constraint fk_filename: time=5.693 calls=1"
"Trigger RI_ConstraintTrigger_a_58224732 for constraint 1430_11703_fk_filename: time=3.172 calls=1"
"Trigger RI_ConstraintTrigger_a_58224788 for constraint fk_filename: time=4.919 calls=1"
"Trigger RI_ConstraintTrigger_a_58224805 for constraint 1431_11707_fk_filename: time=3.101 calls=1"
"Trigger RI_ConstraintTrigger_a_58224845 for constraint fk_filename: time=5.822 calls=1"
"Trigger RI_ConstraintTrigger_a_58224857 for constraint 1432_11711_fk_filename: time=3.769 calls=1"
"Trigger RI_ConstraintTrigger_a_58224897 for constraint fk_filename: time=4.935 calls=1"
"Trigger RI_ConstraintTrigger_a_58224909 for constraint 1433_11715_fk_filename: time=3.604 calls=1"
"Trigger RI_ConstraintTrigger_a_58224949 for constraint fk_filename: time=5.002 calls=1"
"Trigger RI_ConstraintTrigger_a_58224961 for constraint 1434_11719_fk_filename: time=3.447 calls=1"
"Trigger RI_ConstraintTrigger_a_58225001 for constraint fk_filename: time=4.479 calls=1"
"Trigger RI_ConstraintTrigger_a_58225013 for constraint 1435_11723_fk_filename: time=4.274 calls=1"
"Trigger RI_ConstraintTrigger_a_58225053 for constraint fk_filename: time=8.053 calls=1"
"Trigger RI_ConstraintTrigger_a_58225065 for constraint 1436_11727_fk_filename: time=9.265 calls=1"
"Trigger RI_ConstraintTrigger_a_58225105 for constraint fk_filename: time=3.783 calls=1"
"Trigger RI_ConstraintTrigger_a_58225117 for constraint 1437_11731_fk_filename: time=5.919 calls=1"
"Trigger RI_ConstraintTrigger_a_58225170 for constraint fk_filename: time=3.343 calls=1"
"Trigger RI_ConstraintTrigger_a_58225182 for constraint 1438_11735_fk_filename: time=5.461 calls=1"
"Trigger RI_ConstraintTrigger_a_58225222 for constraint fk_filename: time=3.203 calls=1"
"Trigger RI_ConstraintTrigger_a_58225234 for constraint 1439_11739_fk_filename: time=3.177 calls=1"
"Trigger RI_ConstraintTrigger_a_58225274 for constraint fk_filename: time=2.994 calls=1"
"Trigger RI_ConstraintTrigger_a_58225286 for constraint 1440_11743_fk_filename: time=5.852 calls=1"
"Trigger RI_ConstraintTrigger_a_58225342 for constraint fk_filename: time=3.455 calls=1"
"Trigger RI_ConstraintTrigger_a_58225354 for constraint 1441_11747_fk_filename: time=4.543 calls=1"
"Trigger RI_ConstraintTrigger_a_58225394 for constraint fk_filename: time=4.346 calls=1"
"Trigger RI_ConstraintTrigger_a_58225406 for constraint 1442_11751_fk_filename: time=3.716 calls=1"
"Trigger RI_ConstraintTrigger_a_58225446 for constraint fk_filename: time=5.577 calls=1"
"Trigger RI_ConstraintTrigger_a_58225458 for constraint 1443_11755_fk_filename: time=3.179 calls=1"
"Trigger RI_ConstraintTrigger_a_58225498 for constraint fk_filename: time=5.563 calls=1"
"Trigger RI_ConstraintTrigger_a_58225510 for constraint 1444_11759_fk_filename: time=3.696 calls=1"
"Trigger RI_ConstraintTrigger_a_58225550 for constraint fk_filename: time=4.453 calls=1"
"Trigger RI_ConstraintTrigger_a_58225562 for constraint 1445_11763_fk_filename: time=3.684 calls=1"
"Trigger RI_ConstraintTrigger_a_58225602 for constraint fk_filename: time=4.439 calls=1"
"Trigger RI_ConstraintTrigger_a_58225614 for constraint 1446_11767_fk_filename: time=5.292 calls=1"
"Trigger RI_ConstraintTrigger_a_58225654 for constraint fk_filename: time=4.199 calls=1"
"Trigger RI_ConstraintTrigger_a_58225666 for constraint 1447_11771_fk_filename: time=3.172 calls=1"
"Trigger RI_ConstraintTrigger_a_58225716 for constraint fk_filename: time=3.869 calls=1"
"Trigger RI_ConstraintTrigger_a_58225728 for constraint 1448_11775_fk_filename: time=3.511 calls=1"
"Trigger RI_ConstraintTrigger_a_58225768 for constraint fk_filename: time=4.242 calls=1"
"Trigger RI_ConstraintTrigger_a_58225780 for constraint 1449_11779_fk_filename: time=3.312 calls=1"
"Trigger RI_ConstraintTrigger_a_58225820 for constraint fk_filename: time=3.941 calls=1"
"Trigger RI_ConstraintTrigger_a_58225832 for constraint 1450_11783_fk_filename: time=3.266 calls=1"
"Trigger RI_ConstraintTrigger_a_58225879 for constraint fk_filename: time=5.646 calls=1"
"Trigger RI_ConstraintTrigger_a_58225891 for constraint 1451_11787_fk_filename: time=3.369 calls=1"
"Trigger RI_ConstraintTrigger_a_58225931 for constraint fk_filename: time=5.267 calls=1"
"Trigger RI_ConstraintTrigger_a_58225948 for constraint 1452_11791_fk_filename: time=3.817 calls=1"
"Trigger RI_ConstraintTrigger_a_58225988 for constraint fk_filename: time=4.204 calls=1"
"Trigger RI_ConstraintTrigger_a_58226000 for constraint 1453_11795_fk_filename: time=3.111 calls=1"
"Trigger RI_ConstraintTrigger_a_58226040 for constraint fk_filename: time=3.945 calls=1"
"Trigger RI_ConstraintTrigger_a_58226052 for constraint 1454_11799_fk_filename: time=3.180 calls=1"
"Trigger RI_ConstraintTrigger_a_58226092 for constraint fk_filename: time=4.331 calls=1"
"Trigger RI_ConstraintTrigger_a_58226104 for constraint 1455_11803_fk_filename: time=3.110 calls=1"
"Trigger RI_ConstraintTrigger_a_58226144 for constraint fk_filename: time=4.097 calls=1"
"Trigger RI_ConstraintTrigger_a_58226165 for constraint 1456_11807_fk_filename: time=3.308 calls=1"
"Trigger RI_ConstraintTrigger_a_58226206 for constraint fk_filename: time=5.616 calls=1"
"Trigger RI_ConstraintTrigger_a_58226218 for constraint 1457_11811_fk_filename: time=3.323 calls=1"
"Trigger RI_ConstraintTrigger_a_58226270 for constraint fk_filename: time=5.329 calls=1"
...
"Execution Time: 2550.275 ms"
Related
We have postgresql 12v.Weekly purging script on production will run on few tables, on one table after purging/vacuum the table, reindex is failing and creating one new copy with invalid index. Due to this index size increased to 300Gb.
Please find indexes details on table and tell me the steps to fix this issue.
Indexes:
"model_recommendation_association_pkey_new" PRIMARY KEY, btree (id)
"model_recommendation_association_pkey_new_ccnew" UNIQUE, btree (id) INVALID
"model_recommendation_association_pkey_new_ccnew1" UNIQUE, btree (id) INVALID
"model_recommendation_association_pkey_new_ccnew2" UNIQUE, btree (id) INVALID
"model_recommendation_association_pkey_new_ccnew3" UNIQUE, btree (id) INVALID
"model_recommendation_association_pkey_new_ccnew4" UNIQUE, btree (id) INVALID
"model_recommendation_association_pkey_new_ccnew5" UNIQUE, btree (id) INVALID
"model_recommendation_association_pkey_new_ccnew6" UNIQUE, btree (id) INVALID
"model_recommendation_association_pkey_new_ccnew7" UNIQUE, btree (id) INVALID
"mod_recomm" btree (recommendation_id)
"mod_recomm_ccnew" btree (recommendation_id)
"mod_recomm_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew1_ccnew" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew1_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew1_ccnew1_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew1_ccnew1_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew1_ccnew2" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew1_ccnew3" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew1_ccnew_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew1_ccnew_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew2" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew2_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew2_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew3" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew3_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew3_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew4" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew5" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew_ccnew" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew1_ccnew_ccnew1_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew_ccnew1_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew_ccnew2" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew_ccnew3" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew_ccnew_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew1_ccnew_ccnew_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew2" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew1_ccnew" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew1_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew1_ccnew1_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew1_ccnew1_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew1_ccnew2" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew1_ccnew3" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew1_ccnew_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew1_ccnew_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew2" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew2_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew2_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew3" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew3_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew3_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew4" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew5" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew_ccnew" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew2_ccnew_ccnew1_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew_ccnew1_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew_ccnew2" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew_ccnew3" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew_ccnew_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew2_ccnew_ccnew_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew3" btree (recommendation_id)
"mod_recomm_ccnew3_ccnew" btree (recommendation_id)
"mod_recomm_ccnew3_ccnew1" btree (recommendation_id)
"mod_recomm_ccnew3_ccnew1_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew3_ccnew1_ccnew1" btree (recommendation_id) INVALID
"mod_recomm_ccnew3_ccnew2" btree (recommendation_id) INVALID
"mod_recomm_ccnew3_ccnew3" btree (recommendation_id) INVALID
"mod_recomm_ccnew3_ccnew_ccnew" btree (recommendation_id) INVALID
"mod_recomm_ccnew3_ccnew_ccnew1" btree (recommendation_id) INVALID
My question is similar to the one posted earlier in the Community. questions/62936399/error-sql-state-42703-while-trying-to-insert-data-into-my-table
In PostgreSQL, I'm trying to run CREATE Table Statement so that I can continue with inserting values. Although my CREATE statement fails so I can't get on with INSERT statement. The error message that keeps coming up ERROR: relation "eventrequest" does not exist
SQL state: 42P01
I have re-did the entire CREATE Statement twice although the error message does not change.
CREATE TABLE CUSTOMER
(CustNo VARCHAR(8) CONSTRAINT CustNoNotNull NOT NULL,
CustName VARCHAR(30) CONSTRAINT CustNameNotNull NOT NULL,
Address VARCHAR(50) CONSTRAINT AddressNotNull NOT NULL,
Internal CHAR(1) CONSTRAINT InternalNotNull NOT NULL,
Contact VARCHAR(35) CONSTRAINT ContractNotNull NOT NULL,
Phone VARCHAR(11) CONSTRAINT CPhoneNotNull NOT NULL,
City VARCHAR(30) CONSTRAINT CityNotNull NOT NULL,
State VARCHAR(2) CONSTRAINT StateNotNull NOT NULL,
Zip VARCHAR(10) CONSTRAINT ZipNotNull NOT NULL,
CONSTRAINT PK_CUSTOMER PRIMARY KEY (CustNo)
);
CREATE TABLE FACILITY
(FacNo VARCHAR(8) CONSTRAINT FacNoNotNull NOT NULL,
FacName VARCHAR(30) CONSTRAINT FacNameNotNull NOT NULL,
CONSTRAINT PK_FACILITY PRIMARY KEY (FacNo),
CONSTRAINT Unique_FacName UNIQUE(FacName)
);
CREATE TABLE LOCATION
(LocNo VARCHAR(8) CONSTRAINT LocNoNotNull NOT NULL,
FacNo VARCHAR(8),
LocName VARCHAR(30) CONSTRAINT LocNameNotNull NOT NULL,
CONSTRAINT PK_LOCATION PRIMARY KEY (LocNo),
CONSTRAINT FK_FACNO FOREIGN KEY (FacNo) REFERENCES FACILITY (FacNo)
);
CREATE TABLE EMPLOYEE
(
EmpNo CHAR(11) CONSTRAINT EmpNoNotNull NOT NULL,
EmpName VARCHAR(30) CONSTRAINT EmpNameNotNull NOT NULL,
Department VARCHAR(30) CONSTRAINT DepartmentNotNull NOT NULL,
Email VARCHAR(255) CONSTRAINT EmailNotNull NOT NULL,
Phone VARCHAR(30) CONSTRAINT PhoneNotNull NOT NULL,
CONSTRAINT PK_EMPLOYEE PRIMARY KEY (EmpNo)
);
CREATE TABLE EVENTPLAN
(
PlanNo VARCHAR(8) NOT NULL,
EventNo VARCHAR(8) NOT NULL,
workdate DATE NOT NULL,
notes VARCHAR(40),
activity VARCHAR(20) NOT NULL,
empno VARCHAR(8),
CONSTRAINT PK_PLANNO PRIMARY KEY (PlanNo),
CONSTRAINT FK_EVENTNO FOREIGN KEY (EventNo) REFERENCES EventRequest (EventNo)
);
CREATE TABLE EVENTREQUEST
(
EventNo VARCHAR(8) NOT NULL,
DateHeld DATE NOT NULL,
DateReq DATE NOT NULL,
FacNo VARCHAR(8) NOT NULL,
CustNo VARCHAR(8) NOT NULL,
DateAuth DATE,
Status VARCHAR(8) NOT NULL CHECK (Status IN ('Pending', 'Denied', 'Approved')),
EstCost DECIMAL(10, 2) NOT NULL,
EstAudience INT NOT NULL CHECK (EstAudience > 0),
BudNo VARCHAR(8),
CONSTRAINT PK_EVENTNO PRIMARY KEY (EventNo),
CONSTRAINT FK_FACILITYNOEVENTREQ FOREIGN KEY (FacNo) REFERENCES Facility (FacNo),
CONSTRAINT FK_CUSTOMERNO FOREIGN KEY (CustNo) REFERENCES Customer (CustNo)
);
CREATE TABLE EVENTPLANLINE
(
PlanNo CHAR(8) NOT NULL,
LineNo CHAR(8) NOT NULL,
LocNo CHAR(8) NOT NULL,
ResNo CHAR(8) NOT NULL,
TimeStart TIMESTAMP NOT NULL,
TimeEnd TIMESTAMP NOT NULL,
NumberFLD INTEGER NOT NULL,
CONSTRAINT PK_EVENTPLANLINE PRIMARY KEY (PlanNo, LineNo),
CONSTRAINT FK_EVENTPLAN FOREIGN KEY (PlanNo) REFERENCES EventPlan (PlanNo),
CONSTRAINT FK_LOCATION FOREIGN KEY (LocNo) REFERENCES Location (LocNo),
CONSTRAINT FK_RESOURCETBL FOREIGN KEY (ResNo) REFERENCES ResourceTbl (ResNo)
);
CREATE TABLE RESOURCETBL
(
ResNo CHAR(8) NOT NULL,
ResName VARCHAR(30) NOT NULL,
Rate DECIMAL(8, 2) NOT NULL,
CONSTRAINT PK_RESOURCETBL PRIMARY KEY (ResNo)
);
Executing the following SQL script in the server:
ERROR: Error 1215: Cannot add foreign key constraint
SQL Code:
CREATE TABLE IF NOT EXISTS `telecom`.`jobreq` (
`id` INT NOT NULL,
`jobName` VARCHAR(45) NULL,
`priority` VARCHAR(45) NULL,
`dates` DATE NULL,
`status` VARCHAR(45) NULL,
`user` VARCHAR(45) NULL,
`timestamp` DATE NULL,
`service_id` INT(11) NOT NULL,
`client_id` INT(11) NOT NULL,
PRIMARY KEY (`id`, `service_id`, `client_id`),
INDEX `fk_jobreq_service1_idx` (`service_id` ASC),
INDEX `fk_jobreq_client1_idx` (`client_id` ASC),
CONSTRAINT `fk_jobreq_service1`
FOREIGN KEY (`service_id`)
REFERENCES `telecom`.`service` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_jobreq_client1`
FOREIGN KEY (`client_id`)
REFERENCES `telecom`.`client` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 12 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
I am unable to find out why I am getting this error can someone with a high intelligence please assist me.
So it seems all I had to do was to change the name of the table and it went through im guessing somehow the name was magically somehow still in the system
I have defined these tables:
CREATE TABLE "public".category (id BIGSERIAL NOT NULL, name varchar(255) NOT NULL, PRIMARY KEY (id));
CREATE UNIQUE INDEX category_name ON "public".category (name);
CREATE TABLE "public".clusters (id BIGSERIAL NOT NULL, name varchar(255) NOT NULL, PRIMARY KEY (id));
CREATE INDEX clusters_name ON "public".clusters (name);
CREATE TABLE "public".keywords (id BIGSERIAL NOT NULL, text varchar(255) NOT NULL, category_id int8 NOT NULL, top_results int4, cluster_id int8, month_requests int4, click_cost float8, PRIMARY KEY (id));
CREATE INDEX keywords_text ON "public".keywords (text);
ALTER TABLE "public".keywords ADD CONSTRAINT FKkeywords488682 FOREIGN KEY (cluster_id) REFERENCES "public".clusters (id);
ALTER TABLE "public".keywords ADD CONSTRAINT FKkeywords446526 FOREIGN KEY (category_id) REFERENCES "public".category (id) ON UPDATE CASCADE ON DELETE CASCADE;
added one record to category table:
INSERT INTO "public".category(id, name) VALUES (1, 'Test');
And now when I try to add record to keyword table
insert into "public"."keywords" ( "category_id", "text") values ( 1, 'testkey')
I got error:
ERROR: constraint 16959 is not a foreign key constraint
When I do
select * FROM pg_constraint;
I can't see constraint with this id. I can't understand what is the cause of this problem.
hello everybody I'm studying database and I use MySQL Workbench.
I try to create 3 table but it produces a problem:
ERROR: Error 1022: Can't write duplicate key in table 'paziente' SQL
Code:
-- -----------------------------------------------------
-- Table `gestione di prenotazione`.`paziente`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gestione di prenotazione`.`paziente` (
`tesseraSanitario` BIGINT NOT NULL,
`codfsc` VARCHAR(45) NOT NULL,
`luogo di nascita` VARCHAR(45) NULL,
`dataNascita` DATE NULL,
`tipo` VARCHAR(1) NULL,
`username` VARCHAR(45) NULL,
`password` VARCHAR(45) NULL,
`AUSL` VARCHAR(45) NULL,
PRIMARY KEY (`tesseraSanitario`, `codfsc`),
INDEX `cf_idx` (`codfsc` ASC),
UNIQUE INDEX `cf_UNIQUE` (`codfsc` ASC),
CONSTRAINT `cf`
FOREIGN KEY (`codfsc`)
REFERENCES `gestione di prenotazione`.`persona` (`cf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
in follow there are 3 table:
CREATE SCHEMA IF NOT EXISTS `gestione di prenotazione` DEFAULT CHARACTER SET utf8 ;
USE `gestione di prenotazione` ;
-- -----------------------------------------------------
-- Table `gestione di prenotazione`.`persona`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gestione di prenotazione`.`persona` (
`cf` VARCHAR(45) NOT NULL,
`nome` VARCHAR(45) NULL,
`cognome` VARCHAR(45) NULL,
`sesso` VARCHAR(1) NULL,
`indirizzo` VARCHAR(45) NULL,
`telefono` INT NULL,
`comune` VARCHAR(45) NULL,
PRIMARY KEY (`cf`),
UNIQUE INDEX `cf_UNIQUE` (`cf` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `gestione di prenotazione`.`medico`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gestione di prenotazione`.`medico` (
`idmedico` INT NOT NULL,
`codicefiscale` VARCHAR(45) NOT NULL,
`numero di assistito in carico` INT NULL,
`numero massimo di assistito` INT NULL,
PRIMARY KEY (`idmedico`, `codicefiscale`),
INDEX `cf_idx` (`codicefiscale` ASC),
UNIQUE INDEX `cf_UNIQUE` (`codicefiscale` ASC),
CONSTRAINT `cf`
FOREIGN KEY (`codicefiscale`)
REFERENCES `gestione di prenotazione`.`persona` (`cf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `gestione di prenotazione`.`paziente`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `gestione di prenotazione`.`paziente` (
`tesseraSanitario` BIGINT NOT NULL,
`codfsc` VARCHAR(45) NOT NULL,
`luogo di nascita` VARCHAR(45) NULL,
`dataNascita` DATE NULL,
`tipo` VARCHAR(1) NULL,
`username` VARCHAR(45) NULL,
`password` VARCHAR(45) NULL,
`AUSL` VARCHAR(45) NULL,
PRIMARY KEY (`tesseraSanitario`, `codfsc`),
INDEX `cf_idx` (`codfsc` ASC),
UNIQUE INDEX `cf_UNIQUE` (`codfsc` ASC),
CONSTRAINT `cf`
FOREIGN KEY (`codfsc`)
REFERENCES `gestione di prenotazione`.`persona` (`cf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
Your table paziente's primary key is duplicating. So in SQL you cannot add duplicate keys as a primary key. Every primary key should be unique.