powered by simpleCommunicator - 2.0.53     © 2025 Programmizd 02
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Не работает CONSTRAINT DELETE CASCADE
4 сообщений из 4, страница 1 из 1
Не работает CONSTRAINT DELETE CASCADE
    #39535239
Makc64RUS
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Приветствую коллеги! Возможно проблема очевидна, но я никак могу её найти. Прошу помочь свежим взглядом!
Основной сервер psql (PostgreSQL) 9.4.12
Тестовый сервер psql (PostgreSQL) 9.2.18
Суть проблемы, при удалении записи в таблице carts на рабочем сервере, не удаляются сопутствующие ей записи в таблице carts_items. При этом на тестовом всё работает

Ниже вывод команд:
Код: plsql
1.
2.
\d+ carts_items
\d+ carts



Рабочий сервер:
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
transit_db=# \d+ carts
                                                                                 Table "public.carts"
       Column       |            Type             |                                         Modifiers                                         | Storage  | Stats target | Description
--------------------+-----------------------------+-------------------------------------------------------------------------------------------+----------+--------------+-------------
 id                 | integer                     | not null default nextval('carts_id_seq'::regclass)                                        | plain    |              |
 pact_id            | integer                     | not null                                                                                  | plain    |              |
 customer_reference | character varying(64)       |                                                                                           | extended |              |
 description        | character varying(64)       |                                                                                           | extended |              |
 date_created       | timestamp without time zone | not null default timezone('Europe/Moscow'::text, (now())::timestamp(0) without time zone) | plain    |              |
 api_source         | character varying(12)       |                                                                                           | extended |              |
 status             | character varying           |                                                                                           | extended |              |
 domain_id          | integer                     |                                                                                           | plain    |              |
 total_sum          | double precision            | not null default 0                                                                        | plain    |              |
 final_sum          | double precision            | not null default 0                                                                        | plain    |              |
 allowed_item_count | smallint                    | not null default 0                                                                        | plain    |              |
 denied_item_count  | smallint                    | not null default 0                                                                        | plain    |              |
 date_fulfilled     | timestamp without time zone |                                                                                           | plain    |              |
Indexes:
    "carts_pkey" PRIMARY KEY, btree (id)
    "cart_identifier" UNIQUE CONSTRAINT, btree (id, pact_id, api_source)
Referenced by:
    TABLE "carts_items" CONSTRAINT "carts_items_carts_id_fkey" FOREIGN KEY (cart_id) REFERENCES carts(id) MATCH FULL ON DELETE CASCADE

transit_db=# \d+ carts_items
                                                                         Table "public.carts_items"
        Column        |           Type           |                        Modifiers                         | Storage  | Stats target |             Description
----------------------+--------------------------+----------------------------------------------------------+----------+--------------+-------------------------------------
 id                   | integer                  | not null default nextval('carts_items_id_seq'::regclass) | plain    |              |
 cart_id              | integer                  | not null                                                 | plain    |              |
 product_type         | character varying        | not null                                                 | extended |              |
 product_id           | integer                  | not null                                                 | plain    |              |
 product_description  | character varying        |                                                          | extended |              |
 product_order_status | carts_items_order_status | default 'added'::carts_items_order_status                | plain    |              | ENUM ('added', 'allowed', 'denied')
Indexes:
    "carts_items_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "carts_items_carts_id_fkey" FOREIGN KEY (cart_id) REFERENCES carts(id) MATCH FULL ON DELETE CASCADE



Тестовый сервер:
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
transit_db=# \d+ carts
                                                                                 Table "public.carts"
       Column       |            Type             |                                         Modifiers                                         | Storage  | Stats target | Description
--------------------+-----------------------------+-------------------------------------------------------------------------------------------+----------+--------------+-------------
 id                 | integer                     | not null default nextval('carts_id_seq'::regclass)                                        | plain    |              |
 pact_id            | integer                     | not null default nextval('carts_pact_id_seq'::regclass)                                   | plain    |              |
 customer_reference | character varying(64)       |                                                                                           | extended |              |
 description        | character varying(64)       |                                                                                           | extended |              |
 date_created       | timestamp without time zone | not null default timezone('Europe/Moscow'::text, (now())::timestamp(0) without time zone) | plain    |              |
 api_source         | character varying(12)       |                                                                                           | extended |              |
 status             | character varying           |                                                                                           | extended |              |
 domain_id          | integer                     |                                                                                           | plain    |              |
 total_sum          | double precision            | not null default 0                                                                        | plain    |              |
 final_sum          | double precision            | not null default 0                                                                        | plain    |              |
 allowed_item_count | smallint                    | not null default 0                                                                        | plain    |              |
 denied_item_count  | smallint                    | not null default 0                                                                        | plain    |              |
 date_fulfilled     | timestamp without time zone |                                                                                           | plain    |              |
Indexes:
    "carts_pkey" PRIMARY KEY, btree (id)
    "cart_identifier" UNIQUE CONSTRAINT, btree (id, pact_id, api_source)
Referenced by:
    TABLE "carts_items" CONSTRAINT "carts_items_carts_id_fkey" FOREIGN KEY (cart_id) REFERENCES carts(id) MATCH FULL ON DELETE CASCADE
Has OIDs: no

transit_db=# \d+ carts_items
                                                                           Table "public.carts_items"
        Column        |           Type           |                           Modifiers                           | Storage  | Stats target |             Description
----------------------+--------------------------+---------------------------------------------------------------+----------+--------------+-------------------------------------
 id                   | integer                  | not null default nextval('carts_items_id_seq'::regclass)      | plain    |              |
 cart_id              | integer                  | not null default nextval('carts_items_cart_id_seq'::regclass) | plain    |              |
 product_type         | character varying        | not null                                                      | extended |              |
 product_id           | integer                  | not null                                                      | plain    |              |
 product_description  | character varying        |                                                               | extended |              |
 product_order_status | carts_items_order_status | default 'added'::carts_items_order_status                     | plain    |              | ENUM ('added', 'allowed', 'denied')
Indexes:
    "carts_items_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "carts_items_carts_id_fkey" FOREIGN KEY (cart_id) REFERENCES carts(id) MATCH FULL ON DELETE CASCADE
Has OIDs: no



Проблема вылезла после переноса бекапа с версии psql (PostgreSQL) 9.4.8 на новый сервер версии Основной сервер psql (PostgreSQL) 9.4.12
Удаление и пересоздание таблиц не помогает.
Во вложении скриншот как сие выглядит через pg_admin
Удаляю я данные не через pg_admin а SQL Запросом DELETE
...
Рейтинг: 0 / 0
Не работает CONSTRAINT DELETE CASCADE
    #39535253
Makc64RUS
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Ещё заметил нюанс в postgresql.conf есть опция
session_replication_role = 'replica'
без неё сервер не запускался и требовал включить. На других серверах у меня всё работает без неё
...
Рейтинг: 0 / 0
Не работает CONSTRAINT DELETE CASCADE
    #39535259
Фотография vyegorov
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Makc64RUSЕщё заметил нюанс в postgresql.conf есть опция
session_replication_role = 'replica'
без неё сервер не запускался и требовал включить. На других серверах у меня всё работает без неё
Потому и не работает — эта опция вырубает все триггера, которые (в частности) из дочерних таблиц данные удаляют.
...
Рейтинг: 0 / 0
Не работает CONSTRAINT DELETE CASCADE
    #39535267
Makc64RUS
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
да, вы правы, нашёл ответ тут http://www.sql.ru/forum/1232864/kaskadnyy-triger Спасибо вам за подтверждение
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / PostgreSQL [игнор отключен] [закрыт для гостей] / Не работает CONSTRAINT DELETE CASCADE
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]